private CachedStatement buildCachedStatement(final String sql, final Supplier<CalciteConnection> connectionSupplier, final ProcessSession session, final FlowFile flowFile, final RecordReaderFactory recordReaderFactory) throws SQLException { final CalciteConnection connection = connectionSupplier.get(); final SchemaPlus rootSchema = connection.getRootSchema(); final FlowFileTable<?, ?> flowFileTable = new FlowFileTable<>(session, flowFile, recordReaderFactory, getLogger()); rootSchema.add("FLOWFILE", flowFileTable); rootSchema.setCacheEnabled(false); final PreparedStatement stmt = connection.prepareStatement(sql); return new CachedStatement(stmt, flowFileTable, connection); }
rootSchema.setCacheEnabled(false);
private void populateSchema(JsonSchema jsonSchema, SchemaPlus schema) { if (jsonSchema.cache != null) { schema.setCacheEnabled(jsonSchema.cache); } final Pair<String, SchemaPlus> pair = Pair.of(jsonSchema.name, schema); schemaStack.push(pair); jsonSchema.visitChildren(this); final Pair<String, SchemaPlus> p = schemaStack.pop(); assert p == pair; }
private void populateSchema(JsonSchema jsonSchema, SchemaPlus schema) { if (jsonSchema.cache != null) { schema.setCacheEnabled(jsonSchema.cache); } final Pair<String, SchemaPlus> pair = Pair.of(jsonSchema.name, schema); schemaStack.push(pair); jsonSchema.visitChildren(this); final Pair<String, SchemaPlus> p = schemaStack.pop(); assert p == pair; }
private CachedStatement buildCachedStatement(final String sql, final Supplier<CalciteConnection> connectionSupplier, final ProcessSession session, final FlowFile flowFile, final RecordReaderFactory recordReaderFactory) throws SQLException { final CalciteConnection connection = connectionSupplier.get(); final SchemaPlus rootSchema = connection.getRootSchema(); final FlowFileTable<?, ?> flowFileTable = new FlowFileTable<>(session, flowFile, recordReaderFactory, getLogger()); rootSchema.add("FLOWFILE", flowFileTable); rootSchema.setCacheEnabled(false); final PreparedStatement stmt = connection.prepareStatement(sql); return new CachedStatement(stmt, flowFileTable, connection); }
rootSchema.setCacheEnabled(false);
@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)); }
@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)); }
aSchema.setCacheEnabled(true); assertThat(aSchema.getSubSchemaNames().size(), is(0)); assertThat(aSchema.getSubSchemaNames().size(), is(0)); assertThat(aSchema.getSubSchema("b1"), nullValue()); aSchema.setCacheEnabled(false); assertThat(aSchema.getSubSchemaNames().size(), is(1)); assertThat(aSchema.getSubSchema("b1"), notNullValue()); aSchema.setCacheEnabled(true); assertThat(aSchema.getSubSchemaNames().size(), is(2)); aSchema.add("b3", new AbstractSchema()); // explicit aSubSchemaMap.put("b4", new AbstractSchema()); // implicit assertThat(aSchema.getSubSchemaNames().size(), is(3)); aSchema.setCacheEnabled(false); assertThat(aSchema.getSubSchemaNames().size(), is(4)); for (String name : aSchema.getSubSchemaNames()) { a2Schema.setCacheEnabled(true); assertThat(a2Schema.getSubSchemaNames().size(), is(0)); a2Schema.setCacheEnabled(false); assertThat(a2Schema.getSubSchemaNames().size(), is(1)); a2SubSchemaMap.put("b4", new AbstractSchema());
aSchema.setCacheEnabled(true); assertThat(aSchema.getSubSchemaNames().size(), is(0)); assertThat(aSchema.getSubSchemaNames().size(), is(0)); assertThat(aSchema.getSubSchema("b1"), nullValue()); aSchema.setCacheEnabled(false); assertThat(aSchema.getSubSchemaNames().size(), is(1)); assertThat(aSchema.getSubSchema("b1"), notNullValue()); aSchema.setCacheEnabled(true); assertThat(aSchema.getSubSchemaNames().size(), is(2)); aSchema.add("b3", new AbstractSchema()); // explicit aSubSchemaMap.put("b4", new AbstractSchema()); // implicit assertThat(aSchema.getSubSchemaNames().size(), is(3)); aSchema.setCacheEnabled(false); assertThat(aSchema.getSubSchemaNames().size(), is(4)); for (String name : aSchema.getSubSchemaNames()) { a2Schema.setCacheEnabled(true); assertThat(a2Schema.getSubSchemaNames().size(), is(0)); a2Schema.setCacheEnabled(false); assertThat(a2Schema.getSubSchemaNames().size(), is(1)); a2SubSchemaMap.put("b4", new AbstractSchema());