Search in sources :

Example 1 with DruidRel

use of org.apache.druid.sql.calcite.rel.DruidRel in project druid by druid-io.

the class DruidPlanner method flattenOutermostRel.

/**
 * Recursive function (DFS) which traverses the nodes and collects the corresponding {@link DruidRel} into a list if
 * they are not of the type {@link DruidUnionRel} or else calls the method with the child nodes. The DFS order of the
 * nodes are retained, since that is the order in which they will actually be called in {@link DruidUnionRel#runQuery()}
 *
 * @param druidRel                The current relNode
 * @param flattendListAccumulator Accumulator list which needs to be appended by this method
 */
private void flattenOutermostRel(DruidRel<?> druidRel, List<DruidRel<?>> flattendListAccumulator) {
    if (druidRel instanceof DruidUnionRel) {
        DruidUnionRel druidUnionRel = (DruidUnionRel) druidRel;
        druidUnionRel.getInputs().forEach(innerRelNode -> {
            // This type conversion should always be possible
            DruidRel<?> innerDruidRelNode = (DruidRel<?>) innerRelNode;
            flattenOutermostRel(innerDruidRelNode, flattendListAccumulator);
        });
    } else {
        flattendListAccumulator.add(druidRel);
    }
}
Also used : DruidRel(org.apache.druid.sql.calcite.rel.DruidRel) DruidUnionRel(org.apache.druid.sql.calcite.rel.DruidUnionRel)

Example 2 with DruidRel

use of org.apache.druid.sql.calcite.rel.DruidRel 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

DruidRel (org.apache.druid.sql.calcite.rel.DruidRel)2 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 DruidUnionRel (org.apache.druid.sql.calcite.rel.DruidUnionRel)1 QueryMaker (org.apache.druid.sql.calcite.run.QueryMaker)1