@SuppressWarnings("unchecked") public K getKey() { return (K) mKeyValueRecord.get(KEY_FIELD); }
public void setKey(K key) { mKeyValueRecord.put(KEY_FIELD, key); }
@Override public GenericRecord partitionForRecord(GenericRecord record) { GenericRecord partition = new GenericData.Record(SCHEMA); partition.put(TITLE, record.get("title")); return partition; } }
public void readFields(byte[] bytes, int offset, int length, Schema writerSchema, Schema readerSchema) throws IOException { fileSchema = writerSchema; record = new GenericData.Record(writerSchema); binaryDecoder = DecoderFactory.get().binaryDecoder(bytes, offset, length - offset, binaryDecoder); GenericDatumReader<GenericRecord> gdr = new GenericDatumReader<GenericRecord>(writerSchema, readerSchema); record = gdr.read(null, binaryDecoder); }
/** * Instantiates a new generic avro converter. * * @param schema the schema */ public GenericAvroConverter(Schema schema) { this.schema = schema; datumReader = new GenericDatumReader<T>(this.schema); datumWriter = new GenericDatumWriter<T>(this.schema); }
private static <T> AvroFactory<T> fromGeneric(ClassLoader cl, Schema schema) { checkNotNull(schema, "Unable to create an AvroSerializer with a GenericRecord type without a schema"); GenericData genericData = new GenericData(cl); return new AvroFactory<>( genericData, schema, new GenericDatumReader<>(schema, schema, genericData), new GenericDatumWriter<>(schema, genericData) ); }
/** * Creates a GenericRecordBuilder for building Record instances. * @param schema the schema associated with the record class. */ public GenericRecordBuilder(Schema schema) { super(schema, GenericData.get()); record = new GenericData.Record(schema); }
private void output(final AvroOutputFormat<GenericRecord> outputFormat, Schema schema) throws IOException { outputFormat.configure(new Configuration()); outputFormat.open(1, 1); for (int i = 0; i < 100; i++) { GenericRecord record = new GenericData.Record(schema); record.put("user_name", "testUser"); record.put("favorite_number", 1); record.put("favorite_color", "blue"); outputFormat.writeRecord(record); } outputFormat.close(); } }
@VisibleForTesting InlineSchemaAvroBytesDecoder(Schema schemaObj) { this.schemaObj = schemaObj; this.reader = new GenericDatumReader<>(schemaObj); this.schema = null; }
public AvroGenericRecordHDFSWriter(FileRotationPolicy policy, Path path, FSDataOutputStream stream, Schema schema) throws IOException { super(policy, path); this.out = stream; this.schema = schema; DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(schema); avroWriter = new DataFileWriter<>(datumWriter); avroWriter.create(this.schema, this.out); }
/** * Clears the value of the given field. * @param pos the position of the field to clear. * @return a reference to the RecordBuilder. */ protected GenericRecordBuilder clear(int pos) { record.put(pos, null); fieldSetFlags()[pos] = false; return this; }
/** * Creates a GenericRecordBuilder by copying an existing GenericRecordBuilder. * @param other the GenericRecordBuilder to copy. */ public GenericRecordBuilder(GenericRecordBuilder other) { super(other, GenericData.get()); record = new GenericData.Record(other.record, /* deepCopy = */ true); }
@SuppressWarnings("unchecked") public V getValue() { return (V) mKeyValueRecord.get(VALUE_FIELD); }
public void setValue(V value) { mKeyValueRecord.put(VALUE_FIELD, value); }
/** * Clears the value of the given field. * @param pos the position of the field to clear. * @return a reference to the RecordBuilder. */ protected GenericRecordBuilder clear(int pos) { record.put(pos, null); fieldSetFlags()[pos] = false; return this; }
/** * Creates a GenericRecordBuilder for building Record instances. * @param schema the schema associated with the record class. */ public GenericRecordBuilder(Schema schema) { super(schema, GenericData.get()); record = new GenericData.Record(schema); }
private static Object locateNode(GenericRecord element, String columnMapping) { Object value = element; for (String pathElement : Splitter.on('/').omitEmptyStrings().split(columnMapping)) { if (value == null) { return null; } value = ((GenericRecord) value).get(pathElement); } return value; }
@Override public Object getRootField(final GenericRecord record, final String key) { return transformValue(record.get(key)); }