Search in sources :

Example 1 with QueryMaker

use of org.apache.druid.sql.calcite.run.QueryMaker in project druid by druid-io.

the class DruidPlanner method planWithDruidConvention.

/**
 * Construct a {@link PlannerResult} for a {@link RelNode} that is directly translatable to a native Druid query.
 */
private PlannerResult planWithDruidConvention(final RelRoot root, @Nullable final SqlExplain explain, @Nullable final SqlInsert insert) throws ValidationException, RelConversionException {
    final RelRoot possiblyLimitedRoot = possiblyWrapRootWithOuterLimitFromContext(root);
    final QueryMaker queryMaker = buildQueryMaker(root, insert);
    plannerContext.setQueryMaker(queryMaker);
    RelNode parameterized = rewriteRelDynamicParameters(possiblyLimitedRoot.rel);
    final DruidRel<?> druidRel = (DruidRel<?>) planner.transform(Rules.DRUID_CONVENTION_RULES, planner.getEmptyTraitSet().replace(DruidConvention.instance()).plus(root.collation), parameterized);
    if (explain != null) {
        return planExplanation(druidRel, explain, true);
    } else {
        final Supplier<Sequence<Object[]>> resultsSupplier = () -> {
            // sanity check
            final Set<ResourceAction> readResourceActions = plannerContext.getResourceActions().stream().filter(action -> action.getAction() == Action.READ).collect(Collectors.toSet());
            Preconditions.checkState(readResourceActions.isEmpty() == druidRel.getDataSourceNames().isEmpty() || // them with InlineDataSource of empty rows.
            readResourceActions.size() >= druidRel.getDataSourceNames().size(), "Authorization sanity check failed");
            return druidRel.runQuery();
        };
        return new PlannerResult(resultsSupplier, queryMaker.getResultType());
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) RelNode(org.apache.calcite.rel.RelNode) DruidRel(org.apache.druid.sql.calcite.rel.DruidRel) QueryMaker(org.apache.druid.sql.calcite.run.QueryMaker) RelRoot(org.apache.calcite.rel.RelRoot) Sequence(org.apache.druid.java.util.common.guava.Sequence) BaseSequence(org.apache.druid.java.util.common.guava.BaseSequence)

Aggregations

HashSet (java.util.HashSet)1 Set (java.util.Set)1 RelNode (org.apache.calcite.rel.RelNode)1 RelRoot (org.apache.calcite.rel.RelRoot)1 BaseSequence (org.apache.druid.java.util.common.guava.BaseSequence)1 Sequence (org.apache.druid.java.util.common.guava.Sequence)1 DruidRel (org.apache.druid.sql.calcite.rel.DruidRel)1 QueryMaker (org.apache.druid.sql.calcite.run.QueryMaker)1