Search in sources :

Example 66 with Project

use of org.apache.calcite.rel.core.Project in project hive by apache.

the class HiveProjectMergeRule method onMatch.

public void onMatch(RelOptRuleCall call) {
    final Project topProject = call.rel(0);
    final Project bottomProject = call.rel(1);
    // If top project does not reference any column at the bottom project,
    // we can just remove botton project
    final ImmutableBitSet topRefs = RelOptUtil.InputFinder.bits(topProject.getProjects(), null);
    if (topRefs.isEmpty()) {
        RelBuilder relBuilder = call.builder();
        relBuilder.push(bottomProject.getInput());
        relBuilder.project(topProject.getProjects());
        call.transformTo(relBuilder.build());
        return;
    }
    super.onMatch(call);
}
Also used : Project(org.apache.calcite.rel.core.Project) RelBuilder(org.apache.calcite.tools.RelBuilder) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet)

Example 67 with Project

use of org.apache.calcite.rel.core.Project in project hive by apache.

the class HiveFilterProjectTransposeRule method onMatch.

public void onMatch(RelOptRuleCall call) {
    final Filter filter = call.rel(0);
    final Project origproject = call.rel(1);
    RexNode filterCondToPushBelowProj = filter.getCondition();
    RexNode unPushedFilCondAboveProj = null;
    if (RexUtil.containsCorrelation(filterCondToPushBelowProj)) {
        // Correlate from being de-correlated.
        return;
    }
    if (RexOver.containsOver(origproject.getProjects(), null)) {
        RexNode origFilterCond = filterCondToPushBelowProj;
        filterCondToPushBelowProj = null;
        if (pushThroughWindowing) {
            Set<Integer> commonPartitionKeys = getCommonPartitionCols(origproject.getProjects());
            List<RexNode> newPartKeyFilConds = new ArrayList<>();
            List<RexNode> unpushedFilConds = new ArrayList<>();
            // from t1 where value < 10)t1)t2
            if (!commonPartitionKeys.isEmpty()) {
                for (RexNode ce : RelOptUtil.conjunctions(origFilterCond)) {
                    RexNode newCondition = RelOptUtil.pushPastProject(ce, origproject);
                    if (HiveCalciteUtil.isDeterministicFuncWithSingleInputRef(newCondition, commonPartitionKeys)) {
                        newPartKeyFilConds.add(ce);
                    } else {
                        unpushedFilConds.add(ce);
                    }
                }
                if (!newPartKeyFilConds.isEmpty()) {
                    filterCondToPushBelowProj = RexUtil.composeConjunction(filter.getCluster().getRexBuilder(), newPartKeyFilConds, true);
                }
                if (!unpushedFilConds.isEmpty()) {
                    unPushedFilCondAboveProj = RexUtil.composeConjunction(filter.getCluster().getRexBuilder(), unpushedFilConds, true);
                }
            }
        }
    }
    if (filterCondToPushBelowProj != null && !isRedundantIsNotNull(origproject, filterCondToPushBelowProj)) {
        RelNode newProjRel = getNewProject(filterCondToPushBelowProj, unPushedFilCondAboveProj, origproject, filter.getCluster().getTypeFactory(), call.builder());
        call.transformTo(newProjRel);
    }
}
Also used : 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) ArrayList(java.util.ArrayList) RexNode(org.apache.calcite.rex.RexNode)

Example 68 with Project

use of org.apache.calcite.rel.core.Project 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 69 with Project

use of org.apache.calcite.rel.core.Project 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 70 with Project

use of org.apache.calcite.rel.core.Project 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)

Aggregations

Project (org.apache.calcite.rel.core.Project)143 RexNode (org.apache.calcite.rex.RexNode)77 RelNode (org.apache.calcite.rel.RelNode)71 ArrayList (java.util.ArrayList)46 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)35 RexBuilder (org.apache.calcite.rex.RexBuilder)28 RelDataType (org.apache.calcite.rel.type.RelDataType)26 Aggregate (org.apache.calcite.rel.core.Aggregate)22 Filter (org.apache.calcite.rel.core.Filter)22 Join (org.apache.calcite.rel.core.Join)22 List (java.util.List)19 RexLiteral (org.apache.calcite.rex.RexLiteral)19 AggregateCall (org.apache.calcite.rel.core.AggregateCall)18 Sort (org.apache.calcite.rel.core.Sort)18 Test (org.junit.Test)18 RelBuilder (org.apache.calcite.tools.RelBuilder)17 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)16 HiveProject (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject)16 Collectors (java.util.stream.Collectors)15 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)15