@Test public void testReaderWriterCompatibleSchema() throws IOException { DatasetWriter<TestValue> writer = null; try { writer = Datasets.load(testValueView.getUri(), TestValue.class).newWriter(); writer.write(testValue); } finally { Closeables.close(writer, false); } DatasetReader<Value> reader = null; try { reader = valueView.newReader(); Assert.assertEquals(Sets.newHashSet(defaultValue), Sets.newHashSet((Iterable<Value>) reader)); } finally { Closeables.close(reader, false); } }
@Test public void testSpecificProjectionAsType() throws IOException { Dataset<GenericRecord> original = Datasets.load(unbounded.getUri()); DatasetWriter<StandardEvent> writer = null; try { writer = original.asType(StandardEvent.class).newWriter(); writer.write(sepEvent); writer.write(octEvent); writer.write(novEvent); } finally { Closeables.close(writer, false); } final View<SmallEvent> smallEvents = original.asType(SmallEvent.class); Set<SmallEvent> expected = Sets.newHashSet(toSmallEvent(sepEvent), toSmallEvent(octEvent), toSmallEvent(novEvent)); assertContentEquals(expected, smallEvents); TestHelpers.assertThrows("Should not be able to write small events", IncompatibleSchemaException.class, new Runnable() { @Override public void run() { smallEvents.newWriter(); } }); }
@Test public void testGenericProjectionAsSchema() throws IOException { Dataset<StandardEvent> original = Datasets.load( unbounded.getUri(), StandardEvent.class); Schema standardEvent = Schemas.fromAvsc(conf, URI.create("resource:standard_event.avsc"));