Search in sources :

Example 96 with Row

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

the class ZetaSqlDialectSpecTest method testStructOfStructPassthrough.

@Test
public void testStructOfStructPassthrough() {
    String sql = "SELECT * FROM table_with_struct_of_struct";
    PCollection<Row> stream = execute(sql);
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(TestInput.STRUCT_OF_STRUCT).attachValues(Row.withSchema(TestInput.STRUCT_SCHEMA).attachValues(1L, "1")), Row.withSchema(TestInput.STRUCT_OF_STRUCT).attachValues(Row.withSchema(TestInput.STRUCT_SCHEMA).attachValues(2L, "2")));
    pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Also used : ByteString(com.google.protobuf.ByteString) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 97 with Row

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

the class ZetaSqlDialectSpecTest method testZetaSQLBitOrNull.

@Test
public void testZetaSQLBitOrNull() {
    String sql = "SELECT bit_or(CAST(x as int64)) FROM " + "(SELECT NULL x UNION ALL SELECT 5 UNION ALL SELECT 6);";
    PCollection<Row> stream = execute(sql);
    final Schema schema = Schema.builder().addInt64Field("field1").build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValue(7L).build());
    pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Also used : Schema(org.apache.beam.sdk.schemas.Schema) ByteString(com.google.protobuf.ByteString) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 98 with Row

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

the class ZetaSqlDialectSpecTest method testZetaSQLSelectFromTableOrderByNoSelectLimit.

@Test
public void testZetaSQLSelectFromTableOrderByNoSelectLimit() {
    String sql = "SELECT Value FROM KeyValue ORDER BY Key DESC LIMIT 2;";
    PCollection<Row> stream = execute(sql);
    final Schema schema = Schema.builder().addStringField("field2").build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues("KeyValue234").build(), Row.withSchema(schema).addValues("KeyValue235").build());
    pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Also used : Schema(org.apache.beam.sdk.schemas.Schema) ByteString(com.google.protobuf.ByteString) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 99 with Row

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

the class ZetaSqlDialectSpecTest method testReplace1.

@Test
public void testReplace1() {
    String sql = "SELECT REPLACE(@p0, @p1, @p2) AS ColA";
    ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue(""), "p1", Value.createStringValue(""), "p2", Value.createStringValue("a"));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addStringField("field1").build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues("").build());
    pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Also used : Schema(org.apache.beam.sdk.schemas.Schema) Value(com.google.zetasql.Value) ByteString(com.google.protobuf.ByteString) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 100 with Row

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

the class ZetaSqlDialectSpecTest method testCaseWithValueNoElse.

@Test
public void testCaseWithValueNoElse() {
    String sql = "SELECT CASE 2 WHEN 1 THEN 'not possible' WHEN 2 THEN 'seems right' END";
    PCollection<Row> stream = execute(sql);
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(Schema.builder().addStringField("str_field").build()).addValue("seems right").build());
    pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Also used : ByteString(com.google.protobuf.ByteString) 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