use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testReplace3.
@Test
public void testReplace3() {
String sql = "SELECT REPLACE(@p0, @p1, @p2) AS ColA";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue(""), "p1", Value.createStringValue(""), "p2", 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));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testTumbleAsTVF.
@Test
public void testTumbleAsTVF() {
String sql = "select Key, Value, ts, window_start, window_end from " + "TUMBLE((select * from KeyValue), descriptor(ts), 'INTERVAL 1 SECOND')";
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().addInt64Field("Key").addStringField("Value").addDateTimeField("ts").addDateTimeField("window_start").addDateTimeField("window_end").build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(14L, "KeyValue234", DateTimeUtils.parseTimestampWithUTCTimeZone("2018-07-01 21:26:06"), DateTimeUtils.parseTimestampWithUTCTimeZone("2018-07-01 21:26:06"), DateTimeUtils.parseTimestampWithUTCTimeZone("2018-07-01 21:26:07")).build(), Row.withSchema(schema).addValues(15L, "KeyValue235", DateTimeUtils.parseTimestampWithUTCTimeZone("2018-07-01 21:26:07"), DateTimeUtils.parseTimestampWithUTCTimeZone("2018-07-01 21:26:07"), DateTimeUtils.parseTimestampWithUTCTimeZone("2018-07-01T21:26:08")).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testReplace2.
@Test
public void testReplace2() {
String sql = "SELECT REPLACE(@p0, @p1, @p2) AS ColA";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue("abc"), "p1", Value.createStringValue(""), "p2", Value.createStringValue("xyz"));
PCollection<Row> stream = execute(sql, params);
final Schema schema = Schema.builder().addStringField("field1").build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues("abc").build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testIfPositional.
@Test
public void testIfPositional() {
String sql = "SELECT IF(?, ?, ?) AS ColA";
ImmutableList<Value> params = ImmutableList.of(Value.createBoolValue(true), Value.createInt64Value(1), 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));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testNullIfNegative.
@Test
public void testNullIfNegative() {
String sql = "SELECT NULLIF(@p0, @p1) AS ColA";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue("foo"), "p1", Value.createStringValue("null"));
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));
}
Aggregations