Search in sources :

Example 31 with SchemaPlus

use of org.apache.calcite.schema.SchemaPlus in project drill by apache.

the class DropTableHandler method getPlan.

/**
   * Function resolves the schema and invokes the drop method
   * (while IF EXISTS statement is used function invokes the drop method only if table exists).
   * Raises an exception if the schema is immutable.
   *
   * @param sqlNode - SqlDropTable (SQL parse tree of drop table [if exists] query)
   * @return - Single row indicating drop succeeded or table is not found while IF EXISTS statement is used,
   * raise exception otherwise
   */
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException {
    SqlDropTable dropTableNode = ((SqlDropTable) sqlNode);
    String originalTableName = dropTableNode.getName();
    SchemaPlus defaultSchema = config.getConverter().getDefaultSchema();
    List<String> tableSchema = dropTableNode.getSchema();
    DrillConfig drillConfig = context.getConfig();
    UserSession session = context.getSession();
    AbstractSchema temporarySchema = resolveToTemporarySchema(tableSchema, defaultSchema, drillConfig);
    boolean isTemporaryTable = session.isTemporaryTable(temporarySchema, drillConfig, originalTableName);
    if (isTemporaryTable) {
        session.removeTemporaryTable(temporarySchema, originalTableName, drillConfig);
    } else {
        AbstractSchema drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, tableSchema);
        Table tableToDrop = SqlHandlerUtil.getTableFromSchema(drillSchema, originalTableName);
        if (tableToDrop == null || tableToDrop.getJdbcTableType() != Schema.TableType.TABLE) {
            if (dropTableNode.checkTableExistence()) {
                return DirectPlan.createDirectPlan(context, false, String.format("Table [%s] not found", originalTableName));
            } else {
                throw UserException.validationError().message("Table [%s] not found", originalTableName).build(logger);
            }
        }
        SqlHandlerUtil.dropTableFromSchema(drillSchema, originalTableName);
    }
    String message = String.format("%s [%s] dropped", isTemporaryTable ? "Temporary table" : "Table", originalTableName);
    logger.info(message);
    return DirectPlan.createDirectPlan(context, true, message);
}
Also used : Table(org.apache.calcite.schema.Table) SqlDropTable(org.apache.drill.exec.planner.sql.parser.SqlDropTable) DrillConfig(org.apache.drill.common.config.DrillConfig) AbstractSchema(org.apache.drill.exec.store.AbstractSchema) UserSession(org.apache.drill.exec.rpc.user.UserSession) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SqlDropTable(org.apache.drill.exec.planner.sql.parser.SqlDropTable)

Example 32 with SchemaPlus

use of org.apache.calcite.schema.SchemaPlus in project drill by apache.

the class SchemaUtilites method getTemporaryWorkspace.

/**
   * Looks in schema tree for default temporary workspace instance.
   *
   * @param defaultSchema default schema
   * @param config drill config
   * @return default temporary workspace, null if workspace was not found
   */
public static AbstractSchema getTemporaryWorkspace(SchemaPlus defaultSchema, DrillConfig config) {
    String temporarySchema = config.getString(ExecConstants.DEFAULT_TEMPORARY_WORKSPACE);
    List<String> temporarySchemaPath = Lists.newArrayList(temporarySchema);
    SchemaPlus schema = findSchema(defaultSchema, temporarySchemaPath);
    return schema == null ? null : unwrapAsDrillSchemaInstance(schema);
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 33 with SchemaPlus

use of org.apache.calcite.schema.SchemaPlus in project lucene-solr by apache.

the class CalciteSolrDriver method connect.

@Override
public Connection connect(String url, Properties info) throws SQLException {
    if (!this.acceptsURL(url)) {
        return null;
    }
    Connection connection = super.connect(url, info);
    CalciteConnection calciteConnection = (CalciteConnection) connection;
    final SchemaPlus rootSchema = calciteConnection.getRootSchema();
    String schemaName = info.getProperty("zk");
    if (schemaName == null) {
        throw new SQLException("zk must be set");
    }
    rootSchema.add(schemaName, new SolrSchema(info));
    // Set the default schema
    calciteConnection.setSchema(schemaName);
    return connection;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) SchemaPlus(org.apache.calcite.schema.SchemaPlus) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection)

Aggregations

SchemaPlus (org.apache.calcite.schema.SchemaPlus)33 Table (org.apache.calcite.schema.Table)8 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)6 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)6 DruidOperatorTable (io.druid.sql.calcite.planner.DruidOperatorTable)5 PlannerConfig (io.druid.sql.calcite.planner.PlannerConfig)5 PlannerFactory (io.druid.sql.calcite.planner.PlannerFactory)5 StreamableTable (org.apache.calcite.schema.StreamableTable)5 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)4 SqlNode (org.apache.calcite.sql.SqlNode)4 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)4 QueryPlanner (org.apache.storm.sql.planner.trident.QueryPlanner)4 TridentRel (org.apache.storm.sql.planner.trident.rel.TridentRel)4 Before (org.junit.Before)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 CompilerUtil (org.apache.storm.sql.compiler.CompilerUtil)3 CalciteCatalogReader (org.apache.calcite.prepare.CalciteCatalogReader)2 UserSession (org.apache.drill.exec.rpc.user.UserSession)2 DrillFileSystem (org.apache.drill.exec.store.dfs.DrillFileSystem)2