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);
}
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);
}
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;
}
Aggregations