use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlDialectSpecTest method testLikeAllowsEscapingBackslash.
@Test
public void testLikeAllowsEscapingBackslash() {
String sql = "SELECT @p0 LIKE @p1 AS ColA";
ImmutableMap<String, Value> params = ImmutableMap.of("p0", Value.createStringValue("a\\c"), "p1", Value.createStringValue("a\\\\c"));
PCollection<Row> stream = execute(sql, params);
final Schema schema = Schema.builder().addNullableField("field1", FieldType.BOOLEAN).build();
PAssert.that(stream).containsInAnyOrder(Row.withSchema(schema).addValues(true).build());
pipeline.run().waitUntilFinish(Duration.standardMinutes(PIPELINE_EXECUTION_WAITTIME_MINUTES));
}
use of com.google.zetasql.Value in project beam by apache.
the class ZetaSqlBeamTranslationUtils method toBeamRow.
public static Row toBeamRow(Value structValue, Schema schema, boolean verifyValues) {
List<Object> objects = new ArrayList<>(schema.getFieldCount());
List<Value> values = structValue.getFieldList();
for (int i = 0; i < values.size(); i++) {
objects.add(toBeamObject(values.get(i), schema.getField(i).getType(), verifyValues));
}
Row row = verifyValues ? Row.withSchema(schema).addValues(objects).build() : Row.withSchema(schema).attachValues(objects);
return row;
}
use of com.google.zetasql.Value in project beam by apache.
the class SqlAnalyzer method getAnalyzerOptions.
static AnalyzerOptions getAnalyzerOptions(QueryParameters queryParams, String defaultTimezone) {
AnalyzerOptions options = baseAnalyzerOptions();
options.setDefaultTimezone(defaultTimezone);
if (queryParams.getKind() == Kind.NAMED) {
options.setParameterMode(ParameterMode.PARAMETER_NAMED);
for (Map.Entry<String, Value> entry : ((Map<String, Value>) queryParams.named()).entrySet()) {
options.addQueryParameter(entry.getKey(), entry.getValue().getType());
}
} else if (queryParams.getKind() == Kind.POSITIONAL) {
options.setParameterMode(ParameterMode.PARAMETER_POSITIONAL);
for (Value param : (List<Value>) queryParams.positional()) {
options.addPositionalQueryParameter(param.getType());
}
}
return options;
}
Aggregations