public void visit(JsonRoot jsonRoot) { checkRequiredAttributes(jsonRoot, "version"); final Pair<String, SchemaPlus> pair = Pair.of(null, connection.getRootSchema()); schemaStack.push(pair); for (JsonSchema schema : jsonRoot.schemas) { schema.accept(this); } final Pair<String, SchemaPlus> p = schemaStack.pop(); assert p == pair; if (jsonRoot.defaultSchema != null) { try { connection.setSchema(jsonRoot.defaultSchema); } catch (SQLException e) { throw new RuntimeException(e); } } }
public void visit(JsonRoot jsonRoot) { checkRequiredAttributes(jsonRoot, "version"); final Pair<String, SchemaPlus> pair = Pair.of(null, connection == null ? rootSchemaPlus : connection.getRootSchema()); schemaStack.push(pair); for (JsonSchema schema : jsonRoot.schemas) { schema.accept(this); } final Pair<String, SchemaPlus> p = schemaStack.pop(); assert p == pair; if (jsonRoot.defaultSchema != null) { try { if (connection != null) { connection.setSchema(jsonRoot.defaultSchema); } else { defaultSchema = jsonRoot.defaultSchema; } } catch (SQLException e) { throw new RuntimeException(e); } } }
public Connection apply(Connection connection) throws SQLException { CalciteConnection con = connection.unwrap(CalciteConnection.class); SchemaPlus rootSchema = con.getRootSchema(); switch (schemaSpec) { case CLONE_FOODMART: case JDBC_FOODMART_WITH_LATTICE: addSchema(rootSchema, SchemaSpec.JDBC_FOODMART); /* fall through */ default: addSchema(rootSchema, schemaSpec); } con.setSchema(schemaSpec.schemaName); return connection; } }
public Connection apply(Connection connection) throws SQLException { CalciteConnection con = connection.unwrap(CalciteConnection.class); SchemaPlus rootSchema = con.getRootSchema(); switch (schemaSpec) { case CLONE_FOODMART: case JDBC_FOODMART_WITH_LATTICE: addSchema(rootSchema, SchemaSpec.JDBC_FOODMART); /* fall through */ default: addSchema(rootSchema, schemaSpec); } con.setSchema(schemaSpec.schemaName); return connection; } }
@Before public void setUp() throws SQLException { Connection connection = DriverManager.getConnection("jdbc:calcite:"); CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); SchemaPlus rootSchema = calciteConnection.getRootSchema(); rootSchema.add("test", new ReflectiveSchema(new TestSchema())); calciteConnection.setSchema("test"); this.conn = calciteConnection; }
@Before public void setUp() throws SQLException { Connection connection = DriverManager.getConnection("jdbc:calcite:"); CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); SchemaPlus rootSchema = calciteConnection.getRootSchema(); rootSchema.add("test", new ReflectiveSchema(new TestSchema())); calciteConnection.setSchema("test"); this.conn = calciteConnection; }
rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema())); SchemaPlus schema = rootSchema.add("s", new AbstractSchema()); calciteConnection.setSchema("hr"); final TableFunction getHints = apiVersion == 1 ? new SqlAdvisorGetHintsFunction() : new SqlAdvisorGetHintsFunction2();
rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema())); SchemaPlus schema = rootSchema.add("s", new AbstractSchema()); calciteConnection.setSchema("hr"); final TableFunction getHints = apiVersion == 1 ? new SqlAdvisorGetHintsFunction() : new SqlAdvisorGetHintsFunction2();
/** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-281">[CALCITE-1919] * NPE when target in ReflectiveSchema belongs to the unnamed package</a>. */ @Test public void testReflectiveSchemaInUnnamedPackage() throws Exception { final Driver driver = new Driver(); try (CalciteConnection connection = (CalciteConnection) driver.connect("jdbc:calcite:", new Properties())) { SchemaPlus rootSchema = connection.getRootSchema(); final Class<?> c = Class.forName("RootHr"); final Object o = c.getDeclaredConstructor().newInstance(); rootSchema.add("hr", new ReflectiveSchema(o)); connection.setSchema("hr"); final Statement statement = connection.createStatement(); final String sql = "select * from \"emps\""; final ResultSet resultSet = statement.executeQuery(sql); final String expected = "empid=100; name=Bill\n" + "empid=200; name=Eric\n" + "empid=150; name=Sebastian\n"; assertThat(CalciteAssert.toString(resultSet), is(expected)); } }
/** Test case for * <a href="https://issues.apache.org/jira/browse/CALCITE-281">[CALCITE-1919] * NPE when target in ReflectiveSchema belongs to the unnamed package</a>. */ @Test public void testReflectiveSchemaInUnnamedPackage() throws Exception { final Driver driver = new Driver(); try (CalciteConnection connection = (CalciteConnection) driver.connect("jdbc:calcite:", new Properties())) { SchemaPlus rootSchema = connection.getRootSchema(); final Class<?> c = Class.forName("RootHr"); final Object o = c.getDeclaredConstructor().newInstance(); rootSchema.add("hr", new ReflectiveSchema(o)); connection.setSchema("hr"); final Statement statement = connection.createStatement(); final String sql = "select * from \"emps\""; final ResultSet resultSet = statement.executeQuery(sql); final String expected = "empid=100; name=Bill\n" + "empid=200; name=Eric\n" + "empid=150; name=Sebastian\n"; assertThat(CalciteAssert.toString(resultSet), is(expected)); } }
SchemaPlus rootSchema = connection.getRootSchema(); rootSchema.add("sale", new ReflectiveSchema(new Smalls.WideSaleSchema())); connection.setSchema("sale"); final Statement statement = connection.createStatement();
SchemaPlus rootSchema = connection.getRootSchema(); rootSchema.add("sale", new ReflectiveSchema(new Smalls.WideSaleSchema())); connection.setSchema("sale"); final Statement statement = connection.createStatement();
public CalciteConnection createConnection() throws SQLException { CalciteConnection connection = (CalciteConnection) new AutoTempDriver(objects) .connect("jdbc:calcite:", new Properties()); final SchemaPlus rootSchema = connection.getRootSchema(); rootSchema.add("hr", new ReflectiveSchema(new HrSchema())); connection.setSchema("hr"); return connection; } })
public CalciteConnection createConnection() throws SQLException { CalciteConnection connection = (CalciteConnection) new AutoTempDriver(objects) .connect("jdbc:calcite:", new Properties()); final SchemaPlus rootSchema = connection.getRootSchema(); rootSchema.add("hr", new ReflectiveSchema(new HrSchema())); connection.setSchema("hr"); return connection; } })
SchemaPlus rootSchema = connection.getRootSchema(); rootSchema.add("hr", new ReflectiveSchema(new HrSchema())); connection.setSchema("hr"); final Statement statement = connection.createStatement(); final ResultSet resultSet =
SchemaPlus rootSchema = connection.getRootSchema(); rootSchema.add("hr", new ReflectiveSchema(new HrSchema())); connection.setSchema("hr"); final Statement statement = connection.createStatement(); final ResultSet resultSet =
SchemaPlus rootSchema = connection.getRootSchema(); rootSchema.add("hr", new ReflectiveSchema(new HrSchema())); connection.setSchema("hr"); final Statement statement = connection.createStatement(); assertFalse((Boolean) CalciteAssert.call(statement, "isCloseOnCompletion"));
SchemaPlus rootSchema = connection.getRootSchema(); rootSchema.add("hr", new ReflectiveSchema(new HrSchema())); connection.setSchema("hr"); final Statement statement = connection.createStatement(); assertFalse((Boolean) CalciteAssert.call(statement, "isCloseOnCompletion"));