Search in sources :

Example 1 with LogicalDelta

use of org.apache.calcite.rel.stream.LogicalDelta in project calcite by apache.

the class SqlToRelConverter method convertQuery.

/**
 * Converts an unvalidated query's parse tree into a relational expression.
 *
 * @param query           Query to convert
 * @param needsValidation Whether to validate the query before converting;
 *                        <code>false</code> if the query has already been
 *                        validated.
 * @param top             Whether the query is top-level, say if its result
 *                        will become a JDBC result set; <code>false</code> if
 *                        the query will be part of a view.
 */
public RelRoot convertQuery(SqlNode query, final boolean needsValidation, final boolean top) {
    if (needsValidation) {
        query = validator.validate(query);
    }
    RelMetadataQuery.THREAD_PROVIDERS.set(JaninoRelMetadataProvider.of(cluster.getMetadataProvider()));
    RelNode result = convertQueryRecursive(query, top, null).rel;
    if (top) {
        if (isStream(query)) {
            result = new LogicalDelta(cluster, result.getTraitSet(), result);
        }
    }
    RelCollation collation = RelCollations.EMPTY;
    if (!query.isA(SqlKind.DML)) {
        if (isOrdered(query)) {
            collation = requiredCollation(result);
        }
    }
    checkConvertedType(query, result);
    if (SQL2REL_LOGGER.isDebugEnabled()) {
        SQL2REL_LOGGER.debug(RelOptUtil.dumpPlan("Plan after converting SqlNode to RelNode", result, SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES));
    }
    final RelDataType validatedRowType = validator.getValidatedNodeType(query);
    return RelRoot.of(result, validatedRowType, query.getKind()).withCollation(collation);
}
Also used : LogicalDelta(org.apache.calcite.rel.stream.LogicalDelta) RelCollation(org.apache.calcite.rel.RelCollation) RelNode(org.apache.calcite.rel.RelNode) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

RelCollation (org.apache.calcite.rel.RelCollation)1 RelNode (org.apache.calcite.rel.RelNode)1 LogicalDelta (org.apache.calcite.rel.stream.LogicalDelta)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1