use of org.apache.avro.util.Utf8 in project databus by linkedin.
the class TestInternalMetadata method testGetMetadata_HappyPath.
/**
* Verifies that getMetadata() returns the expected GenericRecord for the event's
* metadata and that it has the expected fields and values in it.
*/
@Test
public void testGetMetadata_HappyPath() throws Exception {
LOG.info("starting testGetMetadata_HappyPath()");
// build the event's metadata and then the event
DbusEventPart metadataPart = createMetadataPart();
DbusEvent event = createEvent(metadataPart);
// create a metadata schema set that correctly corresponds to the metadata
VersionedSchemaSet metadataSchemaSet = new VersionedSchemaSet();
metadataSchemaSet.add(SchemaRegistryService.DEFAULT_METADATA_SCHEMA_SOURCE, // METADATA_SCHEMA_VERSION
metadataPart.getSchemaVersion(), // METADATA_SCHEMA_CHECKSUM
new SchemaId(metadataPart.getSchemaDigest()), CORRECT_METADATA_SCHEMA, // preserve original string
true);
// now create the decoder and use it to extract and decode the event's metadata
DbusEventAvroDecoder eventDecoder = createDecoder(metadataSchemaSet);
try {
GenericRecord reuse = null;
GenericRecord decodedMetadata = eventDecoder.getMetadata(event, reuse);
Assert.assertNotNull(decodedMetadata, "getMetadata() returned null GenericRecord;");
Utf8 etag = (Utf8) decodedMetadata.get("etag");
Assert.assertEquals(etag.toString(), "dunno what an etag is");
Integer flags = (Integer) decodedMetadata.get("flags");
Assert.assertEquals(flags, null, "expected flags to be null");
Long expires = (Long) decodedMetadata.get("expires");
Assert.assertNotNull(expires, "expected expires to have a value;");
Assert.assertEquals(expires.longValue(), 1366150681);
Utf8 nonexistentField = (Utf8) decodedMetadata.get("nonexistentField");
Assert.assertNull(nonexistentField, "unexpected value for 'nonexistentField';");
} catch (Exception ex) {
Assert.fail("unexpected error decoding metadata: " + ex);
}
LOG.info("leaving testGetMetadata_HappyPath()");
}
use of org.apache.avro.util.Utf8 in project pinot by linkedin.
the class AvroRecordReader method getGenericRow.
private GenericRow getGenericRow(GenericRecord rawRecord, GenericRow row) {
for (final Field field : _dataStream.getSchema().getFields()) {
FieldSpec spec = _schemaExtractor.getSchema().getFieldSpecFor(field.name());
if (spec == null) {
continue;
}
Object value = rawRecord.get(field.name());
if (value == null) {
incrementNullCountFor(field.name());
if (spec.isSingleValueField()) {
value = spec.getDefaultNullValue();
} else {
value = transformAvroArrayToObjectArray((Array) value, spec);
}
} else {
if (value instanceof Utf8) {
value = ((Utf8) value).toString();
}
if (value instanceof Array) {
value = transformAvroArrayToObjectArray((Array) value, spec);
}
}
row.putField(field.name(), value);
}
return row;
}
use of org.apache.avro.util.Utf8 in project pinot by linkedin.
the class AvroRecordReader method transformAvroArrayToObjectArray.
public static Object[] transformAvroArrayToObjectArray(Array arr, FieldSpec spec) {
if (arr == null) {
return new Object[] { getDefaultNullValue(spec) };
}
if (arr.size() == 0) {
return new Object[] { getDefaultNullValue(spec) };
}
final Object[] ret = new Object[arr.size()];
final Iterator iterator = arr.iterator();
int i = 0;
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Record) {
value = ((Record) value).get(0);
}
if (value instanceof Utf8) {
value = ((Utf8) value).toString();
}
if (value == null) {
value = getDefaultNullValue(spec);
}
ret[i++] = value;
}
return ret;
}
use of org.apache.avro.util.Utf8 in project pinot by linkedin.
the class SegmentTestUtils method transformAvroArrayToObjectArray.
private static Object[] transformAvroArrayToObjectArray(Array arr) {
if (arr == null) {
return new Object[0];
}
final Object[] ret = new Object[arr.size()];
final Iterator iterator = arr.iterator();
int i = 0;
while (iterator.hasNext()) {
Object value = iterator.next();
if (value instanceof Record) {
value = ((Record) value).get(0);
}
if (value instanceof Utf8) {
value = ((Utf8) value).toString();
}
ret[i++] = value;
}
return ret;
}
use of org.apache.avro.util.Utf8 in project hadoop by apache.
the class JobFinishedEvent method getDatum.
public Object getDatum() {
if (datum == null) {
datum = new JobFinished();
datum.setJobid(new Utf8(jobId.toString()));
datum.setFinishTime(finishTime);
datum.setFinishedMaps(finishedMaps);
datum.setFinishedReduces(finishedReduces);
datum.setFailedMaps(failedMaps);
datum.setFailedReduces(failedReduces);
datum.setMapCounters(EventWriter.toAvro(mapCounters, "MAP_COUNTERS"));
datum.setReduceCounters(EventWriter.toAvro(reduceCounters, "REDUCE_COUNTERS"));
datum.setTotalCounters(EventWriter.toAvro(totalCounters, "TOTAL_COUNTERS"));
}
return datum;
}
Aggregations