You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Sameer Deokule <sd...@gmail.com> on 2012/06/29 04:02:26 UTC

Re: runtime error when casting Array to String[]

Hello,

  Is mapping of avro arrays to java arrays instead of lists, still being
planned?

Thanks
Sameer

From: Scott Carey <sc...@richrelevance.com>
To: "user@avro.apache.org" <us...@avro.apache.org>
Date: Wed, 27 Apr 2011 12:09:02 -0700
Subject: Re: runtime error when casting Array<String> to String[]
Thread-Topic: runtime error when casting Array<String> to String[]
Thread-Index: AcwFDouwWK6P0HsIQBW0+lsPhRTwlQ==
Message-ID: <C9...@richrelevance.com>
In-Reply-To: <93...@yahoo-inc.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
user-agent: Microsoft-MacOutlook/14.10.0.110310
acceptlanguage: en-US
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0



On 4/27/11 11:26 AM, "Markus Weimer" <we...@yahoo-inc.com> wrote:

>HI,
>
>> I am working on tools for Avro that will make Alternate object mappings
>>easier.  I hope this will land in 1.6.0.  Custom specific compiled
>>variants will more easily leverage all the work unrelated to object type
>>mapping.
>
>Nice! Will that allow me to have an array of floats in the schema and
>receive it as a float[] in the compiled java class?
>

It will allow users to create custom mappings easier, one of which might
be that avro arrays that map to java array types instead of List.  A few
basic mapping types might find their way into Avro if they are contributed.

The Specific compiler has been templatized for a while now, and users can
create their own code templates that produces classes as they like, but
writing a custom SpecificDatum(Reader|Writer) requires knowing a lot about
things unrelated to the mapping of Avro types to Java types.

Creating a custom mapping isn't always trivial, but having it be a
separate concern from schema translation and resolution, and low level
encoding/decoding operations will allow for greater code re-use and
modular composition.

>Thanks,
>
>Markus

Re: runtime error when casting Array to String[]

Posted by Doug Cutting <cu...@apache.org>.
On Thu, Jun 28, 2012 at 7:02 PM, Sameer Deokule <sd...@gmail.com> wrote:
>   Is mapping of avro arrays to java arrays instead of lists, still being
> planned?

This is possible in Avro 1.7 if you use ReflectDatumReader and the
array schema includes either "java-class" or a "java-element-class"
attribute.  The "java-class" attribute should be an array class name
e.g., "[I" for an int[] and "[Ljava.lang.String" for String[] -- see
http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getName().
 For example, an array of Strings might be represented either with the
schema:
  {"type":"array", "items":"string", "java-class":"[Ljava.lang.String"}
or with:
  {"type":"array", "items":"string", "java-element-class":"java.lang.String"}

Note that ReflectDatumReader is a superclass of SpecificDatumReader
and GenericDatumReader, so in addition to reading reflected records,
it can also correctly read records defined by the specific compiler or
if no class exists for a record it will use the generic
representation.

Doug