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/08 16:19:00 UTC

could I add a field Map

I am using Apache Avro in my project and was wondering could it be possible
to add a field Map (TreeMap). I know that we can use Array and it works but
I would like to be able to get by key :)

Thank you,

Wei Shung

Re: could I add a field Map

Posted by Weishung Chung <we...@gmail.com>.
Hmm...there is a MapSchema in the source...

On Fri, Apr 8, 2011 at 9:19 AM, Weishung Chung <we...@gmail.com> wrote:

> I am using Apache Avro in my project and was wondering could it be possible
> to add a field Map (TreeMap). I know that we can use Array and it works but
> I would like to be able to get by key :)
>
> Thank you,
>
> Wei Shung
>

Re: could I add a field Map

Posted by Weishung Chung <we...@gmail.com>.
Thanks, very useful info. But, how to return the map using the schema?
eg. for record type, we could use

GenericRecord t = new GenericData.Record(s.getField("record").schema());


On Sun, Apr 10, 2011 at 9:55 PM, Felix.徐 <yg...@gmail.com> wrote:

> You can use Record or any other type supported by avro  as the value type
> of Map,here is an example:
>
> {
>     "name": "mapping",
>     "type": "map",
>     "values":{
>         "type":"record",
>         "name":"hi",
>         "fields":[
>             {"name":"a","type":"string"},
>             {"name":"b","type":"string"}
>         ]
>     }
> }
> Also,you can use nested schma in record fileds.
>
> 2011/4/9 Weishung Chung <we...@gmail.com>
>
>> Thanks alot, I will definitely take a look :)
>>
>>
>> On Fri, Apr 8, 2011 at 11:17 AM, Harsh J <qw...@gmail.com> wrote:
>>
>>> Yes, you can have them nested.
>>>
>>> Sounds to me like you can benefit from using Avro IDL to write your
>>> schemas. Have a look at http://avro.apache.org/docs/1.5.0/idl.html
>>>
>>> On Fri, Apr 8, 2011 at 9:43 PM, Weishung Chung <we...@gmail.com>
>>> wrote:
>>> > hmm...could I have nested avro schemas ?
>>> > eg.
>>> > avro schema A defines the data object with multiple fields and another
>>> avro
>>> > schema B defines a container/Array/map of data objects defined by the
>>> avro
>>> > schema A.
>>> >
>>> > On Fri, Apr 8, 2011 at 10:56 AM, Harsh J <qw...@gmail.com>
>>> wrote:
>>> >>
>>> >> You can use Maps as long as their key type is limited to strings I
>>> >> think. Map<String, X> is alright (X should also be Avro-acceptable, of
>>> >> course..).
>>> >>
>>> >> On Fri, Apr 8, 2011 at 7:49 PM, Weishung Chung <we...@gmail.com>
>>> wrote:
>>> >> > I am using Apache Avro in my project and was wondering could it be
>>> >> > possible
>>> >> > to add a field Map (TreeMap). I know that we can use Array and it
>>> works
>>> >> > but
>>> >> > I would like to be able to get by key :)
>>> >> > Thank you,
>>> >> > Wei Shung
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Harsh J
>>> >> http://harshj.com
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> Harsh J
>>> http://harshj.com
>>>
>>
>>
>

Re: could I add a field Map

Posted by "Felix.徐" <yg...@gmail.com>.
You can use Record or any other type supported by avro  as the value type of
Map,here is an example:

{
    "name": "mapping",
    "type": "map",
    "values":{
        "type":"record",
        "name":"hi",
        "fields":[
            {"name":"a","type":"string"},
            {"name":"b","type":"string"}
        ]
    }
}
Also,you can use nested schma in record fileds.
2011/4/9 Weishung Chung <we...@gmail.com>

> Thanks alot, I will definitely take a look :)
>
>
> On Fri, Apr 8, 2011 at 11:17 AM, Harsh J <qw...@gmail.com> wrote:
>
>> Yes, you can have them nested.
>>
>> Sounds to me like you can benefit from using Avro IDL to write your
>> schemas. Have a look at http://avro.apache.org/docs/1.5.0/idl.html
>>
>> On Fri, Apr 8, 2011 at 9:43 PM, Weishung Chung <we...@gmail.com>
>> wrote:
>> > hmm...could I have nested avro schemas ?
>> > eg.
>> > avro schema A defines the data object with multiple fields and another
>> avro
>> > schema B defines a container/Array/map of data objects defined by the
>> avro
>> > schema A.
>> >
>> > On Fri, Apr 8, 2011 at 10:56 AM, Harsh J <qw...@gmail.com>
>> wrote:
>> >>
>> >> You can use Maps as long as their key type is limited to strings I
>> >> think. Map<String, X> is alright (X should also be Avro-acceptable, of
>> >> course..).
>> >>
>> >> On Fri, Apr 8, 2011 at 7:49 PM, Weishung Chung <we...@gmail.com>
>> wrote:
>> >> > I am using Apache Avro in my project and was wondering could it be
>> >> > possible
>> >> > to add a field Map (TreeMap). I know that we can use Array and it
>> works
>> >> > but
>> >> > I would like to be able to get by key :)
>> >> > Thank you,
>> >> > Wei Shung
>> >>
>> >>
>> >>
>> >> --
>> >> Harsh J
>> >> http://harshj.com
>> >
>> >
>>
>>
>>
>> --
>> Harsh J
>> http://harshj.com
>>
>
>

