Search in sources :

Example 41 with Filter

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;
}
Also used : Filter(org.apache.calcite.rel.core.Filter)

Example 42 with Filter

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;
        }
    }
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Filter(org.apache.calcite.rel.core.Filter) RexNode(org.apache.calcite.rex.RexNode)

Example 43 with Filter

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);
}
Also used : Project(org.apache.calcite.rel.core.Project) Filter(org.apache.calcite.rel.core.Filter) Join(org.apache.calcite.rel.core.Join) HiveAntiJoin(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveAntiJoin)

Example 44 with Filter

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());
}
Also used : RexCall(org.apache.calcite.rex.RexCall) RelBuilder(org.apache.calcite.tools.RelBuilder) RexShuttle(org.apache.calcite.rex.RexShuttle) Filter(org.apache.calcite.rel.core.Filter) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) RexNode(org.apache.calcite.rex.RexNode)

Example 45 with Filter

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);
}
Also used : Project(org.apache.calcite.rel.core.Project) TableScan(org.apache.calcite.rel.core.TableScan) Filter(org.apache.calcite.rel.core.Filter)

Aggregations

Filter (org.apache.calcite.rel.core.Filter)67 RexNode (org.apache.calcite.rex.RexNode)38 RelNode (org.apache.calcite.rel.RelNode)35 Project (org.apache.calcite.rel.core.Project)23 ArrayList (java.util.ArrayList)20 RexBuilder (org.apache.calcite.rex.RexBuilder)17 Aggregate (org.apache.calcite.rel.core.Aggregate)15 RelBuilder (org.apache.calcite.tools.RelBuilder)15 Join (org.apache.calcite.rel.core.Join)13 TableScan (org.apache.calcite.rel.core.TableScan)11 List (java.util.List)10 Sort (org.apache.calcite.rel.core.Sort)10 RelOptUtil (org.apache.calcite.plan.RelOptUtil)8 ImmutableList (com.google.common.collect.ImmutableList)7 Collectors (java.util.stream.Collectors)7 LogicalFilter (org.apache.calcite.rel.logical.LogicalFilter)7 RelDataType (org.apache.calcite.rel.type.RelDataType)7 RexInputRef (org.apache.calcite.rex.RexInputRef)7 RexUtil (org.apache.calcite.rex.RexUtil)7 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)7