use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testSelectMapOfRowSelectAll.
@Test
public void testSelectMapOfRowSelectAll() {
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("map{}.*").resolve(MAP_SCHEMA);
Schema outputSchema = SelectHelpers.getOutputSchema(MAP_SCHEMA, fieldAccessDescriptor);
Schema expectedSchema = Schema.builder().addMapField("field1", FieldType.INT32, FieldType.STRING).addMapField("field2", FieldType.INT32, FieldType.INT32).addMapField("field3", FieldType.INT32, FieldType.DOUBLE).addMapField("field_extra", FieldType.INT32, FieldType.STRING).build();
assertEquals(expectedSchema, outputSchema);
Row row = selectRow(MAP_SCHEMA, fieldAccessDescriptor, MAP_ROW);
Row expectedRow = Row.withSchema(expectedSchema).addValue(ImmutableMap.of(1, FLAT_ROW.getValue(0))).addValue(ImmutableMap.of(1, FLAT_ROW.getValue(1))).addValue(ImmutableMap.of(1, FLAT_ROW.getValue(2))).addValue(ImmutableMap.of(1, FLAT_ROW.getValue(3))).build();
assertEquals(expectedRow, row);
}
use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testSelectArrayOfPrimitive.
@Test
public void testSelectArrayOfPrimitive() {
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("primitiveArray").resolve(ARRAY_SCHEMA);
Schema outputSchema = SelectHelpers.getOutputSchema(ARRAY_SCHEMA, fieldAccessDescriptor);
Schema expectedSchema = Schema.builder().addArrayField("primitiveArray", FieldType.INT32).build();
assertEquals(expectedSchema, outputSchema);
Row row = selectRow(ARRAY_SCHEMA, fieldAccessDescriptor, ARRAY_ROW);
Row expectedRow = Row.withSchema(expectedSchema).addArray(1, 2).build();
assertEquals(expectedRow, row);
}
use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testSelectedNestedWildcard.
@Test
public void testSelectedNestedWildcard() {
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("nested.*").resolve(NESTED_SCHEMA);
Schema outputSchema = SelectHelpers.getOutputSchema(NESTED_SCHEMA, fieldAccessDescriptor);
assertEquals(FLAT_SCHEMA, outputSchema);
Row row = selectRow(NESTED_SCHEMA, fieldAccessDescriptor, NESTED_ROW);
assertEquals(FLAT_ROW, row);
}
use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testSelectNullableNestedRow.
@Test
public void testSelectNullableNestedRow() {
FieldAccessDescriptor fieldAccessDescriptor1 = FieldAccessDescriptor.withFieldNames("nested.field1").resolve(NESTED_NULLABLE_SCHEMA);
Row out1 = selectRow(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor1, Row.nullRow(NESTED_NULLABLE_SCHEMA));
assertNull(out1.getValue(0));
FieldAccessDescriptor fieldAccessDescriptor2 = FieldAccessDescriptor.withFieldNames("nested.*").resolve(NESTED_NULLABLE_SCHEMA);
Row out2 = selectRow(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor2, Row.nullRow(NESTED_NULLABLE_SCHEMA));
assertEquals(Collections.nCopies(4, null), out2.getValues());
}
use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testNullableSchema.
@Test
public void testNullableSchema() {
FieldAccessDescriptor fieldAccessDescriptor1 = FieldAccessDescriptor.withFieldNames("nested.field1").resolve(NESTED_NULLABLE_SCHEMA);
Schema schema1 = SelectHelpers.getOutputSchema(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor1);
Schema expectedSchema1 = Schema.builder().addNullableField("field1", FieldType.STRING).build();
assertEquals(expectedSchema1, schema1);
FieldAccessDescriptor fieldAccessDescriptor2 = FieldAccessDescriptor.withFieldNames("nested.*").resolve(NESTED_NULLABLE_SCHEMA);
Schema schema2 = SelectHelpers.getOutputSchema(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor2);
Schema expectedSchema2 = Schema.builder().addNullableField("field1", FieldType.STRING).addNullableField("field2", FieldType.INT32).addNullableField("field3", FieldType.DOUBLE).addNullableField("field_extra", FieldType.STRING).build();
assertEquals(expectedSchema2, schema2);
}
Aggregations