Search in sources :

Example 21 with Value

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

the class ZetaSqlDialectSpecTest method testCastStringToInt64.

@Test
public void testCastStringToInt64() {
    String sql = "SELECT CAST(@p0 AS INT64)";
    ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue("123"));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addInt64Field("field1").build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(123L).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 22 with Value

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

the class ZetaSqlDialectSpecTest method testLTrim2.

@Test
public void testLTrim2() {
    String sql = "SELECT ltrim(@p0, @p1)";
    ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue("abxyzab"), "p1", Value.createStringValue("ab"));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addStringField("field1").build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues("xyzab").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 23 with Value

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

the class ZetaSqlDialectSpecTest method testNamedParameterQuery.

@Test
public void testNamedParameterQuery() {
    String sql = "SELECT @ColA AS ColA";
    ImmutableMap<String, Value> params = ImmutableMap.of("ColA", Value.createInt64Value(5));
    PCollection<Row> stream = execute(sql, params);
    final Schema schema = Schema.builder().addInt64Field("field1").build();
    PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(5L).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 24 with Value

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

the class ZetaSqlDialectSpecTest method testSubstring.

@Test
public void testSubstring() {
    String sql = "SELECT substring(@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 25 with Value

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

the class ZetaSqlDialectSpecTest method testTrim2.

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