use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testReplace1.
@Test
public void testReplace1() {
String sql = "SELECT REPLACE(@p0, @p1, @p2) AS ColA";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue(""), "p1", Value.createStringValue(""), "p2", Value.createStringValue("a"));
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));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testCastBytesToString1.
@Test
@Ignore("https://jira.apache.org/jira/browse/BEAM-9191")
public void testCastBytesToString1() {
String sql = "SELECT CAST(@p0 AS STRING)";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createBytesValue(ByteString.copyFromUtf8("`")));
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));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testZetaSQLSelectNullLimitParam.
@Test
public void testZetaSQLSelectNullLimitParam() {
String sql = "SELECT Key, Value FROM KeyValue LIMIT @lmt;";
ImmutableMap<String, Value> params = ImmutableMap.of("lmt", Value.createNullValue(TypeFactory.createSimpleType(TypeKind.TYPE_INT64)));
ZetaSQLQueryPlanner zetaSQLQueryPlanner = new ZetaSQLQueryPlanner(config);
thrown.expect(RuntimeException.class);
thrown.expectMessage("Limit requires non-null count and offset");
zetaSQLQueryPlanner.convertToBeamRel(sql, params);
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testParameterStruct.
@Test
public void testParameterStruct() {
String sql = "SELECT @p as ColA";
ImmutableMap<String, Value> params = ImmutableMap.of("p", Value.createStructValue(TypeFactory.createStructType(ImmutableList.of(new StructType.StructField("s", TypeFactory.createSimpleType(TypeKind.TYPE_STRING)), new StructType.StructField("i", TypeFactory.createSimpleType(TypeKind.TYPE_INT64)))), ImmutableList.of(Value.createStringValue("foo"), Value.createInt64Value(1L))));
PCollection<Row> stream = execute(sql, params);
final Schema innerSchema = Schema.of(Field.of("s", FieldType.STRING), Field.of("i", FieldType.INT64));
final Schema schema = Schema.of(Field.of("field1", FieldType.row(innerSchema)));
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValue(Row.withSchema(innerSchema).addValues("foo", 1L).build()).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 testIsNotNull1.
@Test
public void testIsNotNull1() {
String sql = "SELECT @p0 IS NOT NULL AS ColA";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createSimpleNullValue(TypeKind.TYPE_STRING));
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));
}
Aggregations