Search in sources :

Example 16 with Row

use of org.apache.beam.sdk.values.Row in project beam by apache.

the class AutoValueSchemaTest method testFromRow_SchemaFieldNumber.

@Test
public void testFromRow_SchemaFieldNumber() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    Row row = Row.withSchema(FIELD_NUMBER_SCHEMA).withFieldValue("lng", 42L).withFieldValue("str", "value!").build();
    SchemaFieldNumberSimpleClass value = registry.getFromRowFunction(SchemaFieldNumberSimpleClass.class).apply(row);
    assertEquals("value!", value.getStr());
    assertEquals(42L, (long) value.getLng());
}
Also used : Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 17 with Row

use of org.apache.beam.sdk.values.Row in project beam by apache.

the class AutoValueSchemaTest method testToRowConstructor.

@Test
public void testToRowConstructor() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    SimpleAutoValue value = new AutoValue_AutoValueSchemaTest_SimpleAutoValue("string", (byte) 1, (short) 2, (int) 3, (long) 4, true, DATE, BYTE_ARRAY, ByteBuffer.wrap(BYTE_ARRAY), DATE.toInstant(), BigDecimal.ONE, STRING_BUILDER);
    Row row = registry.getToRowFunction(SimpleAutoValue.class).apply(value);
    verifyRow(row);
}
Also used : Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 18 with Row

use of org.apache.beam.sdk.values.Row in project beam by apache.

the class AutoValueSchemaTest method testFromRowBuilder.

@Test
public void testFromRowBuilder() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    Row row = createSimpleRow("string");
    SimpleAutoValueWithBuilder value = registry.getFromRowFunction(SimpleAutoValueWithBuilder.class).apply(row);
    verifyAutoValue(value);
}
Also used : Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 19 with Row

use of org.apache.beam.sdk.values.Row in project beam by apache.

the class AutoValueSchemaTest method testToRowBuilder.

@Test
public void testToRowBuilder() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    SimpleAutoValueWithBuilder value = new AutoValue_AutoValueSchemaTest_SimpleAutoValueWithBuilder.Builder().setStr("string").setaByte((byte) 1).setaShort((short) 2).setAnInt((int) 3).setaLong((long) 4).setaBoolean(true).setDateTime(DATE).setBytes(BYTE_ARRAY).setByteBuffer(ByteBuffer.wrap(BYTE_ARRAY)).setInstant(DATE.toInstant()).setBigDecimal(BigDecimal.ONE).setStringBuilder(STRING_BUILDER).build();
    Row row = registry.getToRowFunction(SimpleAutoValueWithBuilder.class).apply(value);
    verifyRow(row);
}
Also used : Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 20 with Row

use of org.apache.beam.sdk.values.Row in project beam by apache.

the class AutoValueSchemaTest method testFromRowNestedBuilder.

@Test
public void testFromRowNestedBuilder() throws NoSuchSchemaException {
    SchemaRegistry registry = SchemaRegistry.createDefault();
    Row inner = createSimpleRow("string");
    Row outer = Row.withSchema(OUTER_SCHEMA).addValue(inner).build();
    AutoValueOuterWithBuilder value = registry.getFromRowFunction(AutoValueOuterWithBuilder.class).apply(outer);
    verifyAutoValue(value.getInner());
}
Also used : 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