use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project dingo by dingodb.
the class TestPhysicalPlan method parse.
private static RelNode parse(String sql) throws SqlParseException {
SqlNode sqlNode = parser.parse(sql);
sqlNode = parser.validate(sqlNode);
RelRoot relRoot = parser.convert(sqlNode);
RelNode relNode = parser.optimize(relRoot.rel);
log.info("relNode = {}", relNode);
return relNode;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot 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;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project beam by apache.
the class ZetaSQLPlannerImpl method rel.
public RelRoot rel(String sql, QueryParameters params) {
RelOptCluster cluster = RelOptCluster.create(planner, new RexBuilder(typeFactory));
AnalyzerOptions options = SqlAnalyzer.getAnalyzerOptions(params, defaultTimezone);
BeamZetaSqlCatalog catalog = BeamZetaSqlCatalog.create(defaultSchemaPlus, (JavaTypeFactory) cluster.getTypeFactory(), options);
// Set up table providers that need to be pre-registered
SqlAnalyzer analyzer = new SqlAnalyzer();
List<List<String>> tables = analyzer.extractTableNames(sql, options);
TableResolution.registerTables(this.defaultSchemaPlus, tables);
QueryTrait trait = new QueryTrait();
catalog.addTables(tables, trait);
ResolvedQueryStmt statement = analyzer.analyzeQuery(sql, options, catalog);
ExpressionConverter expressionConverter = new ExpressionConverter(cluster, params, catalog.getUserFunctionDefinitions());
ConversionContext context = ConversionContext.of(config, expressionConverter, cluster, trait);
RelNode convertedNode = QueryStatementConverter.convertRootQuery(context, statement);
return RelRoot.of(convertedNode, SqlKind.ALL);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project hazelcast by hazelcast.
the class QueryConverter method convert.
public QueryConvertResult convert(SqlNode node) {
SqlToRelConverter converter = new HazelcastSqlToRelConverter(viewExpander, validator, catalogReader, cluster, StandardConvertletTable.INSTANCE, CONFIG);
// 1. Perform initial conversion.
RelRoot root = converter.convertQuery(node, false, true);
// 2. Remove subquery expressions, converting them to Correlate nodes.
RelNode relNoSubqueries = rewriteSubqueries(root.project());
// 3. Perform decorrelation, i.e. rewrite a nested loop where the right side depends on the value of the left side,
// to a variation of joins, semijoins and aggregations, which could be executed much more efficiently.
// See "Unnesting Arbitrary Queries", Thomas Neumann and Alfons Kemper.
RelNode result = converter.decorrelate(node, relNoSubqueries);
// The bug is likely in decorrelation which produces LogicalAggregate with 0 output columns.
if (!hasNestedExists(root.rel)) {
result = converter.trimUnusedFields(true, result);
}
// 5. Collect original field names.
return new QueryConvertResult(result, Pair.right(root.fields));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project hazelcast by hazelcast.
the class HazelcastViewExpander method expandView.
@Override
public RelRoot expandView(RelDataType rowType, String queryString, List<String> schemaPath, @Nullable List<String> viewPath) {
if (expansionStack.contains(viewPath)) {
throw QueryException.error("Cycle detected in view references");
}
expansionStack.push(viewPath);
SqlNode sqlNode = parser.parse(queryString).getNode();
final RelRoot root = sqlToRelConverter.convertQuery(sqlNode, true, true);
expansionStack.pop();
final RelRoot root2 = root.withRel(sqlToRelConverter.flattenTypes(root.rel, true));
final RelBuilder relBuilder = QueryConverter.CONFIG.getRelBuilderFactory().create(relOptCluster, null);
return root2.withRel(RelDecorrelator.decorrelateQuery(root.rel, relBuilder));
}
Aggregations