use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project drill by apache.
the class PluginConverterRule method matches.
@Override
public boolean matches(RelOptRuleCall call) {
RelNode rel = call.rel(0);
boolean canImplement = false;
// cannot use visitor pattern here, since RelShuttle supports only logical rel implementations
if (rel instanceof Aggregate) {
canImplement = pluginImplementor.canImplement(((Aggregate) rel));
} else if (rel instanceof Filter) {
canImplement = pluginImplementor.canImplement(((Filter) rel));
} else if (rel instanceof DrillLimitRelBase) {
canImplement = pluginImplementor.canImplement(((DrillLimitRelBase) rel));
} else if (rel instanceof Project) {
canImplement = pluginImplementor.canImplement(((Project) rel));
} else if (rel instanceof Sort) {
canImplement = pluginImplementor.canImplement(((Sort) rel));
} else if (rel instanceof Union) {
canImplement = pluginImplementor.canImplement(((Union) rel));
} else if (rel instanceof Join) {
canImplement = pluginImplementor.canImplement(((Join) rel));
}
return canImplement && super.matches(call);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project calcite by apache.
the class RelDecorrelator method decorrelateInputWithValueGenerator.
private Frame decorrelateInputWithValueGenerator(RelNode rel, Frame frame) {
// currently only handles one input
assert rel.getInputs().size() == 1;
RelNode oldInput = frame.r;
final SortedMap<CorDef, Integer> corDefOutputs = new TreeMap<>(frame.corDefOutputs);
final Collection<CorRef> corVarList = cm.mapRefRelToCorRef.get(rel);
// This means that we do not need a value generator.
if (rel instanceof Filter) {
SortedMap<CorDef, Integer> map = new TreeMap<>();
List<RexNode> projects = new ArrayList<>();
for (CorRef correlation : corVarList) {
final CorDef def = correlation.def();
if (corDefOutputs.containsKey(def) || map.containsKey(def)) {
continue;
}
try {
findCorrelationEquivalent(correlation, ((Filter) rel).getCondition());
} catch (Util.FoundOne e) {
if (e.getNode() instanceof RexInputRef) {
map.put(def, ((RexInputRef) e.getNode()).getIndex());
} else {
map.put(def, frame.r.getRowType().getFieldCount() + projects.size());
projects.add((RexNode) e.getNode());
}
}
}
// generator.
if (map.size() == corVarList.size()) {
map.putAll(frame.corDefOutputs);
final RelNode r;
if (!projects.isEmpty()) {
relBuilder.push(oldInput).project(Iterables.concat(relBuilder.fields(), projects));
r = relBuilder.build();
} else {
r = oldInput;
}
return register(rel.getInput(0), r, frame.oldToNewOutputs, map);
}
}
int leftInputOutputCount = frame.r.getRowType().getFieldCount();
// can directly add positions into corDefOutputs since join
// does not change the output ordering from the inputs.
RelNode valueGen = createValueGenerator(corVarList, leftInputOutputCount, corDefOutputs);
RelNode join = LogicalJoin.create(frame.r, valueGen, relBuilder.literal(true), ImmutableSet.<CorrelationId>of(), JoinRelType.INNER);
// Filter) are in the output and in the same position.
return register(rel.getInput(0), join, frame.oldToNewOutputs, corDefOutputs);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project drill by apache.
the class DrillMergeFilterRule method onMatch.
// ~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
Filter topFilter = call.rel(0);
Filter bottomFilter = call.rel(1);
// use RexPrograms to merge the two FilterRels into a single program
// so we can convert the two FilterRel conditions to directly
// reference the bottom FilterRel's child
RexBuilder rexBuilder = topFilter.getCluster().getRexBuilder();
RexProgram bottomProgram = createProgram(bottomFilter);
RexProgram topProgram = createProgram(topFilter);
RexProgram mergedProgram = RexProgramBuilder.mergePrograms(topProgram, bottomProgram, rexBuilder);
RexNode newCondition = mergedProgram.expandLocalRef(mergedProgram.getCondition());
// if(!RexUtil.isFlat(newCondition)){
// RexCall newCall = (RexCall) newCondition;
// newCondition = rexBuilder.makeFlatCall( newCall.getOperator(), newCall.getOperands());
// }
Filter newFilterRel = (Filter) filterFactory.createFilter(bottomFilter.getInput(), RexUtil.flatten(rexBuilder, newCondition));
call.transformTo(newFilterRel);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project drill by apache.
the class DrillPushFilterPastProjectRule method onMatch.
// ~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
Filter filterRel = call.rel(0);
Project projRel = call.rel(1);
RelBuilder builder = call.builder();
// get a conjunctions of the filter condition. For each conjunction, if it refers to ITEM or FLATTEN expression
// then we could not pushed down. Otherwise, it's qualified to be pushed down.
final List<RexNode> predList = RelOptUtil.conjunctions(filterRel.getCondition());
final List<RexNode> qualifiedPredList = Lists.newArrayList();
final List<RexNode> unqualifiedPredList = Lists.newArrayList();
for (final RexNode pred : predList) {
if (DrillRelOptUtil.findOperators(pred, projRel.getProjects(), BANNED_OPERATORS) == null) {
qualifiedPredList.add(pred);
} else {
unqualifiedPredList.add(pred);
}
}
final RexNode qualifedPred = RexUtil.composeConjunction(filterRel.getCluster().getRexBuilder(), qualifiedPredList, true);
if (qualifedPred == null) {
return;
}
// convert the filter to one that references the child of the project
RexNode newCondition = RelOptUtil.pushPastProject(qualifedPred, projRel);
RelNode newFilterRel = builder.push(projRel.getInput()).filter(newCondition).build();
RelNode newProjRel = builder.push(newFilterRel).projectNamed(Pair.left(projRel.getNamedProjects()), Pair.right(projRel.getNamedProjects()), true).build();
final RexNode unqualifiedPred = RexUtil.composeConjunction(filterRel.getCluster().getRexBuilder(), unqualifiedPredList, true);
if (unqualifiedPred == null) {
call.transformTo(newProjRel);
} else {
// if there are filters not qualified to be pushed down, then we have to put those filters on top of
// the new Project operator.
// Filter -- unqualified filters
// \
// Project
// \
// Filter -- qualified filters
RelNode filterNotPushed = builder.push(newProjRel).filter(unqualifiedPred).build();
call.transformTo(filterNotPushed);
}
}
Aggregations