avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Carey <sc...@richrelevance.com>
Subject Re: Schema with multiple Record types Java API
Date Thu, 14 Jul 2011 23:02:06 GMT
The name and namespace is part of any named schema (Type.RECORD, Type.FIXED, Type.ENUM).

We don't currently have an API to search a schema for subschemas that match names.  It would
be useful, you might want to create a JIRA ticket explaining your use case.

So it would be a little more complex.

        Schema schema = Schema.parse(schemaDescription);
        Schema.Type type = schema.getType();
        switch (type) {
        case RECORD:
          String name = schema.getName();
          String namespace = schema.getNamespace();
          List<Field> fields = schema.getFields();


In general, I have created SpecificRecord objects from schemas using the specific compiler
(and the ant task or maven plugin) and then within those generated classes there is a static
SCHEMA variable to reference.

Avro IDL is alo an easier way to define related schemas.  Currently there are only build tools
that generate code from these, though there are APIs to extract schemas.


On 7/13/11 10:43 AM, "Peter Wolf" <opus111@gmail.com<mailto:opus111@gmail.com>>

Hello, this a dumb question, but I can not find the answer in the docs

I want to have a complicated schema with lots of Records referencing other Records.

Like this...

  "namespace": "com.foobah",
  "name": "Bah",
  "type": "record",
  "fields": [
  {"name": "value", "type": "int"}

  "namespace": "com.foobah",
  "name": "Foo",
  "type": "record",
  "fields": [
  {"name": "bah", "type": "Bah"}
Using the Java API, how do I reference types within a schema?  Let's say I want to make a
Foo object, I want to do something like this...

        Schema schema = Schema.parse(schemaDescription);
>>> Schema foo = schema.getSchema("com.foobah.Foo"); <<<
        GenericData o = new GenericData( foo );

Many thanks in advance

View raw message