Search in sources :

Example 1 with PojoWithNestedArray

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

the class JavaFieldSchemaTest method testNestedArraysToRow.

@Test
public void testNestedArraysToRow() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    Schema schema = registry.getSchema(PojoWithNestedArray.class);
    SchemaTestUtils.assertSchemaEquivalent(POJO_WITH_NESTED_ARRAY_SCHEMA, schema);
    Row simpleRow = createSimpleRow("string");
    List<Row> list = ImmutableList.of(simpleRow, simpleRow);
    List<List<Row>> listOfList = ImmutableList.of(list, list);
    Row nestedRow = Row.withSchema(POJO_WITH_NESTED_ARRAY_SCHEMA).addValue(listOfList).build();
    SimplePOJO simplePojo = createSimple("string");
    List<SimplePOJO> simplePojoList = ImmutableList.of(simplePojo, simplePojo);
    List<List<SimplePOJO>> simplePojoListOfList = ImmutableList.of(simplePojoList, simplePojoList);
    Row converted = registry.getToRowFunction(PojoWithNestedArray.class).apply(new PojoWithNestedArray(simplePojoListOfList));
    assertEquals(nestedRow, converted);
}
Also used : PojoWithNestedArray(org.apache.beam.sdk.schemas.utils.TestPOJOs.PojoWithNestedArray) 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)

Example 2 with PojoWithNestedArray

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

the class JavaFieldSchemaTest method testNestedArraysFromRow.

@Test
public void testNestedArraysFromRow() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    Schema schema = registry.getSchema(PojoWithNestedArray.class);
    SchemaTestUtils.assertSchemaEquivalent(POJO_WITH_NESTED_ARRAY_SCHEMA, schema);
    Row simpleRow = createSimpleRow("string");
    List<Row> list = ImmutableList.of(simpleRow, simpleRow);
    List<List<Row>> listOfList = ImmutableList.of(list, list);
    Row nestedRow = Row.withSchema(POJO_WITH_NESTED_ARRAY_SCHEMA).addValue(listOfList).build();
    SimplePOJO simplePojo = createSimple("string");
    List<SimplePOJO> simplePojoList = ImmutableList.of(simplePojo, simplePojo);
    List<List<SimplePOJO>> simplePojoListOfList = ImmutableList.of(simplePojoList, simplePojoList);
    PojoWithNestedArray converted = registry.getFromRowFunction(PojoWithNestedArray.class).apply(nestedRow);
    assertEquals(simplePojoListOfList, converted.pojos);
}
Also used : PojoWithNestedArray(org.apache.beam.sdk.schemas.utils.TestPOJOs.PojoWithNestedArray) 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

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