> Which aspect of the generic API are you most interested in? The builder,> getters, or setters?>Most people that use Specific records do so for compile time type safety,> so adding 'set("foo", fooval)' is not desired for those users. On the> other hand it is certainly possible to add it.>

I am interested in getters and setters at first.For now, any code that intends to work with both generic and specificrecord must use the IndexedRecord (and implement the accessors Dougmentioned).It would be useful in some cases to be able to consider specific records asgeneric records too.

Now that you mention it too, I realize I also needed to use specific recordbuilders as generic record builders and could not, so that would be usefultoo.

If you think it's a meaningful addition, I'm happy to make the change.

C.> The code generated by the specific code generation utility uses templates,> one can add a template that extends what is produced to include generic API> bits.>> -Scott>> On 4/15/13 11:23 AM, "Christophe Taton" <[EMAIL PROTECTED]> wrote:>> Hi,> Is there a reason for specific records to not implement the generic API?> I didn't find any obvious technical reason, but maybe I missed something.> Thanks,> C.>>

On Mon, Apr 15, 2013 at 2:21 PM, Christophe Taton <[EMAIL PROTECTED]> wrote:> If you think it's a meaningful addition, I'm happy to make the change.

The two methods I wrote above could be added to SpecificRecordBase andit could then be declared to implement GenericRecord.

I think GenericRecordBuilder could be used to build specific recordswith a few additional changes: - change the type of the 'record' field from GenericData.Record toGenericRecord. - replace the call to 'new GenericData.Record()' to'(GenericRecord)data().newRecord(null, schema())' - add a constructor that accepts a GenericData instance, instead ofcalling GenericData.get().

Then you could use new GenericRecordBuilder(SpecificData.get(),schema) to create specific records.

I would like to figure out how to make SpecificRecord and GenericRecordimmutable in the longer term (or as an option with the code generationand/or builder). The builder is the first step, but setters are theenemy. Is there a way to do this that does not introduce new mutators forall SpecificRecords?

On 4/15/13 3:43 PM, "Doug Cutting" <[EMAIL PROTECTED]> wrote:

>On Mon, Apr 15, 2013 at 2:21 PM, Christophe Taton <[EMAIL PROTECTED]>>wrote:>> If you think it's a meaningful addition, I'm happy to make the change.>>The two methods I wrote above could be added to SpecificRecordBase and>it could then be declared to implement GenericRecord.>>I think GenericRecordBuilder could be used to build specific records>with a few additional changes:> - change the type of the 'record' field from GenericData.Record to>GenericRecord.> - replace the call to 'new GenericData.Record()' to>'(GenericRecord)data().newRecord(null, schema())'> - add a constructor that accepts a GenericData instance, instead of>calling GenericData.get().>>Then you could use new GenericRecordBuilder(SpecificData.get(),>schema) to create specific records.>>Doug

> I would like to figure out how to make SpecificRecord and GenericRecord> immutable in the longer term (or as an option with the code generation> and/or builder). The builder is the first step, but setters are the> enemy. Is there a way to do this that does not introduce new mutators for> all SpecificRecords?>

That's fair. Getters only would work for what I need, assuming setters willeventually come through builders.

And Immutable records would be great!

C.

On 4/15/13 3:43 PM, "Doug Cutting" <[EMAIL PROTECTED]> wrote:>> >On Mon, Apr 15, 2013 at 2:21 PM, Christophe Taton <[EMAIL PROTECTED]>> >wrote:> >> If you think it's a meaningful addition, I'm happy to make the change.> >> >The two methods I wrote above could be added to SpecificRecordBase and> >it could then be declared to implement GenericRecord.> >> >I think GenericRecordBuilder could be used to build specific records> >with a few additional changes:> > - change the type of the 'record' field from GenericData.Record to> >GenericRecord.> > - replace the call to 'new GenericData.Record()' to> >'(GenericRecord)data().newRecord(null, schema())'> > - add a constructor that accepts a GenericData instance, instead of> >calling GenericData.get().> >> >Then you could use new GenericRecordBuilder(SpecificData.get(),> >schema) to create specific records.> >> >Doug>>>

> On Mon, Apr 15, 2013 at 9:19 PM, Scott Carey <[EMAIL PROTECTED]>wrote:>>> I would like to figure out how to make SpecificRecord and GenericRecord>> immutable in the longer term (or as an option with the code generation>> and/or builder). The builder is the first step, but setters are the>> enemy. Is there a way to do this that does not introduce new mutators for>> all SpecificRecords?>>>> That's fair. Getters only would work for what I need, assuming setters> will eventually come through builders.>> And Immutable records would be great!>> C.>> On 4/15/13 3:43 PM, "Doug Cutting" <[EMAIL PROTECTED]> wrote:>>>> >On Mon, Apr 15, 2013 at 2:21 PM, Christophe Taton <[EMAIL PROTECTED]>>> >wrote:>> >> If you think it's a meaningful addition, I'm happy to make the change.>> >>> >The two methods I wrote above could be added to SpecificRecordBase and>> >it could then be declared to implement GenericRecord.>> >>> >I think GenericRecordBuilder could be used to build specific records>> >with a few additional changes:>> > - change the type of the 'record' field from GenericData.Record to>> >GenericRecord.>> > - replace the call to 'new GenericData.Record()' to>> >'(GenericRecord)data().newRecord(null, schema())'>> > - add a constructor that accepts a GenericData instance, instead of>> >calling GenericData.get().>> >>> >Then you could use new GenericRecordBuilder(SpecificData.get(),>> >schema) to create specific records.>> >>> >Doug>>>>>>>

This *could* get us closer to implementing a new "reader" extendingDatumReader that reads text/json and generates Avro records (evenSpecificRecord records). Vice versa - one could similarly write a new"writer" extending the base class DatumWriter that takes an avroSpecificRecord and spits out a text/json representation (without the Avroadornments that are required).

Combined with the technique using GenericRecordBuilder described by Doug inthe email thread, such a new "reader"/ "writer" *could* allow buildingSpecificRecords that have a Schema from text/json strings - thus removingthe requirement that you must use a JsonEncoder to create Json stringsbefore reading/parsing them using JsonDecoder.

I will do some experiments and post findings in a separate thread.On Wed, Apr 17, 2013 at 1:30 AM, Christophe Taton <[EMAIL PROTECTED]>wrote:

> I created https://issues.apache.org/jira/browse/AVRO-1299 and posted a> patch to let SpecificRecordBase implement GenericRecord.> As I think about it, it seems to me that SpecificRecordBuilderBase should> also implement GenericRecord.>> C.>>> On Mon, Apr 15, 2013 at 9:39 PM, Christophe Taton <[EMAIL PROTECTED]>wrote:>>> On Mon, Apr 15, 2013 at 9:19 PM, Scott Carey <[EMAIL PROTECTED]>wrote:>>>>> I would like to figure out how to make SpecificRecord and GenericRecord>>> immutable in the longer term (or as an option with the code generation>>> and/or builder). The builder is the first step, but setters are the>>> enemy. Is there a way to do this that does not introduce new mutators>>> for>>> all SpecificRecords?>>>>>>> That's fair. Getters only would work for what I need, assuming setters>> will eventually come through builders.>>>> And Immutable records would be great!>>>> C.>>>> On 4/15/13 3:43 PM, "Doug Cutting" <[EMAIL PROTECTED]> wrote:>>>>>> >On Mon, Apr 15, 2013 at 2:21 PM, Christophe Taton <[EMAIL PROTECTED]>>>> >wrote:>>> >> If you think it's a meaningful addition, I'm happy to make the change.>>> >>>> >The two methods I wrote above could be added to SpecificRecordBase and>>> >it could then be declared to implement GenericRecord.>>> >>>> >I think GenericRecordBuilder could be used to build specific records>>> >with a few additional changes:>>> > - change the type of the 'record' field from GenericData.Record to>>> >GenericRecord.>>> > - replace the call to 'new GenericData.Record()' to>>> >'(GenericRecord)data().newRecord(null, schema())'>>> > - add a constructor that accepts a GenericData instance, instead of>>> >calling GenericData.get().>>> >>>> >Then you could use new GenericRecordBuilder(SpecificData.get(),>>> >schema) to create specific records.>>> >>>> >Doug>>>>>>>>>>>>-- Pankaj Shroff[EMAIL PROTECTED]

> I think GenericRecordBuilder could be used to build specific records> with a few additional changes:> - change the type of the 'record' field from GenericData.Record to> GenericRecord.> - replace the call to 'new GenericData.Record()' to> '(GenericRecord)data().newRecord(null, schema())'> - add a constructor that accepts a GenericData instance, instead of> calling GenericData.get().>> Then you could use new GenericRecordBuilder(SpecificData.get(),> schema) to create specific records.>

Symmetrically, do you think it's possible to have SpecificRecord buildersextend GenericRecordBuilder?