use of org.apache.avro.file.DataFileStream in project beam by apache.
the class AvroIOTest method testMetadata.
@Test
@SuppressWarnings("unchecked")
@Category(NeedsRunner.class)
public void testMetadata() throws Exception {
List<GenericClass> values = ImmutableList.of(new GenericClass(3, "hi"), new GenericClass(5, "bar"));
File outputFile = tmpFolder.newFile("output.avro");
p.apply(Create.of(values)).apply(AvroIO.write(GenericClass.class).to(outputFile.getAbsolutePath()).withoutSharding().withMetadata(ImmutableMap.<String, Object>of("stringKey", "stringValue", "longKey", 100L, "bytesKey", "bytesValue".getBytes())));
p.run();
DataFileStream dataFileStream = new DataFileStream(new FileInputStream(outputFile), new GenericDatumReader());
assertEquals("stringValue", dataFileStream.getMetaString("stringKey"));
assertEquals(100L, dataFileStream.getMetaLong("longKey"));
assertArrayEquals("bytesValue".getBytes(), dataFileStream.getMeta("bytesKey"));
}
use of org.apache.avro.file.DataFileStream in project beam by apache.
the class AvroIOTest method testAvroIONullCodecWriteAndReadASingleFile.
@Test
@SuppressWarnings("unchecked")
@Category(NeedsRunner.class)
public void testAvroIONullCodecWriteAndReadASingleFile() throws Throwable {
List<GenericClass> values = ImmutableList.of(new GenericClass(3, "hi"), new GenericClass(5, "bar"));
File outputFile = tmpFolder.newFile("output.avro");
p.apply(Create.of(values)).apply(AvroIO.write(GenericClass.class).to(outputFile.getAbsolutePath()).withoutSharding().withCodec(CodecFactory.nullCodec()));
p.run();
PCollection<GenericClass> input = p.apply(AvroIO.read(GenericClass.class).from(outputFile.getAbsolutePath()));
PAssert.that(input).containsInAnyOrder(values);
p.run();
DataFileStream dataFileStream = new DataFileStream(new FileInputStream(outputFile), new GenericDatumReader());
assertEquals("null", dataFileStream.getMetaString("avro.codec"));
}
use of org.apache.avro.file.DataFileStream in project cdap by caskdata.
the class DynamicPartitionerWithAvroTest method readOutput.
private Set<GenericRecord> readOutput(Location location) throws IOException {
DatumReader<GenericRecord> datumReader = new GenericDatumReader<>(SCHEMA);
Set<GenericRecord> records = new HashSet<>();
for (Location file : location.list()) {
if (file.getName().endsWith(".avro")) {
DataFileStream<GenericRecord> fileStream = new DataFileStream<>(file.getInputStream(), datumReader);
Iterables.addAll(records, fileStream);
fileStream.close();
}
}
return records;
}
Aggregations