Search in sources :

Example 41 with Value

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

the class ZetaSqlDialectSpecTest method testLikeAllowsEscapingNonSpecialCharacter.

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

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

the class ZetaSqlDialectSpecTest method testConcatWithNull1.

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

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

the class ZetaSqlDialectSpecTest method testSubstr.

@Test
public void testSubstr() {
    String sql = "SELECT substr(@p0, @p1, @p2)";
    ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue("abc"), "p1", Value.createInt64Value(-2L), "p2", Value.createInt64Value(1L));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addStringField("field1").build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues("b").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 44 with Value

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

the class ZetaSqlDialectSpecTest method testTrim3.

@Test
public void testTrim3() {
    String sql = "SELECT trim(@p0, @p1)";
    ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createSimpleNullValue(TypeKind.TYPE_STRING), "p1", Value.createSimpleNullValue(TypeKind.TYPE_STRING));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addNullableField("field1", FieldType.STRING).build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues((String) 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 45 with Value

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

the class ZetaSqlDialectSpecTest method testRTrim1.

@Test
public void testRTrim1() {
    String sql = "SELECT rtrim(@p0)";
    ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue("   a b c   "));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addStringField("field1").build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues("   a b c").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