Re: could I add a field Map

Posted by Weishung Chung <we...@gmail.com>.
Thanks alot, I will definitely take a look :)

On Fri, Apr 8, 2011 at 11:17 AM, Harsh J <qw...@gmail.com> wrote:

> Yes, you can have them nested.
>
> Sounds to me like you can benefit from using Avro IDL to write your
> schemas. Have a look at http://avro.apache.org/docs/1.5.0/idl.html
>
> On Fri, Apr 8, 2011 at 9:43 PM, Weishung Chung <we...@gmail.com> wrote:
> > hmm...could I have nested avro schemas ?
> > eg.
> > avro schema A defines the data object with multiple fields and another
> avro
> > schema B defines a container/Array/map of data objects defined by the
> avro
> > schema A.
> >
> > On Fri, Apr 8, 2011 at 10:56 AM, Harsh J <qw...@gmail.com> wrote:
> >>
> >> You can use Maps as long as their key type is limited to strings I
> >> think. Map<String, X> is alright (X should also be Avro-acceptable, of
> >> course..).
> >>
> >> On Fri, Apr 8, 2011 at 7:49 PM, Weishung Chung <we...@gmail.com>
> wrote:
> >> > I am using Apache Avro in my project and was wondering could it be
> >> > possible
> >> > to add a field Map (TreeMap). I know that we can use Array and it
> works
> >> > but
> >> > I would like to be able to get by key :)
> >> > Thank you,
> >> > Wei Shung
> >>
> >>
> >>
> >> --
> >> Harsh J
> >> http://harshj.com
> >
> >
>
>
>
> --
> Harsh J
> http://harshj.com
>

Re: could I add a field Map

Posted by Harsh J <qw...@gmail.com>.
Yes, you can have them nested.

Sounds to me like you can benefit from using Avro IDL to write your
schemas. Have a look at http://avro.apache.org/docs/1.5.0/idl.html

On Fri, Apr 8, 2011 at 9:43 PM, Weishung Chung <we...@gmail.com> wrote:
> hmm...could I have nested avro schemas ?
> eg.
> avro schema A defines the data object with multiple fields and another avro
> schema B defines a container/Array/map of data objects defined by the avro
> schema A.
>
> On Fri, Apr 8, 2011 at 10:56 AM, Harsh J <qw...@gmail.com> wrote:
>>
>> You can use Maps as long as their key type is limited to strings I
>> think. Map<String, X> is alright (X should also be Avro-acceptable, of
>> course..).
>>
>> On Fri, Apr 8, 2011 at 7:49 PM, Weishung Chung <we...@gmail.com> wrote:
>> > I am using Apache Avro in my project and was wondering could it be
>> > possible
>> > to add a field Map (TreeMap). I know that we can use Array and it works
>> > but
>> > I would like to be able to get by key :)
>> > Thank you,
>> > Wei Shung
>>
>>
>>
>> --
>> Harsh J
>> http://harshj.com
>
>



-- 
Harsh J
http://harshj.com

Re: could I add a field Map

Posted by Weishung Chung <we...@gmail.com>.
hmm...could I have nested avro schemas ?
eg.
avro schema A defines the data object with multiple fields and another avro
schema B defines a container/Array/map of data objects defined by the avro
schema A.

On Fri, Apr 8, 2011 at 10:56 AM, Harsh J <qw...@gmail.com> wrote:

> You can use Maps as long as their key type is limited to strings I
> think. Map<String, X> is alright (X should also be Avro-acceptable, of
> course..).
>
> On Fri, Apr 8, 2011 at 7:49 PM, Weishung Chung <we...@gmail.com> wrote:
> > I am using Apache Avro in my project and was wondering could it be
> possible
> > to add a field Map (TreeMap). I know that we can use Array and it works
> but
> > I would like to be able to get by key :)
> > Thank you,
> > Wei Shung
>
>
>
> --
> Harsh J
> http://harshj.com
>

Re: could I add a field Map

Posted by Harsh J <qw...@gmail.com>.
You can use Maps as long as their key type is limited to strings I
think. Map<String, X> is alright (X should also be Avro-acceptable, of
course..).

On Fri, Apr 8, 2011 at 7:49 PM, Weishung Chung <we...@gmail.com> wrote:
> I am using Apache Avro in my project and was wondering could it be possible
> to add a field Map (TreeMap). I know that we can use Array and it works but
> I would like to be able to get by key :)
> Thank you,
> Wei Shung



-- 
Harsh J
http://harshj.com