use of org.apache.beam.sdk.values.Row in project beam by apache.
the class RowCoderTest method testConsistentWithEqualsMapWithNull.
@Test
public void testConsistentWithEqualsMapWithNull() throws Exception {
Schema schema = Schema.builder().addField("a", Schema.FieldType.map(Schema.FieldType.INT32, Schema.FieldType.INT32.withNullable(true))).build();
Row row = Row.withSchema(schema).addValue(Collections.singletonMap(1, null)).build();
CoderProperties.coderDecodeEncodeEqual(RowCoder.of(schema), row);
}
use of org.apache.beam.sdk.values.Row in project beam by apache.
the class RowCoderTest method testEncodingPositionAddNewFieldsAndReorderExisting.
@Test
public void testEncodingPositionAddNewFieldsAndReorderExisting() throws Exception {
Schema schema1 = Schema.builder().addNullableField("f_int32", FieldType.INT32).addNullableField("f_string", FieldType.STRING).build();
Schema schema2 = Schema.builder().addNullableField("f_int32", FieldType.INT32).addNullableField("f_boolean", FieldType.BOOLEAN).addNullableField("f_string", FieldType.STRING).build();
schema2.setEncodingPositions(ImmutableMap.of("f_int32", 0, "f_string", 1, "f_boolean", 2));
Row row = Row.withSchema(schema1).withFieldValue("f_int32", 42).withFieldValue("f_string", "hello world!").build();
Row expected = Row.withSchema(schema2).withFieldValue("f_int32", 42).withFieldValue("f_string", "hello world!").build();
ByteArrayOutputStream os = new ByteArrayOutputStream();
RowCoder.of(schema1).encode(row, os);
Row decoded = RowCoder.of(schema2).decode(new ByteArrayInputStream(os.toByteArray()));
assertEquals(expected, decoded);
}
use of org.apache.beam.sdk.values.Row in project beam by apache.
the class RowCoderTest method testConsistentWithEqualsMapWithBytesKeyField.
@Test
@Ignore
public void testConsistentWithEqualsMapWithBytesKeyField() throws Exception {
FieldType fieldType = FieldType.map(FieldType.BYTES, FieldType.INT32);
Schema schema = Schema.of(Schema.Field.of("f1", fieldType));
RowCoder coder = RowCoder.of(schema);
Map<byte[], Integer> map1 = Collections.singletonMap(new byte[] { 1, 2, 3, 4 }, 1);
Row row1 = Row.withSchema(schema).addValue(map1).build();
Map<byte[], Integer> map2 = Collections.singletonMap(new byte[] { 1, 2, 3, 4 }, 1);
Row row2 = Row.withSchema(schema).addValue(map2).build();
Assume.assumeTrue(coder.consistentWithEquals());
CoderProperties.coderConsistentWithEquals(coder, row1, row2);
}
use of org.apache.beam.sdk.values.Row in project beam by apache.
the class RowCoderTest method testIterables.
@Test
public void testIterables() throws Exception {
Schema schema = Schema.builder().addIterableField("f_iter", FieldType.STRING).build();
Row row = Row.withSchema(schema).addIterable(ImmutableList.of("one", "two", "three", "four")).build();
CoderProperties.coderDecodeEncodeEqual(RowCoder.of(schema), row);
}
use of org.apache.beam.sdk.values.Row in project beam by apache.
the class RowCoderTest method testConsistentWithEqualsArrayWithNull.
@Test
public void testConsistentWithEqualsArrayWithNull() throws Exception {
Schema schema = Schema.builder().addField("a", Schema.FieldType.array(Schema.FieldType.INT32.withNullable(true))).build();
Row row = Row.withSchema(schema).addValue(Arrays.asList(1, null)).build();
CoderProperties.coderDecodeEncodeEqual(RowCoder.of(schema), row);
}
Aggregations