Search in sources :

Example 71 with Value

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));
}
Also used : Schema(org.apache.beam.sdk.schemas.Schema) Value(com.google.zetasql.Value) ByteString(com.google.protobuf.ByteString) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Example 72 with Value

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;
}
Also used : ArrayList(java.util.ArrayList) Value(com.google.zetasql.Value) Row(org.apache.beam.sdk.values.Row)

Example 73 with Value

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;
}
Also used : Value(com.google.zetasql.Value) Map(java.util.Map) AnalyzerOptions(com.google.zetasql.AnalyzerOptions)

Aggregations

Value (com.google.zetasql.Value)73 Test (org.junit.Test)69 Row (org.apache.beam.sdk.values.Row)66 ByteString (com.google.protobuf.ByteString)64 Schema (org.apache.beam.sdk.schemas.Schema)63 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)9 DateTimeUtils.parseDateToValue (org.apache.beam.sdk.extensions.sql.zetasql.DateTimeUtils.parseDateToValue)5 DateTimeUtils.parseTimeToValue (org.apache.beam.sdk.extensions.sql.zetasql.DateTimeUtils.parseTimeToValue)5 DateTimeUtils.parseTimestampWithTZToValue (org.apache.beam.sdk.extensions.sql.zetasql.DateTimeUtils.parseTimestampWithTZToValue)5 StructField (com.google.zetasql.StructType.StructField)3 AnalyzerOptions (com.google.zetasql.AnalyzerOptions)1 StructType (com.google.zetasql.StructType)1 StatusRuntimeException (com.google.zetasql.io.grpc.StatusRuntimeException)1 ResolvedNodes (com.google.zetasql.resolvedast.ResolvedNodes)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ZetaSqlException (org.apache.beam.sdk.extensions.sql.zetasql.ZetaSqlException)1 Ignore (org.junit.Ignore)1