use of org.apache.beam.sdk.schemas.Schema.FieldType in project beam by apache.
the class RowCoderTest method testArrayOfRow.
@Test
public void testArrayOfRow() throws Exception {
Schema nestedSchema = Schema.builder().addInt32Field("f1_int").addStringField("f1_str").build();
FieldType collectionElementType = FieldType.row(nestedSchema);
Schema schema = Schema.builder().addArrayField("f_array", collectionElementType).build();
Row row = Row.withSchema(schema).addArray(Row.withSchema(nestedSchema).addValues(1, "one").build(), Row.withSchema(nestedSchema).addValues(2, "two").build(), Row.withSchema(nestedSchema).addValues(3, "three").build()).build();
CoderProperties.coderDecodeEncodeEqual(RowCoder.of(schema), row);
}
use of org.apache.beam.sdk.schemas.Schema.FieldType in project beam by apache.
the class RowCoderTest method testIterableOfRow.
@Test
public void testIterableOfRow() throws Exception {
Schema nestedSchema = Schema.builder().addInt32Field("f1_int").addStringField("f1_str").build();
FieldType collectionElementType = FieldType.row(nestedSchema);
Schema schema = Schema.builder().addIterableField("f_iter", collectionElementType).build();
Row row = Row.withSchema(schema).addIterable(ImmutableList.of(Row.withSchema(nestedSchema).addValues(1, "one").build(), Row.withSchema(nestedSchema).addValues(2, "two").build(), Row.withSchema(nestedSchema).addValues(3, "three").build())).build();
CoderProperties.coderDecodeEncodeEqual(RowCoder.of(schema), row);
}
use of org.apache.beam.sdk.schemas.Schema.FieldType in project beam by apache.
the class RowCoderTest method testConsistentWithEqualsArrayOfBytes.
@Test
public void testConsistentWithEqualsArrayOfBytes() throws Exception {
FieldType fieldType = FieldType.array(FieldType.BYTES);
Schema schema = Schema.of(Schema.Field.of("f1", fieldType));
RowCoder coder = RowCoder.of(schema);
List<byte[]> list1 = Collections.singletonList(new byte[] { 1, 2, 3, 4 });
Row row1 = Row.withSchema(schema).addValue(list1).build();
List<byte[]> list2 = Collections.singletonList(new byte[] { 1, 2, 3, 4 });
Row row2 = Row.withSchema(schema).addValue(list2).build();
Assume.assumeTrue(coder.consistentWithEquals());
CoderProperties.coderConsistentWithEquals(coder, row1, row2);
}
use of org.apache.beam.sdk.schemas.Schema.FieldType in project beam by apache.
the class RowCoderTest method testIterableOfIterable.
@Test
public void testIterableOfIterable() throws Exception {
FieldType iterableType = FieldType.iterable(FieldType.array(FieldType.INT32));
Schema schema = Schema.builder().addField("f_iter", iterableType).build();
Row row = Row.withSchema(schema).addIterable(ImmutableList.of(Lists.newArrayList(1, 2, 3, 4), Lists.newArrayList(5, 6, 7, 8), Lists.newArrayList(9, 10, 11, 12))).build();
CoderProperties.coderDecodeEncodeEqual(RowCoder.of(schema), row);
}
use of org.apache.beam.sdk.schemas.Schema.FieldType in project beam by apache.
the class Row method getBaseValue.
/**
* Returns the base type for this field. If this is a logical type, we convert to the base value.
* Otherwise the field itself is returned.
*/
@Nullable
public <T> T getBaseValue(int idx, Class<T> clazz) {
Object value = getValue(idx);
FieldType fieldType = getSchema().getField(idx).getType();
if (fieldType.getTypeName().isLogicalType() && value != null) {
while (fieldType.getTypeName().isLogicalType()) {
value = fieldType.getLogicalType().toBaseType(value);
fieldType = fieldType.getLogicalType().getBaseType();
}
}
return (T) value;
}
Aggregations