You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Weishung Chung <we...@gmail.com> on 2011/04/13 18:52:14 UTC
does the map need to be embedded in a record
Hello,
I have a question about Avro schema. Does the map type need to be embedded
in a record? Could I have a schema like this without embedding the map in a
record?
{
"name": "mapping",
"type": "map",
"values":{
"type":"record",
"name":"hi",
"fields":[
{"name":"a","type":"string"},
{"name":"b","type":"string"}
]
}
}
Thank you
Re: does the map need to be embedded in a record
Posted by Weishung Chung <we...@gmail.com>.
Thank you so much :)
On Wed, Apr 13, 2011 at 9:31 PM, Felix.徐 <yg...@gmail.com> wrote:
> I have replied it, you should use s.getValueType() to get the schema of
> value in map.
> And getElementType() is for Array.
>
>
> 2011/4/14 Scott Carey <sc...@richrelevance.com>
>
>> Only records have fields. Maps have value types:
>>
>>
>> http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getValueType%28%29
>>
>> Likewise, arrays have
>> http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getElementType%28%29
>>
>> and unions have
>> http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getTypes%28%29
>>
>>
>> On 4/13/11 10:38 AM, "Weishung Chung" <we...@gmail.com> wrote:
>>
>> It looks like only the RecordSchema has implemented the getField method
>> getField(String fieldname)
>>
>> If I were to use the example schema, (map without embedded in a record),
>> I can't use the getField method because the MapSchema does not implement
>> the getField method, so, the following doesn't work
>>
>> Schema s = Schema.parse(new File(MY_SCHEMA_FILE);
>> GenericRecord t = new GenericData.Record(s.getField("hi").schema());
>>
>> So, I am curious how to create the GenericRecord instance to populate
>> fields a and b of the record before inserting into the Map?
>>
>>
>>
>> On Wed, Apr 13, 2011 at 12:16 PM, Scott Carey <sc...@richrelevance.com>wrote:
>>
>>> In general you don't need to wrap an unnamed complex type (map, array,
>>> union) in a record.
>>>
>>> Some language APIs might not support these 'naked' types with the same
>>> level of ease that they support named ones.
>>>
>>> Note in your schema below the "name" field -- "mapping" is completely
>>> ignored. Maps don't have names.
>>>
>>> Other 'nameless' schemas are ones with a single intrinsic data type,
>>> like:
>>>
>>> { "type": "int" }
>>>
>>>
>>> On 4/13/11 9:52 AM, "Weishung Chung" <we...@gmail.com> wrote:
>>>
>>> Hello,
>>>
>>> I have a question about Avro schema. Does the map type need to be
>>> embedded in a record? Could I have a schema like this without embedding the
>>> map in a record?
>>>
>>> {
>>> "name": "mapping",
>>> "type": "map",
>>> "values":{
>>> "type":"record",
>>> "name":"hi",
>>> "fields":[
>>> {"name":"a","type":"string"},
>>> {"name":"b","type":"string"}
>>> ]
>>> }
>>> }
>>>
>>>
>>> Thank you
>>>
>>>
>>
>
Re: does the map need to be embedded in a record
Posted by "Felix.徐" <yg...@gmail.com>.
I have replied it, you should use s.getValueType() to get the schema of
value in map.
And getElementType() is for Array.
2011/4/14 Scott Carey <sc...@richrelevance.com>
> Only records have fields. Maps have value types:
>
>
> http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getValueType%28%29
>
> Likewise, arrays have
> http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getElementType%28%29
>
> and unions have
> http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getTypes%28%29
>
>
> On 4/13/11 10:38 AM, "Weishung Chung" <we...@gmail.com> wrote:
>
> It looks like only the RecordSchema has implemented the getField method
> getField(String fieldname)
>
> If I were to use the example schema, (map without embedded in a record),
> I can't use the getField method because the MapSchema does not implement
> the getField method, so, the following doesn't work
>
> Schema s = Schema.parse(new File(MY_SCHEMA_FILE);
> GenericRecord t = new GenericData.Record(s.getField("hi").schema());
>
> So, I am curious how to create the GenericRecord instance to populate
> fields a and b of the record before inserting into the Map?
>
>
>
> On Wed, Apr 13, 2011 at 12:16 PM, Scott Carey <sc...@richrelevance.com>wrote:
>
>> In general you don't need to wrap an unnamed complex type (map, array,
>> union) in a record.
>>
>> Some language APIs might not support these 'naked' types with the same
>> level of ease that they support named ones.
>>
>> Note in your schema below the "name" field -- "mapping" is completely
>> ignored. Maps don't have names.
>>
>> Other 'nameless' schemas are ones with a single intrinsic data type, like:
>>
>> { "type": "int" }
>>
>>
>> On 4/13/11 9:52 AM, "Weishung Chung" <we...@gmail.com> wrote:
>>
>> Hello,
>>
>> I have a question about Avro schema. Does the map type need to be embedded
>> in a record? Could I have a schema like this without embedding the map in a
>> record?
>>
>> {
>> "name": "mapping",
>> "type": "map",
>> "values":{
>> "type":"record",
>> "name":"hi",
>> "fields":[
>> {"name":"a","type":"string"},
>> {"name":"b","type":"string"}
>> ]
>> }
>> }
>>
>>
>> Thank you
>>
>>
>
Re: does the map need to be embedded in a record
Posted by Scott Carey <sc...@richrelevance.com>.
Only records have fields. Maps have value types:
http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getValueType%28%29
Likewise, arrays have http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getElementType%28%29
and unions have http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getTypes%28%29
On 4/13/11 10:38 AM, "Weishung Chung" <we...@gmail.com>> wrote:
It looks like only the RecordSchema has implemented the getField method
getField(String fieldname)
If I were to use the example schema, (map without embedded in a record),
I can't use the getField method because the MapSchema does not implement the getField method, so, the following doesn't work
Schema s = Schema.parse(new File(MY_SCHEMA_FILE);
GenericRecord t = new GenericData.Record(s.getField("hi").schema());
So, I am curious how to create the GenericRecord instance to populate fields a and b of the record before inserting into the Map?
On Wed, Apr 13, 2011 at 12:16 PM, Scott Carey <sc...@richrelevance.com>> wrote:
In general you don't need to wrap an unnamed complex type (map, array, union) in a record.
Some language APIs might not support these 'naked' types with the same level of ease that they support named ones.
Note in your schema below the "name" field -- "mapping" is completely ignored. Maps don't have names.
Other 'nameless' schemas are ones with a single intrinsic data type, like:
{ "type": "int" }
On 4/13/11 9:52 AM, "Weishung Chung" <we...@gmail.com>> wrote:
Hello,
I have a question about Avro schema. Does the map type need to be embedded in a record? Could I have a schema like this without embedding the map in a record?
{
"name": "mapping",
"type": "map",
"values":{
"type":"record",
"name":"hi",
"fields":[
{"name":"a","type":"string"},
{"name":"b","type":"string"}
]
}
}
Thank you
Re: does the map need to be embedded in a record
Posted by Weishung Chung <we...@gmail.com>.
It looks like only the RecordSchema has implemented the getField method
getField(String fieldname)
If I were to use the example schema, (map without embedded in a record),
I can't use the getField method because the MapSchema does not implement the
getField method, so, the following doesn't work
Schema s = Schema.parse(new File(MY_SCHEMA_FILE);
GenericRecord t = new GenericData.Record(s.getField("hi").schema());
So, I am curious how to create the GenericRecord instance to populate
fields a and b of the record before inserting into the Map?
On Wed, Apr 13, 2011 at 12:16 PM, Scott Carey <sc...@richrelevance.com>wrote:
> In general you don't need to wrap an unnamed complex type (map, array,
> union) in a record.
>
> Some language APIs might not support these 'naked' types with the same
> level of ease that they support named ones.
>
> Note in your schema below the "name" field -- "mapping" is completely
> ignored. Maps don't have names.
>
> Other 'nameless' schemas are ones with a single intrinsic data type, like:
>
> { "type": "int" }
>
>
> On 4/13/11 9:52 AM, "Weishung Chung" <we...@gmail.com> wrote:
>
> Hello,
>
> I have a question about Avro schema. Does the map type need to be embedded
> in a record? Could I have a schema like this without embedding the map in a
> record?
>
> {
> "name": "mapping",
> "type": "map",
> "values":{
> "type":"record",
> "name":"hi",
> "fields":[
> {"name":"a","type":"string"},
> {"name":"b","type":"string"}
> ]
> }
> }
>
>
> Thank you
>
>
Re: does the map need to be embedded in a record
Posted by Scott Carey <sc...@richrelevance.com>.
In general you don't need to wrap an unnamed complex type (map, array, union) in a record.
Some language APIs might not support these 'naked' types with the same level of ease that they support named ones.
Note in your schema below the "name" field -- "mapping" is completely ignored. Maps don't have names.
Other 'nameless' schemas are ones with a single intrinsic data type, like:
{ "type": "int" }
On 4/13/11 9:52 AM, "Weishung Chung" <we...@gmail.com>> wrote:
Hello,
I have a question about Avro schema. Does the map type need to be embedded in a record? Could I have a schema like this without embedding the map in a record?
{
"name": "mapping",
"type": "map",
"values":{
"type":"record",
"name":"hi",
"fields":[
{"name":"a","type":"string"},
{"name":"b","type":"string"}
]
}
}
Thank you