Search in sources :

Example 1 with TYPE_STRING

use of com.google.zetasql.ZetaSQLType.TypeKind.TYPE_STRING in project beam by apache.

the class ExpressionConverter method convertIntervalToRexIntervalLiteral.

private RexNode convertIntervalToRexIntervalLiteral(ResolvedLiteral resolvedLiteral) {
    if (resolvedLiteral.getType().getKind() != TYPE_STRING) {
        throw new ZetaSqlException(INTERVAL_FORMAT_MSG);
    }
    String valStr = resolvedLiteral.getValue().getStringValue();
    List<String> stringList = Arrays.stream(valStr.split(" ")).filter(s -> !s.isEmpty()).collect(Collectors.toList());
    if (stringList.size() != 3) {
        throw new ZetaSqlException(INTERVAL_FORMAT_MSG);
    }
    if (!Ascii.toUpperCase(stringList.get(0)).equals("INTERVAL")) {
        throw new ZetaSqlException(INTERVAL_FORMAT_MSG);
    }
    long intervalValue;
    try {
        intervalValue = Long.parseLong(stringList.get(1));
    } catch (NumberFormatException e) {
        throw new ZetaSqlException(Status.UNIMPLEMENTED.withDescription(INTERVAL_FORMAT_MSG).withCause(e).asRuntimeException());
    }
    String intervalDatepart = Ascii.toUpperCase(stringList.get(2));
    return createCalciteIntervalRexLiteral(intervalValue, intervalDatepart);
}
Also used : RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) Arrays(java.util.Arrays) FixedOutputSchemaTVF(com.google.zetasql.TableValuedFunction.FixedOutputSchemaTVF) Type(com.google.zetasql.Type) TYPE_TIMESTAMP(com.google.zetasql.ZetaSQLType.TypeKind.TYPE_TIMESTAMP) SqlParserPos(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserPos) Status(com.google.zetasql.io.grpc.Status) Value(com.google.zetasql.Value) SqlIntervalQualifier(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIntervalQualifier) USER_DEFINED_SQL_FUNCTIONS(org.apache.beam.sdk.extensions.sql.zetasql.BeamZetaSqlCatalog.USER_DEFINED_SQL_FUNCTIONS) BigDecimal(java.math.BigDecimal) TVFStreamingUtils(org.apache.beam.sdk.extensions.sql.impl.utils.TVFStreamingUtils) ResolvedColumn(com.google.zetasql.resolvedast.ResolvedColumn) Map(java.util.Map) RexLiteral(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLiteral) RelDataTypeFieldImpl(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFieldImpl) Internal(org.apache.beam.sdk.annotations.Internal) ResolvedFunctionCall(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedFunctionCall) ZetaSqlUserDefinedSQLNativeTableValuedFunction(org.apache.beam.sdk.extensions.sql.impl.ZetaSqlUserDefinedSQLNativeTableValuedFunction) RexBuilder(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexBuilder) ImmutableSet(com.google.common.collect.ImmutableSet) ResolvedGetStructField(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedGetStructField) ImmutableMap(com.google.common.collect.ImmutableMap) ResolvedLiteral(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedLiteral) ResolvedOrderByScan(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedOrderByScan) ResolvedProjectScan(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedProjectScan) ZetaSqlException(org.apache.beam.sdk.extensions.sql.zetasql.ZetaSqlException) Collectors(java.util.stream.Collectors) ResolvedParameter(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedParameter) List(java.util.List) ResolvedExpr(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedExpr) TypeKind(com.google.zetasql.ZetaSQLType.TypeKind) TVFRelation(com.google.zetasql.TVFRelation) TYPE_BOOL(com.google.zetasql.ZetaSQLType.TypeKind.TYPE_BOOL) TYPE_DOUBLE(com.google.zetasql.ZetaSQLType.TypeKind.TYPE_DOUBLE) IntStream(java.util.stream.IntStream) ResolvedColumnRef(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedColumnRef) ZetaSqlCalciteTranslationUtils(org.apache.beam.sdk.extensions.sql.zetasql.ZetaSqlCalciteTranslationUtils) TableValuedFunction(com.google.zetasql.TableValuedFunction) ResolvedArgumentRef(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedArgumentRef) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode) SqlIdentifier(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier) ZETASQL_FUNCTION_GROUP_NAME(org.apache.beam.sdk.extensions.sql.zetasql.BeamZetaSqlCatalog.ZETASQL_FUNCTION_GROUP_NAME) SqlKind(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlKind) ResolvedAggregateScan(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedAggregateScan) TYPE_BYTES(com.google.zetasql.ZetaSQLType.TypeKind.TYPE_BYTES) ArrayList(java.util.ArrayList) TYPE_STRING(com.google.zetasql.ZetaSQLType.TypeKind.TYPE_STRING) SqlRowOperator(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.fun.SqlRowOperator) ImmutableList(com.google.common.collect.ImmutableList) PRE_DEFINED_WINDOW_FUNCTIONS(org.apache.beam.sdk.extensions.sql.zetasql.BeamZetaSqlCatalog.PRE_DEFINED_WINDOW_FUNCTIONS) Preconditions.checkArgument(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument) ResolvedNodes(com.google.zetasql.resolvedast.ResolvedNodes) RelDataTypeField(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField) RESOLVED_FUNCTION_CALL(com.google.zetasql.ZetaSQLResolvedNodeKind.ResolvedNodeKind.RESOLVED_FUNCTION_CALL) TYPE_NUMERIC(com.google.zetasql.ZetaSQLType.TypeKind.TYPE_NUMERIC) Nullable(org.checkerframework.checker.nullness.qual.Nullable) ResolvedCast(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedCast) QueryParameters(org.apache.beam.sdk.extensions.sql.impl.QueryPlanner.QueryParameters) USER_DEFINED_JAVA_SCALAR_FUNCTIONS(org.apache.beam.sdk.extensions.sql.zetasql.BeamZetaSqlCatalog.USER_DEFINED_JAVA_SCALAR_FUNCTIONS) Ascii(com.google.common.base.Ascii) TYPE_INT64(com.google.zetasql.ZetaSQLType.TypeKind.TYPE_INT64) TimeUnit(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.avatica.util.TimeUnit) RexCall(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexCall) SqlOperator(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator) RelOptCluster(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptCluster) RelDataType(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType) RexInputRef(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef) ResolvedComputedColumn(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedComputedColumn) Preconditions(com.google.common.base.Preconditions) ResolvedCreateFunctionStmt(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedCreateFunctionStmt) RelRecordType(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelRecordType) ZetaSqlException(org.apache.beam.sdk.extensions.sql.zetasql.ZetaSqlException)

