avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fengyun RAO <raofeng...@gmail.com>
Subject Re: How to dynamically create a MapSchema with "String" as key, not "Utf8"
Date Fri, 23 May 2014 14:56:09 GMT
I didn't realize this is exactly the right answer, thank you, Harsh!


2014-05-19 18:52 GMT+08:00 Harsh J <harsh@cloudera.com>:

> Ah my bad, I didn't realise you wanted to infer/generate the schema in
> code. I believe you may be looking for this static method perhaps:
>
> http://avro.apache.org/docs/1.7.6/api/java/org/apache/avro/generic/GenericData.html#setStringType(org.apache.avro.Schema
> ,
> org.apache.avro.generic.GenericData.StringType)
>
> On Mon, May 19, 2014 at 4:03 PM, Fengyun RAO <raofengyun@gmail.com> wrote:
> > Yes, I knew it. "MyType.java" was compiled using "-string".
> >
> > My question is how to generate schema of Map<String, MyType> , providing
> > that I only have "MyType.avsc" file, but not the map schema file.
> >
> > Schema.createMap(Schema myType) method generates a Map<Utf8, MyType>, not
> > Map<String, MyType>.
> >
> >
> > 2014-05-19 18:16 GMT+08:00 Harsh J <harsh@cloudera.com>:
> >
> >> You can pass -string to the avro-tools compile program, to make the
> >> generated classes use String/CharSequence and not Utf8.
> >>
> >> On Mon, May 19, 2014 at 1:37 PM, Fengyun RAO <raofengyun@gmail.com>
> wrote:
> >> > I've noticed the jira page:
> >> > https://issues.apache.org/jira/browse/AVRO-803,
> >> > and known how to generate a Map<String, MyType> class using a schema
> >> > file.
> >> >
> >> > In my case, the schema file is “MyType.avsc”, and I used avro-tools
to
> >> > generate a "MyType.java" class,
> >> > My question is how to dynamically create a MapSchema of Map<String,
> >> > MyType>,
> >> > since I have to Ser/De a Map<String, MyType>.
> >> >
> >> > I tried to use the method Schema.createMap(Schema myType), but the key
> >> > is
> >> > "Utf8" not "String".
> >>
> >>
> >>
> >> --
> >> Harsh J
> >
> >
>
>
>
> --
> Harsh J
>

Mime
View raw message