use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project hive by apache.
the class HiveFilterSortPredicates method matches.
@Override
public boolean matches(RelOptRuleCall call) {
final Filter filter = call.rel(0);
HiveRulesRegistry registry = call.getPlanner().getContext().unwrap(HiveRulesRegistry.class);
// we do not need to apply the optimization
if (registry != null && registry.getVisited(this).contains(filter)) {
return false;
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project hive by apache.
the class HiveFilterSortPredicates method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
try {
final Filter filter = call.rel(0);
final RelNode input = call.rel(1);
// Register that we have visited this operator in this rule
HiveRulesRegistry registry = call.getPlanner().getContext().unwrap(HiveRulesRegistry.class);
if (registry != null) {
registry.registerVisited(this, filter);
}
final RexNode originalCond = filter.getCondition();
final RexSortPredicatesShuttle sortPredicatesShuttle = new RexSortPredicatesShuttle(input, filter.getCluster().getMetadataQuery());
final RexNode newCond = originalCond.accept(sortPredicatesShuttle);
if (!sortPredicatesShuttle.modified) {
// We are done, bail out
return;
}
// We register the new filter so we do not fire the rule on it again
final Filter newFilter = filter.copy(filter.getTraitSet(), input, newCond);
if (registry != null) {
registry.registerVisited(this, newFilter);
}
call.transformTo(newFilter);
} catch (Exception e) {
if (noColsMissingStats.get() > 0) {
LOG.warn("Missing column stats (see previous messages), skipping sort predicates in filter expressions in CBO");
noColsMissingStats.set(0);
} else {
throw e;
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project hive by apache.
the class HiveAntiSemiJoinRule method onMatch.
// is null filter over a left join.
public void onMatch(final RelOptRuleCall call) {
final Project project = call.rel(0);
final Filter filter = call.rel(1);
final Join join = call.rel(2);
perform(call, project, filter, join);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project hive by apache.
the class FilterFlattenCorrelatedConditionRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
Filter filter = call.rel(0);
RelBuilder b = call.builder();
b.push(filter.getInput());
final int proj = b.fields().size();
List<RexNode> projOperands = new ArrayList<>();
RexNode newCondition = filter.getCondition().accept(new RexShuttle() {
@Override
public RexNode visitCall(RexCall call) {
switch(call.getKind()) {
case EQUALS:
case NOT_EQUALS:
case GREATER_THAN:
case GREATER_THAN_OR_EQUAL:
case LESS_THAN:
case LESS_THAN_OR_EQUAL:
RexNode op0 = call.operands.get(0);
RexNode op1 = call.operands.get(1);
final int replaceIndex;
if (RexUtil.containsCorrelation(op1) && isUncorrelatedCall(op0)) {
replaceIndex = 0;
} else if (RexUtil.containsCorrelation(op0) && isUncorrelatedCall(op1)) {
replaceIndex = 1;
} else {
// Structure does not match, do not replace
replaceIndex = -1;
}
if (replaceIndex != -1) {
List<RexNode> copyOperands = new ArrayList<>(call.operands);
RexNode oldOp = call.operands.get(replaceIndex);
RexNode newOp = b.getRexBuilder().makeInputRef(oldOp.getType(), proj + projOperands.size());
projOperands.add(oldOp);
copyOperands.set(replaceIndex, newOp);
return call.clone(call.type, copyOperands);
}
break;
case AND:
case OR:
return super.visitCall(call);
}
return call;
}
});
if (newCondition.equals(filter.getCondition())) {
return;
}
b.projectPlus(projOperands);
b.filter(newCondition);
b.project(b.fields(ImmutableBitSet.range(proj).asList()));
call.transformTo(b.build());
}
use of org.apache.beam.vendor.calcite.v1_28_0.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);
}
Aggregations