Aggregations

Ascii (com.google.common.base.Ascii)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 TVFRelation (com.google.zetasql.TVFRelation)1 TableValuedFunction (com.google.zetasql.TableValuedFunction)1 FixedOutputSchemaTVF (com.google.zetasql.TableValuedFunction.FixedOutputSchemaTVF)1 Type (com.google.zetasql.Type)1 Value (com.google.zetasql.Value)1 RESOLVED_FUNCTION_CALL (com.google.zetasql.ZetaSQLResolvedNodeKind.ResolvedNodeKind.RESOLVED_FUNCTION_CALL)1 TypeKind (com.google.zetasql.ZetaSQLType.TypeKind)1 TYPE_BOOL (com.google.zetasql.ZetaSQLType.TypeKind.TYPE_BOOL)1 TYPE_BYTES (com.google.zetasql.ZetaSQLType.TypeKind.TYPE_BYTES)1 TYPE_DOUBLE (com.google.zetasql.ZetaSQLType.TypeKind.TYPE_DOUBLE)1 TYPE_INT64 (com.google.zetasql.ZetaSQLType.TypeKind.TYPE_INT64)1 TYPE_NUMERIC (com.google.zetasql.ZetaSQLType.TypeKind.TYPE_NUMERIC)1 TYPE_STRING (com.google.zetasql.ZetaSQLType.TypeKind.TYPE_STRING)1 TYPE_TIMESTAMP (com.google.zetasql.ZetaSQLType.TypeKind.TYPE_TIMESTAMP)1 Status (com.google.zetasql.io.grpc.Status)1