use of org.apache.calcite.rel.core.Filter in project storm by apache.
the class TridentFilterRule method convert.
@Override
public RelNode convert(RelNode rel) {
final Filter filter = (Filter) rel;
final RelNode input = filter.getInput();
return new TridentFilterRel(filter.getCluster(), filter.getTraitSet().replace(TridentLogicalConvention.INSTANCE), convert(input, input.getTraitSet().replace(TridentLogicalConvention.INSTANCE)), filter.getCondition());
}
use of org.apache.calcite.rel.core.Filter in project hive by apache.
the class HiveRelDecorrelator method decorrelateInputWithValueGenerator.
private Frame decorrelateInputWithValueGenerator(RelNode rel) {
// currently only handles one input input
assert rel.getInputs().size() == 1;
RelNode oldInput = rel.getInput(0);
final Frame frame = map.get(oldInput);
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<>();
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) {
map.put(def, (Integer) e.getNode());
}
}
// generator.
if (map.size() == corVarList.size()) {
map.putAll(frame.corDefOutputs);
return register(oldInput, frame.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, rexBuilder.makeLiteral(true), ImmutableSet.<CorrelationId>of(), JoinRelType.INNER);
// LogicalFilter) are in the output and in the same position.
return register(oldInput, join, frame.oldToNewOutputs, corDefOutputs);
}
use of org.apache.calcite.rel.core.Filter in project hive by apache.
the class HiveMaterializedViewFilterScanRule method onMatch.
//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
final Project project = call.rel(0);
final Filter filter = call.rel(1);
final TableScan scan = call.rel(2);
apply(call, project, filter, scan);
}
use of org.apache.calcite.rel.core.Filter in project hive by apache.
the class SubstitutionVisitor method toMutable.
private static MutableRel toMutable(RelNode rel) {
if (rel instanceof TableScan) {
return MutableScan.of((TableScan) rel);
}
if (rel instanceof Values) {
return MutableValues.of((Values) rel);
}
if (rel instanceof Project) {
final Project project = (Project) rel;
final MutableRel input = toMutable(project.getInput());
return MutableProject.of(input, project.getProjects(), project.getRowType().getFieldNames());
}
if (rel instanceof Filter) {
final Filter filter = (Filter) rel;
final MutableRel input = toMutable(filter.getInput());
return MutableFilter.of(input, filter.getCondition());
}
if (rel instanceof Aggregate) {
final Aggregate aggregate = (Aggregate) rel;
final MutableRel input = toMutable(aggregate.getInput());
return MutableAggregate.of(input, aggregate.indicator, aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList());
}
if (rel instanceof Join) {
final Join join = (Join) rel;
final MutableRel left = toMutable(join.getLeft());
final MutableRel right = toMutable(join.getRight());
return MutableJoin.of(join.getCluster(), left, right, join.getCondition(), join.getJoinType(), join.getVariablesSet());
}
if (rel instanceof Sort) {
final Sort sort = (Sort) rel;
final MutableRel input = toMutable(sort.getInput());
return MutableSort.of(input, sort.getCollation(), sort.offset, sort.fetch);
}
throw new RuntimeException("cannot translate " + rel + " to MutableRel");
}
use of org.apache.calcite.rel.core.Filter in project hive by apache.
the class HiveFilterProjectTSTransposeRule method onMatch.
// ~ Methods ----------------------------------------------------------------
// implement RelOptRule
public void onMatch(RelOptRuleCall call) {
final Filter filter = call.rel(0);
final Project project = call.rel(1);
if (RexOver.containsOver(project.getProjects(), null)) {
// it can be pushed down. For now we don't support this.
return;
}
if (RexUtil.containsCorrelation(filter.getCondition())) {
// Correlate from being de-correlated.
return;
}
// convert the filter to one that references the child of the project
RexNode newCondition = RelOptUtil.pushPastProject(filter.getCondition(), project);
// Remove cast of BOOLEAN NOT NULL to BOOLEAN or vice versa. Filter accepts
// nullable and not-nullable conditions, but a CAST might get in the way of
// other rewrites.
final RelDataTypeFactory typeFactory = filter.getCluster().getTypeFactory();
if (RexUtil.isNullabilityCast(typeFactory, newCondition)) {
newCondition = ((RexCall) newCondition).getOperands().get(0);
}
RelNode newFilterRel = filterFactory == null ? filter.copy(filter.getTraitSet(), project.getInput(), newCondition) : filterFactory.createFilter(project.getInput(), newCondition);
RelNode newProjRel = projectFactory == null ? project.copy(project.getTraitSet(), newFilterRel, project.getProjects(), project.getRowType()) : projectFactory.createProject(newFilterRel, project.getProjects(), project.getRowType().getFieldNames());
call.transformTo(newProjRel);
}
Aggregations