Search in sources :

Example 1 with NestedArrayPOJO

use of org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedArrayPOJO in project beam by apache.

the class JavaFieldSchemaTest method testRecursiveArraySetters.

@Test
public void testRecursiveArraySetters() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    Row row1 = createSimpleRow("string1");
    Row row2 = createSimpleRow("string2");
    Row row3 = createSimpleRow("string3");
    ;
    Row row = Row.withSchema(NESTED_ARRAY_POJO_SCHEMA).addArray(row1, row2, row3).build();
    NestedArrayPOJO pojo = registry.getFromRowFunction(NestedArrayPOJO.class).apply(row);
    assertEquals(3, pojo.pojos.length);
    assertEquals("string1", pojo.pojos[0].str);
    assertEquals("string2", pojo.pojos[1].str);
    assertEquals("string3", pojo.pojos[2].str);
}
Also used : NestedArrayPOJO(org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedArrayPOJO) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 2 with NestedArrayPOJO

use of org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedArrayPOJO in project beam by apache.

the class JavaFieldSchemaTest method testRecursiveArrayGetters.

@Test
public void testRecursiveArrayGetters() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    SchemaTestUtils.assertSchemaEquivalent(NESTED_ARRAY_POJO_SCHEMA, registry.getSchema(NestedArrayPOJO.class));
    SimplePOJO simple1 = createSimple("string1");
    SimplePOJO simple2 = createSimple("string2");
    SimplePOJO simple3 = createSimple("string3");
    NestedArrayPOJO pojo = new NestedArrayPOJO(simple1, simple2, simple3);
    Row row = registry.getToRowFunction(NestedArrayPOJO.class).apply(pojo);
    List<Row> rows = (List) row.getArray("pojos");
    assertSame(simple1, registry.getFromRowFunction(SimplePOJO.class).apply(rows.get(0)));
    assertSame(simple2, registry.getFromRowFunction(SimplePOJO.class).apply(rows.get(1)));
    assertSame(simple3, registry.getFromRowFunction(SimplePOJO.class).apply(rows.get(2)));
}
Also used : NestedArrayPOJO(org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedArrayPOJO) List(java.util.List) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) Row(org.apache.beam.sdk.values.Row) SimplePOJO(org.apache.beam.sdk.schemas.utils.TestPOJOs.SimplePOJO) Test(org.junit.Test)

Aggregations

NestedArrayPOJO (org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedArrayPOJO)2 Row (org.apache.beam.sdk.values.Row)2 Test (org.junit.Test)2 List (java.util.List)1 SimplePOJO (org.apache.beam.sdk.schemas.utils.TestPOJOs.SimplePOJO)1 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)1