Search in sources :

Example 41 with Row

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);
}
Also used : Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 42 with 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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 43 with Row

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);
}
Also used : Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) FieldType(org.apache.beam.sdk.schemas.Schema.FieldType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 44 with Row

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);
}
Also used : Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 45 with 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);
}
Also used : Schema(org.apache.beam.sdk.schemas.Schema) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Aggregations

Row (org.apache.beam.sdk.values.Row)958 Test (org.junit.Test)879 Schema (org.apache.beam.sdk.schemas.Schema)566 ByteString (com.google.protobuf.ByteString)219 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)206 Matchers.containsString (org.hamcrest.Matchers.containsString)85 Category (org.junit.experimental.categories.Category)72 Value (com.google.zetasql.Value)66 List (java.util.List)49 FieldAccessDescriptor (org.apache.beam.sdk.schemas.FieldAccessDescriptor)49 DateTime (org.joda.time.DateTime)46 UsesSchema (org.apache.beam.sdk.testing.UsesSchema)43 DefaultSchema (org.apache.beam.sdk.schemas.annotations.DefaultSchema)36 PCollection (org.apache.beam.sdk.values.PCollection)36 BeamSqlEnv (org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv)35 FieldType (org.apache.beam.sdk.schemas.Schema.FieldType)33 ArrayList (java.util.ArrayList)29 BeamIOSourceRel (org.apache.beam.sdk.extensions.sql.impl.rel.BeamIOSourceRel)28 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)28 Ignore (org.junit.Ignore)27