use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project drill by apache.
the class SchemaUtilites method resolveToMutableDrillSchema.
/**
* Given reference to default schema in schema tree, search for schema with given <i>schemaPath</i>. Once a schema is
* found resolve it into a mutable <i>AbstractDrillSchema</i> instance. A {@link UserException} is throws when:
* <li>No schema for given <i>schemaPath</i> is found.</li>
* <li>Schema found for given <i>schemaPath</i> is a root schema.</li>
* <li>Resolved schema is not a mutable schema.</li>
*
* @param defaultSchema default schema
* @param schemaPath current schema path
* @return mutable schema, exception otherwise
*/
public static AbstractSchema resolveToMutableDrillSchema(final SchemaPlus defaultSchema, List<String> schemaPath) {
final SchemaPlus schema = findSchema(defaultSchema, schemaPath);
if (schema == null) {
throwSchemaNotFoundException(defaultSchema, SCHEMA_PATH_JOINER.join(schemaPath));
}
if (isRootSchema(schema)) {
throw UserException.validationError().message("Root schema is immutable. Creating or dropping tables/views is not allowed in root schema." + "Select a schema using 'USE schema' command.").build(logger);
}
final AbstractSchema drillSchema = unwrapAsDrillSchemaInstance(schema);
if (!drillSchema.isMutable()) {
throw UserException.validationError().message("Unable to create or drop tables/views. Schema [%s] is immutable.", getSchemaPath(schema)).build(logger);
}
return drillSchema;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project herddb by diennea.
the class CalcitePlanner method getSchemaForTableSpace.
private SchemaPlus getSchemaForTableSpace(String defaultTableSpace) {
long startTs = System.currentTimeMillis();
while (true) {
SchemaPlus schema = getRootSchema();
SchemaPlus result = schema.getSubSchema(defaultTableSpace);
if (result != null) {
return result;
}
long delta = System.currentTimeMillis() - startTs;
LOG.log(Level.FINE, "schema {0} not available yet, after waiting {1}/{2} ms", new Object[] { defaultTableSpace, delta, waitForSchemaTimeout });
if (delta >= waitForSchemaTimeout) {
return null;
}
clearCache();
try {
Thread.sleep(100);
} catch (InterruptedException err) {
Thread.currentThread().interrupt();
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project herddb by diennea.
the class CalcitePlanner method getRootSchema.
private SchemaPlus getRootSchema() {
if (rootSchema != null) {
return rootSchema;
}
final SchemaPlus _rootSchema = Frameworks.createRootSchema(true);
for (String tableSpace : manager.getLocalTableSpaces()) {
TableSpaceManager tableSpaceManager = manager.getTableSpaceManager(tableSpace);
SchemaPlus schema = _rootSchema.add(tableSpace, new AbstractSchema());
List<Table> tables = tableSpaceManager.getAllTablesForPlanner();
for (Table table : tables) {
AbstractTableManager tableManager = tableSpaceManager.getTableManager(table.name);
TableImpl tableDef = new TableImpl(tableManager);
schema.add(table.name, tableDef);
}
}
rootSchema = _rootSchema;
return _rootSchema;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class ModelHandler method visit.
public void visit(JsonMapSchema jsonSchema) {
checkRequiredAttributes(jsonSchema, "name");
final SchemaPlus parentSchema = currentMutableSchema("schema");
final SchemaPlus schema = parentSchema.add(jsonSchema.name, new AbstractSchema());
if (jsonSchema.path != null) {
schema.setPath(stringListList(jsonSchema.path));
}
populateSchema(jsonSchema, schema);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class ModelHandler method visit.
public void visit(JsonCustomTable jsonTable) {
try {
checkRequiredAttributes(jsonTable, "name", "factory");
final SchemaPlus schema = currentMutableSchema("table");
final TableFactory tableFactory = AvaticaUtils.instantiatePlugin(TableFactory.class, jsonTable.factory);
final Table table = tableFactory.create(schema, jsonTable.name, operandMap(null, jsonTable.operand), null);
for (JsonColumn column : jsonTable.columns) {
column.accept(this);
}
schema.add(jsonTable.name, table);
} catch (Exception e) {
throw new RuntimeException("Error instantiating " + jsonTable, e);
}
}
Aggregations