Search in sources :

Example 1 with HazelcastSqlToRelConverter

use of com.hazelcast.jet.sql.impl.HazelcastSqlToRelConverter 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));
}
Also used : SqlToRelConverter(org.apache.calcite.sql2rel.SqlToRelConverter) HazelcastSqlToRelConverter(com.hazelcast.jet.sql.impl.HazelcastSqlToRelConverter) RelNode(org.apache.calcite.rel.RelNode) RelRoot(org.apache.calcite.rel.RelRoot) HazelcastSqlToRelConverter(com.hazelcast.jet.sql.impl.HazelcastSqlToRelConverter)

Aggregations

HazelcastSqlToRelConverter (com.hazelcast.jet.sql.impl.HazelcastSqlToRelConverter)1 RelNode (org.apache.calcite.rel.RelNode)1 RelRoot (org.apache.calcite.rel.RelRoot)1 SqlToRelConverter (org.apache.calcite.sql2rel.SqlToRelConverter)1