use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testParameterStructNested.
@Test
public void testParameterStructNested() {
String sql = "SELECT @outer_struct.inner_struct.s as ColA";
StructType innerStructType = TypeFactory.createStructType(ImmutableList.of(new StructType.StructField("s", TypeFactory.createSimpleType(TypeKind.TYPE_STRING))));
ImmutableMap<String, Value> params = ImmutableMap.of("outer_struct", Value.createStructValue(TypeFactory.createStructType(ImmutableList.of(new StructType.StructField("inner_struct", innerStructType))), ImmutableList.of(Value.createStructValue(innerStructType, ImmutableList.of(Value.createStringValue("foo"))))));
PCollection<Row> stream = execute(sql, params);
final Schema schema = Schema.builder().addStringField("field1").build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValue("foo").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 testCharLengthNull.
@Test
public void testCharLengthNull() {
String sql = "SELECT CHAR_LENGTH(@p0);";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createSimpleNullValue(TypeKind.TYPE_STRING));
PCollection<Row> stream = execute(sql, params);
final Schema schema = Schema.builder().addNullableField("field", FieldType.INT64).build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues((Object) 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 testIsNullTrueFalse.
@Test
public void testIsNullTrueFalse() {
String sql = "WITH Src AS (\n" + " SELECT NULL as data UNION ALL\n" + " SELECT TRUE UNION ALL\n" + " SELECT FALSE\n" + ")\n" + "SELECT\n" + " data IS NULL as isnull,\n" + " data IS NOT NULL as isnotnull,\n" + " data IS TRUE as istrue,\n" + " data IS NOT TRUE as isnottrue,\n" + " data IS FALSE as isfalse,\n" + " data IS NOT FALSE as isnotfalse\n" + "FROM Src\n";
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().addField("isnull", FieldType.BOOLEAN).addField("isnotnull", FieldType.BOOLEAN).addField("istrue", FieldType.BOOLEAN).addField("isnottrue", FieldType.BOOLEAN).addField("isfalse", FieldType.BOOLEAN).addField("isnotfalse", FieldType.BOOLEAN).build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(true, false, false, true, false, true).build(), Row.withSchema(schema).addValues(false, true, true, false, false, true).build(), Row.withSchema(schema).addValues(false, true, false, true, true, 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 testCastStringToString.
@Test
public void testCastStringToString() {
String sql = "SELECT CAST(@p0 AS STRING)";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue(""));
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 testIfBasic.
@Test
public void testIfBasic() {
String sql = "SELECT IF(@p0, @p1, @p2) AS ColA";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createBoolValue(true), "p1", Value.createInt64Value(1), "p2", 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));
}
Aggregations