Search in sources :

Example 61 with SqlIdentifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project flink by apache.

the class SqlValidatorImpl method getNamespace.

private SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope) {
    if (node instanceof SqlIdentifier && scope instanceof DelegatingScope) {
        final SqlIdentifier id = (SqlIdentifier) node;
        final DelegatingScope idScope = (DelegatingScope) ((DelegatingScope) scope).getParent();
        return getNamespace(id, idScope);
    } else if (node instanceof SqlCall) {
        // Handle extended identifiers.
        final SqlCall call = (SqlCall) node;
        switch(call.getOperator().getKind()) {
            case TABLE_REF:
                return getNamespace(call.operand(0), scope);
            case EXTEND:
                final SqlNode operand0 = call.getOperandList().get(0);
                final SqlIdentifier identifier = operand0.getKind() == SqlKind.TABLE_REF ? ((SqlCall) operand0).operand(0) : (SqlIdentifier) operand0;
                final DelegatingScope idScope = (DelegatingScope) scope;
                return getNamespace(identifier, idScope);
            case AS:
                final SqlNode nested = call.getOperandList().get(0);
                switch(nested.getKind()) {
                    case TABLE_REF:
                    case EXTEND:
                        return getNamespace(nested, scope);
                }
                break;
        }
    }
    return getNamespace(node);
}
Also used : SqlCall(org.apache.calcite.sql.SqlCall) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Example 62 with SqlIdentifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project flink by apache.

the class ParserImpl method parseIdentifier.

@Override
public UnresolvedIdentifier parseIdentifier(String identifier) {
    CalciteParser parser = calciteParserSupplier.get();
    SqlIdentifier sqlIdentifier = parser.parseIdentifier(identifier);
    return UnresolvedIdentifier.of(sqlIdentifier.names);
}
Also used : SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) CalciteParser(org.apache.flink.table.planner.parse.CalciteParser)

Example 63 with SqlIdentifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project beam by apache.

the class SqlOperators method createUdfOperator.

private static SqlUserDefinedFunction createUdfOperator(String name, Method method, final SqlSyntax syntax, String funGroup, String jarPath) {
    Function function = ZetaSqlScalarFunctionImpl.create(method, funGroup, jarPath);
    final RelDataTypeFactory typeFactory = createTypeFactory();
    List<RelDataType> argTypes = new ArrayList<>();
    List<SqlTypeFamily> typeFamilies = new ArrayList<>();
    for (FunctionParameter o : function.getParameters()) {
        final RelDataType type = o.getType(typeFactory);
        argTypes.add(type);
        typeFamilies.add(Util.first(type.getSqlTypeName().getFamily(), SqlTypeFamily.ANY));
    }
    final FamilyOperandTypeChecker typeChecker = OperandTypes.family(typeFamilies, i -> function.getParameters().get(i).isOptional());
    final List<RelDataType> paramTypes = toSql(typeFactory, argTypes);
    return new SqlUserDefinedFunction(new SqlIdentifier(name, SqlParserPos.ZERO), infer((ScalarFunction) function), InferTypes.explicit(argTypes), typeChecker, paramTypes, function) {

        @Override
        public SqlSyntax getSyntax() {
            return syntax;
        }
    };
}
Also used : FamilyOperandTypeChecker(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.FamilyOperandTypeChecker) SqlUserDefinedFunction(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlUserDefinedFunction) Function(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Function) SqlFunction(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlFunction) AggregateFunction(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.AggregateFunction) ScalarFunction(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.ScalarFunction) SqlUserDefinedAggFunction(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlUserDefinedAggFunction) SqlUserDefinedFunction(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.validate.SqlUserDefinedFunction) ScalarFunction(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.ScalarFunction) SqlTypeFamily(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.type.SqlTypeFamily) RelDataTypeFactory(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFactory) ArrayList(java.util.ArrayList) RelDataType(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType) SqlIdentifier(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier) FunctionParameter(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.FunctionParameter)

Example 64 with SqlIdentifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project beam by apache.

the class SqlSetOptionBeam method execute.

@Override
public void execute(CalcitePrepare.Context context) {
    final SqlIdentifier name = getName();
    final SqlNode value = getValue();
    final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, name);
    if (!(pair.left.schema instanceof BeamCalciteSchema)) {
        throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.internal("Schema is not instanceof BeamCalciteSchema"));
    }
    BeamCalciteSchema schema = (BeamCalciteSchema) pair.left.schema;
    if (value != null) {
        schema.setPipelineOption(pair.right, SqlDdlNodes.getString(value));
    } else if ("ALL".equals(pair.right)) {
        schema.removeAllPipelineOptions();
    } else {
        schema.removePipelineOption(pair.right);
    }
}
Also used : CalciteSchema(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema) BeamCalciteSchema(org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema) SqlIdentifier(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier) BeamCalciteSchema(org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema) SqlNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode)

Example 65 with SqlIdentifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project beam by apache.

the class SqlDdlNodes method schema.

/**
 * Returns the schema in which to create an object.
 */
static Pair<CalciteSchema, String> schema(CalcitePrepare.Context context, boolean mutable, SqlIdentifier id) {
    final List<String> path;
    if (id.isSimple()) {
        path = context.getDefaultSchemaPath();
    } else {
        path = Util.skipLast(id.names);
    }
    CalciteSchema schema = mutable ? context.getMutableRootSchema() : context.getRootSchema();
    for (String p : path) {
        schema = schema.getSubSchema(p, true);
        if (schema == null) {
            throw new AssertionError(String.format("Got null sub-schema for path '%s' in %s", p, path));
        }
    }
    return Pair.of(schema, name(id));
}
Also used : CalciteSchema(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema) NlsString(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.NlsString)

Aggregations

SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)131 SqlNode (org.apache.calcite.sql.SqlNode)84 RelDataType (org.apache.calcite.rel.type.RelDataType)46 SqlNodeList (org.apache.calcite.sql.SqlNodeList)43 ArrayList (java.util.ArrayList)41 SqlCall (org.apache.calcite.sql.SqlCall)32 BitString (org.apache.calcite.util.BitString)28 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)21 SqlSelect (org.apache.calcite.sql.SqlSelect)21 SqlParserPos (org.apache.calcite.sql.parser.SqlParserPos)12 SchemaPlus (org.apache.calcite.schema.SchemaPlus)11 SqlOperator (org.apache.calcite.sql.SqlOperator)11 NlsString (org.apache.calcite.util.NlsString)11 List (java.util.List)9 Map (java.util.Map)9 RelOptTable (org.apache.calcite.plan.RelOptTable)9 RexNode (org.apache.calcite.rex.RexNode)9 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)9 ImmutableList (com.google.common.collect.ImmutableList)8 RelNode (org.apache.calcite.rel.RelNode)7