use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testArrayRowArray.
@Test
public void testArrayRowArray() {
Schema f1 = Schema.builder().addStringField("f0").build();
Schema f2 = Schema.builder().addArrayField("f1", FieldType.row(f1)).build();
Schema f3 = Schema.builder().addRowField("f2", f2).build();
Schema f4 = Schema.builder().addArrayField("f3", FieldType.row(f3)).build();
Row r1 = Row.withSchema(f1).addValue("first").build();
Row r2 = Row.withSchema(f2).addArray(r1, r1).build();
Row r3 = Row.withSchema(f3).addValue(r2).build();
Row r4 = Row.withSchema(f4).addArray(r3, r3).build();
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("f3.f2.f1.f0").resolve(f4);
Schema outputSchema = SelectHelpers.getOutputSchema(f4, fieldAccessDescriptor);
Schema expectedSchema = Schema.builder().addArrayField("f0", FieldType.array(FieldType.STRING)).build();
assertEquals(expectedSchema, outputSchema);
Row out = selectRow(f4, fieldAccessDescriptor, r4);
Row expected = Row.withSchema(outputSchema).addArray(Lists.newArrayList("first", "first"), Lists.newArrayList("first", "first")).build();
assertEquals(expected, out);
}
use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testSelectDoubleNested.
@Test
public void testSelectDoubleNested() {
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("nested2.nested.field1").resolve(DOUBLE_NESTED_SCHEMA);
Schema outputSchema = SelectHelpers.getOutputSchema(DOUBLE_NESTED_SCHEMA, fieldAccessDescriptor);
Schema expectedSchema = Schema.builder().addStringField("field1").build();
assertEquals(expectedSchema, outputSchema);
Row row = selectRow(DOUBLE_NESTED_SCHEMA, fieldAccessDescriptor, DOUBLE_NESTED_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 testSelectIterableOfPrimitive.
@Test
public void testSelectIterableOfPrimitive() {
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("primitiveIter").resolve(ITERABLE_SCHEMA);
Schema outputSchema = SelectHelpers.getOutputSchema(ITERABLE_SCHEMA, fieldAccessDescriptor);
Schema expectedSchema = Schema.builder().addIterableField("primitiveIter", FieldType.INT32).build();
assertEquals(expectedSchema, outputSchema);
Row row = selectRow(ITERABLE_SCHEMA, fieldAccessDescriptor, ITERABLE_ROW);
Row expectedRow = Row.withSchema(expectedSchema).addIterable(ImmutableList.of(1, 2)).build();
assertEquals(expectedRow, row);
}
use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testNullableSchemaArray.
@Test
public void testNullableSchemaArray() {
FieldAccessDescriptor fieldAccessDescriptor1 = FieldAccessDescriptor.withFieldNames("nestedArray.field1").resolve(NESTED_NULLABLE_SCHEMA);
Schema schema1 = SelectHelpers.getOutputSchema(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor1);
Schema expectedSchema1 = Schema.builder().addNullableField("field1", FieldType.array(FieldType.STRING)).build();
assertEquals(expectedSchema1, schema1);
FieldAccessDescriptor fieldAccessDescriptor2 = FieldAccessDescriptor.withFieldNames("nestedArray.*").resolve(NESTED_NULLABLE_SCHEMA);
Schema schema2 = SelectHelpers.getOutputSchema(NESTED_NULLABLE_SCHEMA, fieldAccessDescriptor2);
Schema expectedSchema2 = Schema.builder().addNullableField("field1", FieldType.array(FieldType.STRING)).addNullableField("field2", FieldType.array(FieldType.INT32)).addNullableField("field3", FieldType.array(FieldType.DOUBLE)).addNullableField("field_extra", FieldType.array(FieldType.STRING)).build();
assertEquals(expectedSchema2, schema2);
}
use of org.apache.beam.sdk.schemas.FieldAccessDescriptor in project beam by apache.
the class SelectHelpersTest method testSelectFieldOfRecord.
@Test
public void testSelectFieldOfRecord() {
Schema f1 = Schema.builder().addInt64Field("f0").build();
Schema f2 = Schema.builder().addRowField("f1", f1).build();
Schema f3 = Schema.builder().addRowField("f2", f2).build();
// {"f0": 42}
Row r1 = Row.withSchema(f1).addValue(42L).build();
// {"f1": {"f0": 42}}
Row r2 = Row.withSchema(f2).addValue(r1).build();
// {"f2": {"f1": {"f0": 42}}}
Row r3 = Row.withSchema(f3).addValue(r2).build();
FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withFieldNames("f2.f1").resolve(f3);
Schema outputSchema = SelectHelpers.getOutputSchema(f3, fieldAccessDescriptor);
Row out = selectRow(f3, fieldAccessDescriptor, r3);
assertEquals(f2, outputSchema);
assertEquals(r2, out);
}
Aggregations