Search in sources :

Example 1 with NestedMapPOJO

use of org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedMapPOJO 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);
}
Also used : NestedMapPOJO(org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedMapPOJO) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 2 with NestedMapPOJO

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

the class JavaFieldSchemaTest method testMapFieldGetters.

@Test
public void testMapFieldGetters() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    SchemaTestUtils.assertSchemaEquivalent(NESTED_MAP_POJO_SCHEMA, registry.getSchema(NestedMapPOJO.class));
    SimplePOJO simple1 = createSimple("string1");
    SimplePOJO simple2 = createSimple("string2");
    SimplePOJO simple3 = createSimple("string3");
    NestedMapPOJO pojo = new NestedMapPOJO(ImmutableMap.of("simple1", simple1, "simple2", simple2, "simple3", simple3));
    Row row = registry.getToRowFunction(NestedMapPOJO.class).apply(pojo);
    Map<String, Row> extractedMap = row.getMap("map");
    assertEquals(3, extractedMap.size());
    assertEquals("string1", extractedMap.get("simple1").getString("str"));
    assertEquals("string2", extractedMap.get("simple2").getString("str"));
    assertEquals("string3", extractedMap.get("simple3").getString("str"));
}
Also used : NestedMapPOJO(org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedMapPOJO) Row(org.apache.beam.sdk.values.Row) Matchers.containsString(org.hamcrest.Matchers.containsString) SimplePOJO(org.apache.beam.sdk.schemas.utils.TestPOJOs.SimplePOJO) Test(org.junit.Test)

Aggregations

NestedMapPOJO (org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedMapPOJO)2 Row (org.apache.beam.sdk.values.Row)2 Test (org.junit.Test)2 SimplePOJO (org.apache.beam.sdk.schemas.utils.TestPOJOs.SimplePOJO)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1