Search in sources :

Example 21 with CalciteSchema

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project beam by apache.

the class SqlDropObject method execute.

@Override
public void execute(CalcitePrepare.Context context) {
    final List<String> path = context.getDefaultSchemaPath();
    CalciteSchema schema = 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));
        }
    }
    final boolean existed;
    switch(getKind()) {
        case DROP_TABLE:
            if (schema.schema instanceof BeamCalciteSchema) {
                BeamCalciteSchema beamSchema = (BeamCalciteSchema) schema.schema;
                beamSchema.getTableProvider().dropTable(name.getSimple());
                existed = true;
            } else {
                existed = schema.removeTable(name.getSimple());
            }
            if (!existed && !ifExists) {
                throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.tableNotFound(name.getSimple()));
            }
            break;
        default:
            throw new AssertionError(getKind());
    }
}
Also used : BeamCalciteSchema(org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema) CalciteSchema(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema) BeamCalciteSchema(org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema)

Example 22 with CalciteSchema

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema 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 23 with CalciteSchema

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project beam by apache.

the class SqlCreateExternalTable method execute.

@Override
public void execute(CalcitePrepare.Context context) {
    final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, name);
    if (pair.left.plus().getTable(pair.right) != null) {
        // Table exists.
        if (!ifNotExists) {
            // They did not specify IF NOT EXISTS, so give error.
            throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.tableExists(pair.right));
        }
        return;
    }
    // Table does not exist. Create it.
    if (!(pair.left.schema instanceof BeamCalciteSchema)) {
        throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.internal("Schema is not instanceof BeamCalciteSchema"));
    }
    BeamCalciteSchema schema = (BeamCalciteSchema) pair.left.schema;
    schema.getTableProvider().createTable(toTable());
}
Also used : BeamCalciteSchema(org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema) CalciteSchema(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema) BeamCalciteSchema(org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema)

Example 24 with CalciteSchema

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema 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)

Example 25 with CalciteSchema

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema in project drill by axbaretto.

the class DynamicSchema method getSubSchema.

@Override
public CalciteSchema getSubSchema(String schemaName, boolean caseSensitive) {
    Schema s = schema.getSubSchema(schemaName);
    if (s != null) {
        return new DynamicSchema(this, s, schemaName);
    }
    CalciteSchema ret = getSubSchemaMap().get(schemaName);
    return ret;
}
Also used : CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) SimpleCalciteSchema(org.apache.calcite.jdbc.SimpleCalciteSchema) Schema(org.apache.calcite.schema.Schema) CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) SimpleCalciteSchema(org.apache.calcite.jdbc.SimpleCalciteSchema)

Aggregations

CalciteSchema (org.apache.calcite.jdbc.CalciteSchema)31 SchemaPlus (org.apache.calcite.schema.SchemaPlus)8 CalciteSchema (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema)6 ArrayList (java.util.ArrayList)5 RelDataType (org.apache.calcite.rel.type.RelDataType)5 Test (org.junit.Test)5 Method (java.lang.reflect.Method)4 SchemaPlus (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus)4 Schema (org.apache.calcite.schema.Schema)4 Table (org.apache.calcite.schema.Table)4 SqlNode (org.apache.calcite.sql.SqlNode)4 ImmutableList (com.google.common.collect.ImmutableList)3 BeamCalciteSchema (org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema)3 JdbcConnection (org.apache.beam.sdk.extensions.sql.impl.JdbcConnection)3 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)3 TableFunction (org.apache.calcite.schema.TableFunction)3 TranslatableTable (org.apache.calcite.schema.TranslatableTable)3 AbstractSchema (org.apache.calcite.schema.impl.AbstractSchema)3 ViewTableMacro (org.apache.calcite.schema.impl.ViewTableMacro)3 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)3