public Row<T, K> clone() { Schema schema = value.getSchema(); T newvalue; try { newvalue = (T) Class.forName(schema.getFullName()).newInstance(); } catch (Exception e) { throw new AvroBaseException("Could not clone row", e); } for (Schema.Field field : schema.getFields()) { int pos = field.pos(); newvalue.put(pos, value.get(pos)); } return new Row<T, K>(newvalue, row, version); } }
if (f != null) { field = field.substring(dotindex + 1); Object o = value.get(f.pos()); if (o instanceof GenericArray) { GenericArray ga = (GenericArray) o; if (e instanceof SpecificRecord) { SpecificRecord sr = (SpecificRecord) e; addField(sr, sr.getSchema(), document, field, solrfield); } else { throw new AvroBaseException("Invalid field name" + solrfield); Object o = value.get(f.pos()); if (o instanceof GenericArray) { GenericArray ga = (GenericArray) o; if (e instanceof SpecificRecord) { SpecificRecord sr = (SpecificRecord) e; Schema.Field idField = sr.getSchema().getField("id"); if (idField != null) { document.addField(solrfield, sr.get(idField.pos()));
@Override protected void setField(Object record, String name, int position, Object o) { ((SpecificRecord)record).put(position, o); } @Override
@Override protected Object getField(Object record, String name, int position) { return ((SpecificRecord)record).get(position); }
@Override public E compose(List<S> subEntities) { E entity; try { entity = entityConstructor.newInstance(); } catch (Throwable e) { LOG.error( "Error trying to construct entity of type: " + entityClass.getName(), e); throw new DatasetException(e); } int cnt = 0; for (S subEntity : subEntities) { if (subEntity != null) { entity.put(cnt, subEntity); } cnt++; } return entity; }
@Override protected Object getField(Object record, String name, int position) { return ((SpecificRecord)record).get(position); }
@InterfaceAudience.Private @Override public Schema getSchema(SpecificRecord t) { return t.getSchema(); }
@Override public E compose(List<S> subEntities) { E entity; try { entity = entityConstructor.newInstance(); } catch (Throwable e) { LOG.error( "Error trying to construct entity of type: " + entityClass.getName(), e); throw new DatasetException(e); } int cnt = 0; for (S subEntity : subEntities) { if (subEntity != null) { entity.put(cnt, subEntity); } cnt++; } return entity; }
@SuppressWarnings("unchecked") @Override public List<S> decompose(E entity) { List<S> subEntityList = new ArrayList<S>(); for (int i = 0; i < entitySchema.getFields().size(); i++) { subEntityList.add((S) entity.get(i)); } return subEntityList; } }
/** * Creates a SpecificRecordBuilderBase by copying an existing record instance. * @param other the record instance to copy. */ protected SpecificRecordBuilderBase(T other) { super(other.getSchema(), SpecificData.get()); } }
@Override public E compose(List<S> subEntities) { E entity; try { entity = entityConstructor.newInstance(); } catch (Throwable e) { LOG.error( "Error trying to construct entity of type: " + entityClass.getName(), e); throw new DatasetException(e); } int cnt = 0; for (S subEntity : subEntities) { if (subEntity != null) { entity.put(cnt, subEntity); } cnt++; } return entity; }
@SuppressWarnings("unchecked") @Override public List<S> decompose(E entity) { List<S> subEntityList = new ArrayList<S>(); for (int i = 0; i < entitySchema.getFields().size(); i++) { subEntityList.add((S) entity.get(i)); } return subEntityList; } }
@InterfaceAudience.Private @Override public DatumReader getReader(Class<SpecificRecord> clazz) { try { return new SpecificDatumReader(clazz.newInstance().getSchema()); } catch (Exception e) { throw new RuntimeException(e); } }
private T getAvroObject(DBObject ro) { BasicDBObject vo = (BasicDBObject) ro.get("value"); Class c = SpecificData.get().getClass(readerSchema); T ao; try { ao = (T) c.newInstance(); for (Schema.Field field : readerSchema.getFields()) { String name = field.name(); Object v = vo.get(name); if (v instanceof byte[]) { v = ByteBuffer.wrap((byte[]) v); } ao.put(field.pos(), v); } } catch (Exception e) { throw new AvroBaseException("Could not create object", e); } return ao; }
@SuppressWarnings("unchecked") @Override public List<S> decompose(E entity) { List<S> subEntityList = new ArrayList<S>(); for (int i = 0; i < entitySchema.getFields().size(); i++) { subEntityList.add((S) entity.get(i)); } return subEntityList; } }