Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
Avro >> mail # user >> Could specific records implement the generic API as well?


Copy link to this message
-
Re: Could specific records implement the generic API as well?
SpecificRecordBase implements IndexedRecord, so that fields can be
accessed by number, but not directly by name.  However Implementing
#set(String,Object) and #get(String) is easy:

public static Object get(SpecificRecordBase record, String fieldName) {
  return record.get(record.getSchema().getField(fieldName).pos());
}

public static void set(SpecificRecordBase record, String fieldName,
Object value) {
  record.set(record.getSchema().getField(fieldName).pos(), value);
}

Doug

On Mon, Apr 15, 2013 at 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.
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB