Re: Direct conversion from Generic Record to Specific Record

2014-02-06 Thread Doug Cutting
SpecificData#deepCopy will make this conversion. It currently fails for enums, but the fix is easy. Here's a patch that makes that fix and demonstrates a conversion. If this change is of interest, please file an issue in Jira. Doug Index: lang/java/avro/src/main/java/org/apache/avro/generic/Ge

Re: Direct conversion from Generic Record to Specific Record

2014-02-06 Thread Roger Hoover
Great. Thanks, Christophe. On Thu, Feb 6, 2014 at 8:12 AM, Christophe Taton wrote: > I believe we could eventually make a generic function that can rewrite any > record or record builder, whether specific or generic, into another record > or record builder, whether specific or generic. > > Unt

Re: Direct conversion from Generic Record to Specific Record

2014-02-06 Thread Roger Hoover
Thank you, Mika. I'll do this in mean time. Was wondering if there was a better way... On Thu, Feb 6, 2014 at 6:10 AM, Mika Ristimaki wrote: > Hi, > > If you don't mind the overhead you can make the conversion through the > avro binary data. So something like this should work (assuming both re

Re: Direct conversion from Generic Record to Specific Record

2014-02-06 Thread Christophe Taton
I believe we could eventually make a generic function that can rewrite any record or record builder, whether specific or generic, into another record or record builder, whether specific or generic. Until this happens, Mika's suggestion is probably the best short-term solution. C. On Wed, Feb 5,

Re: Direct conversion from Generic Record to Specific Record

2014-02-06 Thread Mika Ristimaki
Hi, If you don't mind the overhead you can make the conversion through the avro binary data. So something like this should work (assuming both records are using the same schema) GenericRecord myRecord = ... GenericDatumWriter writer = new GenericDatumWriter(MyCustomRecord.getClassSchema()); By

Re: Direct conversion from Generic Record to Specific Record

2014-02-05 Thread Roger Hoover
Hi Christophe, Thanks for your reply. When you say that we could write a generic conversion function, do you mean we can write one that works for all schemas? That would be great! I'd like an API something like this: MyCustomRecord record = MyCustomRecord.newBuilder(GenericRecord record).build

Re: Direct conversion from Generic Record to Specific Record

2014-02-05 Thread Christophe Taton
Hi Roger, With the change proposed in https://issues.apache.org/jira/browse/AVRO-1443, you would be able to create a specific record using a generic builder API. That means we could write a generic conversion function that creates specific records. Would that work for you? C. On Wed, Feb 5, 2014

Direct conversion from Generic Record to Specific Record

2014-02-05 Thread Roger Hoover
Hi, I'm working with an existing API that hands me a GenericRecord. Is there an easy way I can covert it into a SpecificRecord. Really I want to get it into the code-generated object. Thanks, Roger