use of org.apache.calcite.sql.advise.SqlAdvisorGetHintsFunction in project calcite by apache.
the class JdbcTest method adviseSql.
private void adviseSql(String sql, Function<ResultSet, Void> checker) throws ClassNotFoundException, SQLException {
Properties info = new Properties();
info.put("lex", "JAVA");
info.put("quoting", "DOUBLE_QUOTE");
Connection connection = DriverManager.getConnection("jdbc:calcite:", info);
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
rootSchema.add("hr", new ReflectiveSchema(new HrSchema()));
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
calciteConnection.setSchema("hr");
final TableFunction table = new SqlAdvisorGetHintsFunction();
schema.add("get_hints", table);
PreparedStatement ps = connection.prepareStatement("select *\n" + "from table(\"s\".\"get_hints\"(?, ?)) as t(id, names, type)");
SqlParserUtil.StringAndPos sap = SqlParserUtil.findPos(sql);
ps.setString(1, sap.sql);
ps.setInt(2, sap.cursor);
final ResultSet resultSet = ps.executeQuery();
checker.apply(resultSet);
resultSet.close();
connection.close();
}
Aggregations