use of org.verdictdb.connection.JdbcQueryResult in project traindb by traindb-project.
the class TrainDBQueryEngine method processQuery.
@Override
public VerdictSingleResult processQuery(String query) throws Exception {
SqlParser.Config parserConf = SqlParser.config().withParserFactory(TrainDBCalciteSQLParserImpl.FACTORY).withUnquotedCasing(Casing.TO_LOWER);
FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(schemaManager.getCurrentSchema()).parserConfig(parserConf).build();
Planner planner = Frameworks.getPlanner(config);
SqlNode parse = planner.parse(query);
TableNameQualifier.toFullyQualifiedName(schemaManager, conn.getDefaultSchema(), parse);
LOG.debug("Parsed query: " + parse.toString());
SqlNode validate = planner.validate(parse);
RelRoot relRoot = planner.rel(validate);
LOG.debug(RelOptUtil.dumpPlan("Generated plan: ", relRoot.rel, SqlExplainFormat.TEXT, SqlExplainLevel.ALL_ATTRIBUTES));
SqlDialect.DatabaseProduct dp = SqlDialect.DatabaseProduct.POSTGRESQL;
String queryString = validate.toSqlString(dp.getDialect()).getSql();
LOG.debug("query string: " + queryString);
try {
Connection internalConn = DriverManager.getConnection("jdbc:traindb-calcite:");
PreparedStatement stmt = internalConn.prepareStatement(queryString);
ResultSet rs = stmt.executeQuery();
return new VerdictSingleResultFromDbmsQueryResult(new JdbcQueryResult(rs));
} catch (SQLException e) {
LOG.debug(ExceptionUtils.getStackTrace(e));
}
return null;
}
Aggregations