use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testStringAggregationParamsDelimiter.
@Test
public void testStringAggregationParamsDelimiter() {
String sql = "SELECT string_agg(\"s\", @separator) FROM (SELECT 1)";
ImmutableMap<String, Value> params = ImmutableMap.<String, Value>builder().put("separator", Value.createStringValue(",")).build();
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
// BEAM-13673
thrown.expect(ZetaSqlException.class);
zetaSQLQueryPlanner.convertToBeamRel(sql, params);
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testTrim1.
@Test
public void testTrim1() {
String sql = "SELECT trim(@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));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testEQ6.
@Test
public void testEQ6() {
String sql = "SELECT ? = ? AS ColA";
ImmutableList<Value> params = ImmutableList.of(Value.createInt64Value(4L), Value.createInt64Value(5L));
PCollection<Row> stream = execute(sql, params);
final Schema schema = Schema.builder().addNullableField("field1", FieldType.BOOLEAN).build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(false).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 testUNNESTParameters.
@Test
public void testUNNESTParameters() {
String sql = "SELECT * FROM UNNEST(@p0);";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createArrayValue(TypeFactory.createArrayType(TypeFactory.createSimpleType(TypeKind.TYPE_STRING)), ImmutableList.of(Value.createStringValue("foo"), Value.createStringValue("bar"))));
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql, params);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
Schema schema = Schema.builder().addStringField("str_field").build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues("foo").build(), Row.withSchema(schema).addValues("bar").build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlTimeFunctionsTest method testTimestampAddWithParameter2.
@Test
public void testTimestampAddWithParameter2() {
String sql = "SELECT TIMESTAMP_ADD(@p0, INTERVAL @p1 MINUTE)";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", parseTimestampWithTZToValue("2008-12-25 15:30:00+07:30"), "p1", Value.createInt64Value(10L));
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
BeamRelNode beamRelNode = zetaSQLQueryPlanner.convertToBeamRel(sql, params);
PCollection<Row> stream = BeamSqlRelUtils.toPCollection(pipeline, beamRelNode);
final Schema schema = Schema.builder().addDateTimeField("field1").build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(parseTimestampWithTimeZone("2008-12-25 15:40:00+07:30")).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
Aggregations