use of org.apache.calcite.schema.Schema in project calcite by apache.
the class SqlCreateForeignSchema method execute.
public void execute(CalcitePrepare.Context context) {
final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, name);
final SchemaPlus subSchema0 = pair.left.plus().getSubSchema(pair.right);
if (subSchema0 != null) {
if (!getReplace() && !ifNotExists) {
throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.schemaExists(pair.right));
}
}
final Schema subSchema;
final String libraryName;
if (type != null) {
Preconditions.checkArgument(library == null);
final String typeName = (String) value(this.type);
final JsonSchema.Type type = Util.enumVal(JsonSchema.Type.class, typeName.toUpperCase(Locale.ROOT));
if (type != null) {
switch(type) {
case JDBC:
libraryName = JdbcSchema.Factory.class.getName();
break;
default:
libraryName = null;
}
} else {
libraryName = null;
}
if (libraryName == null) {
throw SqlUtil.newContextException(this.type.getParserPosition(), RESOURCE.schemaInvalidType(typeName, Arrays.toString(JsonSchema.Type.values())));
}
} else {
Preconditions.checkArgument(library != null);
libraryName = (String) value(library);
}
final SchemaFactory schemaFactory = AvaticaUtils.instantiatePlugin(SchemaFactory.class, libraryName);
final Map<String, Object> operandMap = new LinkedHashMap<>();
for (Pair<SqlIdentifier, SqlNode> option : options(optionList)) {
operandMap.put(option.left.getSimple(), value(option.right));
}
subSchema = schemaFactory.create(pair.left.plus(), pair.right, operandMap);
pair.left.add(pair.right, subSchema);
}
use of org.apache.calcite.schema.Schema in project calcite by apache.
the class ModelHandler method visit.
public void visit(JsonCustomSchema jsonSchema) {
try {
final SchemaPlus parentSchema = currentMutableSchema("sub-schema");
checkRequiredAttributes(jsonSchema, "name", "factory");
final SchemaFactory schemaFactory = AvaticaUtils.instantiatePlugin(SchemaFactory.class, jsonSchema.factory);
final Schema schema = schemaFactory.create(parentSchema, jsonSchema.name, operandMap(jsonSchema, jsonSchema.operand));
final SchemaPlus schemaPlus = parentSchema.add(jsonSchema.name, schema);
populateSchema(jsonSchema, schemaPlus);
} catch (Exception e) {
throw new RuntimeException("Error instantiating " + jsonSchema, e);
}
}
use of org.apache.calcite.schema.Schema in project calcite by apache.
the class CsvTest method testPrepared.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1031">[CALCITE-1031]
* In prepared statement, CsvScannableTable.scan is called twice</a>. To see
* the bug, place a breakpoint in CsvScannableTable.scan, and note that it is
* called twice. It should only be called once.
*/
@Test
public void testPrepared() throws SQLException {
final Properties properties = new Properties();
properties.setProperty("caseSensitive", "true");
try (final Connection connection = DriverManager.getConnection("jdbc:calcite:", properties)) {
final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
final Schema schema = CsvSchemaFactory.INSTANCE.create(calciteConnection.getRootSchema(), null, ImmutableMap.<String, Object>of("directory", resourcePath("sales"), "flavor", "scannable"));
calciteConnection.getRootSchema().add("TEST", schema);
final String sql = "select * from \"TEST\".\"DEPTS\" where \"NAME\" = ?";
final PreparedStatement statement2 = calciteConnection.prepareStatement(sql);
statement2.setString(1, "Sales");
final ResultSet resultSet1 = statement2.executeQuery();
Function<ResultSet, Void> expect = expect("DEPTNO=10; NAME=Sales");
expect.apply(resultSet1);
}
}
use of org.apache.calcite.schema.Schema in project drill by apache.
the class CassandraRootDrillSchemaFactory method registerSchemas.
@Override
public void registerSchemas(SchemaConfig schemaConfig, SchemaPlus parent) {
Schema schema = new CassandraRootDrillSchema(getName(), plugin, calciteSchemaFactory, parent, getName(), plugin.getConfig().toConfigMap());
parent.add(getName(), schema);
}
use of org.apache.calcite.schema.Schema in project drill by apache.
the class CassandraRootDrillSchema method createSubSchema.
private Schema createSubSchema(String schemaName) {
Map<String, Object> configs = new HashMap<>(configMap);
configs.put("keyspace", schemaName);
SchemaPlus parentSchema = parent.getSubSchema(parentName);
Schema schema = new CassandraDrillSchema(schemaName, plugin, (CassandraSchema) schemaFactory.create(parentSchema, schemaName, configs));
parentSchema.add(schemaName, schema);
return schema;
}
Aggregations