Search in sources :

Example 91 with Row

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

the class ZetaSqlDialectSpecTest method testLikeNullPattern.

@Test
public void testLikeNullPattern() {
    String sql = "SELECT @p0 LIKE @p1 AS ColA";
    ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue("ab%"), "p1", Value.createSimpleNullValue(TypeKind.TYPE_STRING));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addNullableField("field1", FieldType.BOOLEAN).build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues((Object) null).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 92 with Row

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

the class ZetaSqlDialectSpecTest method testCaseWithValueMultipleCases.

@Test
public void testCaseWithValueMultipleCases() {
    String sql = "SELECT CASE 2 WHEN 1 THEN 'not possible' WHEN 2 THEN 'seems right' ELSE 'also not" + " possible' 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)

Example 93 with Row

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

the class ZetaSqlDialectSpecTest method testStructOfStructRemap.

@Test
@Ignore("[BEAM-9378] This should work, but is currently unimplemented.")
public void testStructOfStructRemap() {
    String sql = "SELECT STRUCT(row.row_id AS int_value_remapped) AS remapped FROM table_with_struct_of_struct";
    PCollection<Row> stream = execute(sql);
    Schema nested = Schema.builder().addInt64Field("int_value_remapped").build();
    Schema schema = Schema.builder().addRowField("remapped", nested).build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).attachValues(Row.withSchema(nested).attachValues(1L)), Row.withSchema(schema).attachValues(Row.withSchema(nested).attachValues(2L)));
    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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 94 with Row

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

the class ZetaSqlDialectSpecTest method testIfNullPositive.

@Test
public void testIfNullPositive() {
    String sql = "SELECT IFNULL(@p0, @p1) AS ColA";
    ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue("foo"), "p1", Value.createStringValue("default"));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addNullableField("field1", FieldType.STRING).build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues("foo").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 95 with Row

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

the class ZetaSqlDialectSpecTest method testZetaSQLSelectFromTableWithStructType2.

@Test
public void testZetaSQLSelectFromTableWithStructType2() {
    String sql = "SELECT table_with_struct.struct_col.struct_col_str FROM table_with_struct WHERE id = 1;";
    PCollection<Row> stream = execute(sql);
    final Schema schema = Schema.builder().addStringField("field").build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValue("row_one").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)

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