use of org.apache.calcite.schema.Schema in project drill by axbaretto.
the class DynamicSchema method getImplicitSubSchema.
@Override
protected CalciteSchema getImplicitSubSchema(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;
}
use of org.apache.calcite.schema.Schema 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;
}
use of org.apache.calcite.schema.Schema in project calcite by apache.
the class CalciteSchema method createRootSchema.
/**
* Creates a root schema.
*
* @param addMetadataSchema Whether to add a "metadata" schema containing
* definitions of tables, columns etc.
* @param cache If true create {@link CachingCalciteSchema};
* if false create {@link SimpleCalciteSchema}
* @param name Schema name
*/
public static CalciteSchema createRootSchema(boolean addMetadataSchema, boolean cache, String name) {
CalciteSchema rootSchema;
final Schema schema = new CalciteConnectionImpl.RootSchema();
if (cache) {
rootSchema = new CachingCalciteSchema(null, schema, name);
} else {
rootSchema = new SimpleCalciteSchema(null, schema, name);
}
if (addMetadataSchema) {
rootSchema.add("metadata", MetadataSchema.INSTANCE);
}
return rootSchema;
}
use of org.apache.calcite.schema.Schema in project calcite by apache.
the class JdbcTest method testExplicitImplicitSchemaSameName.
@Test
public void testExplicitImplicitSchemaSameName() throws Exception {
final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false).plus();
// create schema "/a"
final Map<String, Schema> aSubSchemaMap = new HashMap<>();
final SchemaPlus aSchema = rootSchema.add("a", new AbstractSchema() {
@Override
protected Map<String, Schema> getSubSchemaMap() {
return aSubSchemaMap;
}
});
// add explicit schema "/a/b".
aSchema.add("b", new AbstractSchema());
// add implicit schema "/a/b"
aSubSchemaMap.put("b", new AbstractSchema());
aSchema.setCacheEnabled(true);
// explicit should win implicit.
assertThat(aSchema.getSubSchemaNames().size(), is(1));
}
use of org.apache.calcite.schema.Schema in project calcite by apache.
the class ScannableTableTest method testPrepared2.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1031">[CALCITE-1031]
* In prepared statement, CsvScannableTable.scan is called twice</a>.
*/
@Test
public void testPrepared2() 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 AtomicInteger scanCount = new AtomicInteger();
final AtomicInteger enumerateCount = new AtomicInteger();
final Schema schema = new AbstractSchema() {
@Override
protected Map<String, Table> getTableMap() {
return ImmutableMap.<String, Table>of("TENS", new SimpleTable() {
private Enumerable<Object[]> superScan(DataContext root) {
return super.scan(root);
}
@Override
public Enumerable<Object[]> scan(final DataContext root) {
scanCount.incrementAndGet();
return new AbstractEnumerable<Object[]>() {
public Enumerator<Object[]> enumerator() {
enumerateCount.incrementAndGet();
return superScan(root).enumerator();
}
};
}
});
}
};
calciteConnection.getRootSchema().add("TEST", schema);
final String sql = "select * from \"TEST\".\"TENS\" where \"i\" < ?";
final PreparedStatement statement = calciteConnection.prepareStatement(sql);
assertThat(scanCount.get(), is(0));
assertThat(enumerateCount.get(), is(0));
// First execute
statement.setInt(1, 20);
assertThat(scanCount.get(), is(0));
ResultSet resultSet = statement.executeQuery();
assertThat(scanCount.get(), is(1));
assertThat(enumerateCount.get(), is(1));
assertThat(resultSet, Matchers.returnsUnordered("i=0", "i=10"));
assertThat(scanCount.get(), is(1));
assertThat(enumerateCount.get(), is(1));
// Second execute
resultSet = statement.executeQuery();
assertThat(scanCount.get(), is(2));
assertThat(resultSet, Matchers.returnsUnordered("i=0", "i=10"));
assertThat(scanCount.get(), is(2));
// Third execute
statement.setInt(1, 30);
resultSet = statement.executeQuery();
assertThat(scanCount.get(), is(3));
assertThat(resultSet, Matchers.returnsUnordered("i=0", "i=10", "i=20"));
assertThat(scanCount.get(), is(3));
}
}
Aggregations