use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testSelectArrayOfNestedRow.
@Test
public void testSelectArrayOfNestedRow() {
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("nestedRowArray[].nested.field1").resolve(ARRAY_SCHEMA);
Schema outputSchema = SelectHelpers.getOutputSchema(ARRAY_SCHEMA, fieldAccessDescriptor);
Schema.builder().addStringField("field1").build();
Schema expectedSchema = Schema.builder().addArrayField("field1", FieldType.STRING).build();
assertEquals(expectedSchema, outputSchema);
Row row = selectRow(ARRAY_SCHEMA, fieldAccessDescriptor, ARRAY_ROW);
Row expectedRow = Row.withSchema(expectedSchema).addArray("first", "first").build();
assertEquals(expectedRow, row);
}
use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testsSimpleSelectSingle.
@Test
public void testsSimpleSelectSingle() {
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("field1").resolve(FLAT_SCHEMA);
Schema outputSchema = SelectHelpers.getOutputSchema(FLAT_SCHEMA, fieldAccessDescriptor);
Schema expectedSchema = Schema.builder().addStringField("field1").build();
assertEquals(expectedSchema, outputSchema);
Row row = selectRow(FLAT_SCHEMA, fieldAccessDescriptor, FLAT_ROW);
Row expectedRow = Row.withSchema(expectedSchema).addValue("first").build();
assertEquals(expectedRow, row);
}
use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testIterableRowIterable.
@Test
public void testIterableRowIterable() {
Schema f1 = Schema.builder().addStringField("f0").build();
Schema f2 = Schema.builder().addIterableField("f1", FieldType.row(f1)).build();
Schema f3 = Schema.builder().addRowField("f2", f2).build();
Schema f4 = Schema.builder().addIterableField("f3", FieldType.row(f3)).build();
Row r1 = Row.withSchema(f1).addValue("first").build();
Row r2 = Row.withSchema(f2).addIterable(ImmutableList.of(r1, r1)).build();
Row r3 = Row.withSchema(f3).addValue(r2).build();
Row r4 = Row.withSchema(f4).addIterable(ImmutableList.of(r3, r3)).build();
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("f3.f2.f1.f0").resolve(f4);
Schema outputSchema = SelectHelpers.getOutputSchema(f4, fieldAccessDescriptor);
Schema expectedSchema = Schema.builder().addIterableField("f0", FieldType.iterable(FieldType.STRING)).build();
assertEquals(expectedSchema, outputSchema);
Row out = selectRow(f4, fieldAccessDescriptor, r4);
Row expected = Row.withSchema(outputSchema).addIterable(ImmutableList.of(ImmutableList.of("first", "first"), ImmutableList.of("first", "first"))).build();
assertEquals(expected, out);
}
use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testSelectMapOfIterable.
@Test
public void testSelectMapOfIterable() {
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("map.field1").resolve(MAP_ITERABLE_SCHEMA);
Schema outputSchema = SelectHelpers.getOutputSchema(MAP_ITERABLE_SCHEMA, fieldAccessDescriptor);
Schema expectedSchema = Schema.builder().addMapField("field1", FieldType.INT32, FieldType.iterable(FieldType.STRING)).build();
assertEquals(expectedSchema, outputSchema);
Row row = selectRow(MAP_ITERABLE_SCHEMA, fieldAccessDescriptor, MAP_ITERABLE_ROW);
Row expectedRow = Row.withSchema(expectedSchema).addValue(ImmutableMap.of(1, ImmutableList.of("first"))).build();
assertEquals(expectedRow, row);
}
use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testsSimpleSelectSingleWithUnderscore.
@Test
public void testsSimpleSelectSingleWithUnderscore() {
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("field_extra").resolve(FLAT_SCHEMA);
Schema outputSchema = SelectHelpers.getOutputSchema(FLAT_SCHEMA, fieldAccessDescriptor);
Schema expectedSchema = Schema.builder().addStringField("field_extra").build();
assertEquals(expectedSchema, outputSchema);
Row row = selectRow(FLAT_SCHEMA, fieldAccessDescriptor, FLAT_ROW);
Row expectedRow = Row.withSchema(expectedSchema).addValue("extra").build();
assertEquals(expectedRow, row);
}
Aggregations