Search in sources :

Example 1 with NestedArrayBean

use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.NestedArrayBean in project beam by apache.

the class JavaBeanSchemaTest method testRecursiveArrayGetters.

@Test
public void testRecursiveArrayGetters() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    SchemaTestUtils.assertSchemaEquivalent(NESTED_ARRAY_BEAN_SCHEMA, registry.getSchema(NestedArrayBean.class));
    SimpleBean simple1 = createSimple("string1");
    SimpleBean simple2 = createSimple("string2");
    SimpleBean simple3 = createSimple("string3");
    NestedArrayBean bean = new NestedArrayBean(simple1, simple2, simple3);
    Row row = registry.getToRowFunction(NestedArrayBean.class).apply(bean);
    List<Row> rows = (List) row.getArray("beans");
    assertSame(simple1, registry.getFromRowFunction(SimpleBean.class).apply(rows.get(0)));
    assertSame(simple2, registry.getFromRowFunction(SimpleBean.class).apply(rows.get(1)));
    assertSame(simple3, registry.getFromRowFunction(SimpleBean.class).apply(rows.get(2)));
}
Also used : SimpleBean(org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean) NestedArrayBean(org.apache.beam.sdk.schemas.utils.TestJavaBeans.NestedArrayBean) 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) Test(org.junit.Test)

Example 2 with NestedArrayBean

use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.NestedArrayBean in project beam by apache.

the class JavaBeanSchemaTest 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_BEAN_SCHEMA).addArray(row1, row2, row3).build();
    NestedArrayBean bean = registry.getFromRowFunction(NestedArrayBean.class).apply(row);
    assertEquals(3, bean.getBeans().length);
    assertEquals("string1", bean.getBeans()[0].getStr());
    assertEquals("string2", bean.getBeans()[1].getStr());
    assertEquals("string3", bean.getBeans()[2].getStr());
}
Also used : NestedArrayBean(org.apache.beam.sdk.schemas.utils.TestJavaBeans.NestedArrayBean) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Aggregations

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