use of org.apache.beam.sdk.values.Row in project beam by apache.
the class AutoValueSchemaTest method testToRowNestedConstructor.
@Test
public void testToRowNestedConstructor() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
SimpleAutoValue inner = new AutoValue_AutoValueSchemaTest_SimpleAutoValue("string", (byte) 1, (short) 2, (int) 3, (long) 4, true, DATE, BYTE_ARRAY, ByteBuffer.wrap(BYTE_ARRAY), DATE.toInstant(), BigDecimal.ONE, STRING_BUILDER);
AutoValueOuter outer = new AutoValue_AutoValueSchemaTest_AutoValueOuter(inner);
Row row = registry.getToRowFunction(AutoValueOuter.class).apply(outer);
verifyRow(row.getRow("inner"));
}
use of org.apache.beam.sdk.values.Row in project beam by apache.
the class AutoValueSchemaTest method testFromRowNestedConstructor.
@Test
public void testFromRowNestedConstructor() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
Row inner = createSimpleRow("string");
Row outer = Row.withSchema(OUTER_SCHEMA).addValue(inner).build();
AutoValueOuter value = registry.getFromRowFunction(AutoValueOuter.class).apply(outer);
verifyAutoValue(value.getInner());
}
use of org.apache.beam.sdk.values.Row in project beam by apache.
the class JavaFieldSchemaTest method testFromRowWithGetters.
@Test
public void testFromRowWithGetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
SimplePOJO pojo = createSimple("string");
Row row = registry.getToRowFunction(SimplePOJO.class).apply(pojo);
// Test that the fromRowFunction simply returns the original object back.
SimplePOJO extracted = registry.getFromRowFunction(SimplePOJO.class).apply(row);
assertSame(pojo, extracted);
}
use of org.apache.beam.sdk.values.Row in project beam by apache.
the class JavaFieldSchemaTest method testRecursiveGetters.
@Test
public void testRecursiveGetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
SchemaTestUtils.assertSchemaEquivalent(NESTED_POJO_SCHEMA, registry.getSchema(NestedPOJO.class));
NestedPOJO pojo = new NestedPOJO(createSimple("string"));
Row row = registry.getToRowFunction(NestedPOJO.class).apply(pojo);
Row nestedRow = row.getRow("nested");
assertEquals("string", nestedRow.getString("str"));
assertEquals((byte) 1, (Object) nestedRow.getByte("aByte"));
assertEquals((short) 2, (Object) nestedRow.getInt16("aShort"));
assertEquals((int) 3, (Object) nestedRow.getInt32("anInt"));
assertEquals((long) 4, (Object) nestedRow.getInt64("aLong"));
assertTrue(nestedRow.getBoolean("aBoolean"));
assertEquals(DATE.toInstant(), nestedRow.getDateTime("dateTime"));
assertEquals(INSTANT, nestedRow.getDateTime("instant").toInstant());
assertArrayEquals("not equal", BYTE_ARRAY, nestedRow.getBytes("bytes"));
assertArrayEquals("not equal", BYTE_BUFFER.array(), nestedRow.getBytes("byteBuffer"));
assertEquals(BigDecimal.ONE, nestedRow.getDecimal("bigDecimal"));
assertEquals("stringbuilder", nestedRow.getString("stringBuilder"));
}
use of org.apache.beam.sdk.values.Row in project beam by apache.
the class JavaFieldSchemaTest method testMapFieldSetters.
@Test
public void testMapFieldSetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
Row row1 = createSimpleRow("string1");
Row row2 = createSimpleRow("string2");
Row row3 = createSimpleRow("string3");
Row row = Row.withSchema(NESTED_MAP_POJO_SCHEMA).addValue(ImmutableMap.of("simple1", row1, "simple2", row2, "simple3", row3)).build();
NestedMapPOJO pojo = registry.getFromRowFunction(NestedMapPOJO.class).apply(row);
assertEquals(3, pojo.map.size());
assertEquals("string1", pojo.map.get("simple1").str);
assertEquals("string2", pojo.map.get("simple2").str);
assertEquals("string3", pojo.map.get("simple3").str);
}
Aggregations