use of org.apache.druid.sql.calcite.rel.DruidUnionRel in project druid by druid-io.
the class DruidSortUnionRule method onMatch.
@Override
public void onMatch(final RelOptRuleCall call) {
final Sort sort = call.rel(0);
final DruidUnionRel unionRel = call.rel(1);
final int limit = RexLiteral.intValue(sort.fetch);
final int offset = sort.offset != null ? RexLiteral.intValue(sort.offset) : 0;
final DruidUnionRel newUnionRel = DruidUnionRel.create(unionRel.getPlannerContext(), unionRel.getRowType(), unionRel.getInputs(), unionRel.getLimit() >= 0 ? Math.min(limit + offset, unionRel.getLimit()) : limit + offset);
if (offset == 0) {
call.transformTo(newUnionRel);
} else {
call.transformTo(call.builder().push(newUnionRel).sortLimit(offset, -1, Collections.emptyList()).build());
}
}
use of org.apache.druid.sql.calcite.rel.DruidUnionRel 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);
}
}
Aggregations