Search in sources :

Example 11 with Filter

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());
}
Also used : RelNode(org.apache.calcite.rel.RelNode) LogicalFilter(org.apache.calcite.rel.logical.LogicalFilter) Filter(org.apache.calcite.rel.core.Filter) TridentFilterRel(org.apache.storm.sql.planner.trident.rel.TridentFilterRel)

Example 12 with Filter

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);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) HiveFilter(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter) Filter(org.apache.calcite.rel.core.Filter) LogicalFilter(org.apache.calcite.rel.logical.LogicalFilter) SqlValidatorUtil(org.apache.calcite.sql.validate.SqlValidatorUtil) RelMdUtil(org.apache.calcite.rel.metadata.RelMdUtil) RexUtil(org.apache.calcite.rex.RexUtil) RelOptUtil(org.apache.calcite.plan.RelOptUtil) ReflectUtil(org.apache.calcite.util.ReflectUtil) Util(org.apache.calcite.util.Util) TreeMap(java.util.TreeMap)

Example 13 with Filter

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

Example 14 with Filter

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");
}
Also used : TableScan(org.apache.calcite.rel.core.TableScan) Project(org.apache.calcite.rel.core.Project) Filter(org.apache.calcite.rel.core.Filter) Values(org.apache.calcite.rel.core.Values) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin) Join(org.apache.calcite.rel.core.Join) LogicalSort(org.apache.calcite.rel.logical.LogicalSort) Sort(org.apache.calcite.rel.core.Sort) Aggregate(org.apache.calcite.rel.core.Aggregate) LogicalAggregate(org.apache.calcite.rel.logical.LogicalAggregate)

Example 15 with Filter

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);
}
Also used : RexCall(org.apache.calcite.rex.RexCall) Project(org.apache.calcite.rel.core.Project) HiveProject(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject) RelNode(org.apache.calcite.rel.RelNode) Filter(org.apache.calcite.rel.core.Filter) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

Filter (org.apache.calcite.rel.core.Filter)20 RexNode (org.apache.calcite.rex.RexNode)12 RelNode (org.apache.calcite.rel.RelNode)8 Project (org.apache.calcite.rel.core.Project)7 RexBuilder (org.apache.calcite.rex.RexBuilder)4 TableScan (org.apache.calcite.rel.core.TableScan)3 LogicalFilter (org.apache.calcite.rel.logical.LogicalFilter)3 HiveFilter (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter)3 HiveProject (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject)3 ArrayList (java.util.ArrayList)2 Aggregate (org.apache.calcite.rel.core.Aggregate)2 DimFilter (io.druid.query.filter.DimFilter)1 DruidRel (io.druid.sql.calcite.rel.DruidRel)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 RelOptUtil (org.apache.calcite.plan.RelOptUtil)1 Join (org.apache.calcite.rel.core.Join)1 Sort (org.apache.calcite.rel.core.Sort)1 Values (org.apache.calcite.rel.core.Values)1 LogicalAggregate (org.apache.calcite.rel.logical.LogicalAggregate)1