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);
}
}
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());
}
}
Aggregations