Search in sources :

Example 46 with Value

use of com.google.zetasql.Value in project beam by apache.

the class ZetaSqlDialectSpecTest method testParameterStructNested.

@Test
public void testParameterStructNested() {
    String sql = "SELECT @outer_struct.inner_struct.s as ColA";
    StructType innerStructType = TypeFactory.createStructType(ImmutableList.of(new StructType.StructField("s", TypeFactory.createSimpleType(TypeKind.TYPE_STRING))));
    ImmutableMap<String, Value> params = ImmutableMap.of("outer_struct", Value.createStructValue(TypeFactory.createStructType(ImmutableList.of(new StructType.StructField("inner_struct", innerStructType))), ImmutableList.of(Value.createStructValue(innerStructType, ImmutableList.of(Value.createStringValue("foo"))))));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addStringField("field1").build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValue("foo").build());
    pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Also used : StructField(com.google.zetasql.StructType.StructField) StructType(com.google.zetasql.StructType) 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 47 with Value

use of com.google.zetasql.Value in project beam by apache.

the class ZetaSqlDialectSpecTest method testCharLengthNull.

@Test
public void testCharLengthNull() {
    String sql = "SELECT CHAR_LENGTH(@p0);";
    ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createSimpleNullValue(TypeKind.TYPE_STRING));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addNullableField("field", FieldType.INT64).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 48 with Value

use of com.google.zetasql.Value in project beam by apache.

the class ZetaSqlDialectSpecTest method testIsNullTrueFalse.

@Test
public void testIsNullTrueFalse() {
    String sql = "WITH Src AS (\n" + "  SELECT NULL as data UNION ALL\n" + "  SELECT TRUE UNION ALL\n" + "  SELECT FALSE\n" + ")\n" + "SELECT\n" + "  data IS NULL as isnull,\n" + "  data IS NOT NULL as isnotnull,\n" + "  data IS TRUE as istrue,\n" + "  data IS NOT TRUE as isnottrue,\n" + "  data IS FALSE as isfalse,\n" + "  data IS NOT FALSE as isnotfalse\n" + "FROM Src\n";
    ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
    ImmutableMap<String, Value> params = ImmutableMap.of();
    BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql, params);
    PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
    final Schema schema = Schema.builder().addField("isnull", FieldType.BOOLEAN).addField("isnotnull", FieldType.BOOLEAN).addField("istrue", FieldType.BOOLEAN).addField("isnottrue", FieldType.BOOLEAN).addField("isfalse", FieldType.BOOLEAN).addField("isnotfalse", FieldType.BOOLEAN).build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(true, false, false, true, false, true).build(), Row.withSchema(schema).addValues(false, true, true, false, false, true).build(), Row.withSchema(schema).addValues(false, true, false, true, true, false).build());
    pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Also used : BeamRelNode(org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode) 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 49 with Value

use of com.google.zetasql.Value in project beam by apache.

the class ZetaSqlDialectSpecTest method testCastStringToString.

@Test
public void testCastStringToString() {
    String sql = "SELECT CAST(@p0 AS STRING)";
    ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue(""));
    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 50 with Value

use of com.google.zetasql.Value in project beam by apache.

the class ZetaSqlDialectSpecTest method testIfBasic.

@Test
public void testIfBasic() {
    String sql = "SELECT IF(@p0, @p1, @p2) AS ColA";
    ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createBoolValue(true), "p1", Value.createInt64Value(1), "p2", Value.createInt64Value(2));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addNullableField("field1", FieldType.INT64).build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(1L).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)

Aggregations

Value (com.google.zetasql.Value)73 Test (org.junit.Test)69 Row (org.apache.beam.sdk.values.Row)66 ByteString (com.google.protobuf.ByteString)64 Schema (org.apache.beam.sdk.schemas.Schema)63 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)9 DateTimeUtils.parseDateToValue (org.apache.beam.sdk.extensions.sql.zetasql.DateTimeUtils.parseDateToValue)5 DateTimeUtils.parseTimeToValue (org.apache.beam.sdk.extensions.sql.zetasql.DateTimeUtils.parseTimeToValue)5 DateTimeUtils.parseTimestampWithTZToValue (org.apache.beam.sdk.extensions.sql.zetasql.DateTimeUtils.parseTimestampWithTZToValue)5 StructField (com.google.zetasql.StructType.StructField)3 AnalyzerOptions (com.google.zetasql.AnalyzerOptions)1 StructType (com.google.zetasql.StructType)1 StatusRuntimeException (com.google.zetasql.io.grpc.StatusRuntimeException)1 ResolvedNodes (com.google.zetasql.resolvedast.ResolvedNodes)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ZetaSqlException (org.apache.beam.sdk.extensions.sql.zetasql.ZetaSqlException)1 Ignore (org.junit.Ignore)1