Package org.eigenbase.rel

Examples of org.eigenbase.rel.AggregateRelBase


  @Override
  public void onMatch(RelOptRuleCall call) {
    final ProjectRelBase project = call.rel(0);
    final JoinRelBase join = call.rel(1);
    final RelNode left = call.rel(2);
    final AggregateRelBase aggregate = call.rel(3);
    final BitSet bits = RelOptUtil.InputFinder.bits(project.getProjects(),
        null);
    final BitSet rightBits = BitSets.range(left.getRowType().getFieldCount(),
        join.getRowType().getFieldCount());
    if (bits.intersects(rightBits)) {
      return;
    }
    final JoinInfo joinInfo = join.analyzeCondition();
    if (!joinInfo.rightSet().equals(BitSets.range(aggregate.getGroupCount()))) {
      // Rule requires that aggregate key to be the same as the join key.
      // By the way, neither a super-set nor a sub-set would work.
      return;
    }
    final List<Integer> newRightKeys = Lists.newArrayList();
    final IntList aggregateKeys = BitSets.toList(aggregate.getGroupSet());
    for (int key : joinInfo.rightKeys) {
      newRightKeys.add(aggregateKeys.get(key));
    }
    final SemiJoinRel semiJoin =
        new SemiJoinRel(join.getCluster(),
            join.getCluster().traitSetOf(Convention.NONE),
            left, aggregate.getChild(),
            join.getCondition(), joinInfo.leftKeys,
            ImmutableIntList.copyOf(newRightKeys));
    final ProjectRelBase newProject =
        project.copy(project.getTraitSet(), semiJoin, project.getProjects(),
            project.getRowType());
View Full Code Here


    return validChild;
  }
 
  private static boolean isEmptyGrpAggr(RelNode gbNode) {
    // Verify if both groupset and aggrfunction are empty)
    AggregateRelBase aggrnode = (AggregateRelBase) gbNode;
    if (aggrnode.getGroupSet().isEmpty() && aggrnode.getAggCallList().isEmpty()) {
      return true;
    }
    return false;
  }
View Full Code Here

        ImmutableList.of(intType), longType);
    // TODO: Using 0 might be wrong; might need to walk down to find the
    // proper index of a dummy.
    List<Integer> argList = ImmutableList.of(0);
    AggregateCall dummyCall = new AggregateCall(countFn, false, argList, longType, null);
    AggregateRelBase newAggRel = oldAggRel.copy(oldAggRel.getTraitSet(), oldAggRel.getChild(),
        oldAggRel.getGroupSet(), ImmutableList.of(dummyCall));
    RelNode select = introduceDerivedTable(newAggRel);
    parent.replaceInput(0, select);
  }
View Full Code Here

  @Override
  public boolean matches(RelOptRuleCall call) {
    if (!super.matches(call)) {
      return false;
    }
    AggregateRelBase oldAggRel = (AggregateRelBase) call.rels[0];
    return containsAvgStddevVarCall(oldAggRel.getAggCallList());
  }
View Full Code Here

    return containsAvgStddevVarCall(oldAggRel.getAggCallList());
  }

  @Override
  public void onMatch(RelOptRuleCall ruleCall) {
    AggregateRelBase oldAggRel = (AggregateRelBase) ruleCall.rels[0];
    reduceAggs(ruleCall, oldAggRel);
  }
View Full Code Here

                  input.getRowType().getFieldNames(),
                  Collections.<String>nCopies(
                      extraArgCount,
                      null)));
    }
    AggregateRelBase newAggRel =
        newAggregateRel(
            oldAggRel, input, newCalls);

    RelNode projectRel =
        CalcRel.createProject(
View Full Code Here

        operand(AggregateRelBase.class,
            operand(FilterRelBase.class, any())));
  }

  public void onMatch(RelOptRuleCall call) {
    final AggregateRelBase aggregate = call.rel(0);
    final FilterRelBase filter = call.rel(1);

    // Do the columns used by the filter appear in the output of the aggregate?
    final BitSet filterColumns =
        RelOptUtil.InputFinder.bits(filter.getCondition());
    final BitSet newGroupSet =
        BitSets.union(aggregate.getGroupSet(), filterColumns);
    final RelNode input = filter.getChild();
    final Boolean unique =
        RelMetadataQuery.areColumnsUnique(input, newGroupSet);
    if (unique != null && unique) {
      // The input is already unique on the grouping columns, so there's little
      // advantage of aggregating again. More important, without this check,
      // the rule fires forever: A-F => A-F-A => A-A-F-A => A-A-A-F-A => ...
      return;
    }
    final AggregateRelBase newAggregate =
        aggregate.copy(aggregate.getTraitSet(), input, newGroupSet,
            aggregate.getAggCallList());
    final Mappings.TargetMapping mapping = Mappings.target(
        new Function<Integer, Integer>() {
          public Integer apply(Integer a0) {
            return BitSets.toList(newGroupSet).indexOf(a0);
          }
        },
        input.getRowType().getFieldCount(),
        newGroupSet.cardinality());
    final RexNode newCondition =
        RexUtil.apply(mapping, filter.getCondition());
    final FilterRelBase newFilter = filter.copy(filter.getTraitSet(),
        newAggregate, newCondition);
    if (BitSets.contains(aggregate.getGroupSet(), filterColumns)) {
      // Everything needed by the filter is returned by the aggregate.
      assert newGroupSet.equals(aggregate.getGroupSet());
      call.transformTo(newFilter);
    } else {
      // The filter needs at least one extra column.
      // Now aggregate it away.
      final BitSet topGroupSet = new BitSet();
      for (int c : BitSets.toIter(aggregate.getGroupSet())) {
        topGroupSet.set(BitSets.toList(newGroupSet).indexOf(c));
      }
      final List<AggregateCall> topAggCallList = Lists.newArrayList();
      int i = newGroupSet.cardinality();
      for (AggregateCall aggregateCall : aggregate.getAggCallList()) {
        final Aggregation rollup =
            SubstitutionVisitor.getRollup(aggregateCall.getAggregation());
        if (rollup == null) {
          // This aggregate cannot be rolled up.
          return;
        }
        if (aggregateCall.isDistinct()) {
          // Cannot roll up distinct.
          return;
        }
        topAggCallList.add(
            new AggregateCall(rollup, aggregateCall.isDistinct(),
                ImmutableList.of(i++), aggregateCall.type, aggregateCall.name));
      }
      final AggregateRelBase topAggregate =
          aggregate.copy(aggregate.getTraitSet(), newFilter, topGroupSet,
              topAggCallList);
      call.transformTo(topAggregate);
    }
  }
View Full Code Here

    super(operand, description);
  }

  @Override
  public void onMatch(RelOptRuleCall call) {
    final AggregateRelBase aggregate = call.rel(0);
    final StarTable.StarTableScan scan = call.rel(1);
    apply(call, null, aggregate, scan);
  }
View Full Code Here

        operand(AggregateRelBase.class,
            operand(ProjectRelBase.class, any())));
  }

  public void onMatch(RelOptRuleCall call) {
    final AggregateRelBase aggregate = call.rel(0);
    final ProjectRelBase project = call.rel(1);
    RelNode x = apply(aggregate, project);
    if (x != null) {
      call.transformTo(x);
    }
View Full Code Here

      }
      aggCalls.add(aggregateCall.copy(newArgs.build()));
    }

    final BitSet newGroupSet = BitSets.of(newKeys);
    final AggregateRelBase newAggregate =
        aggregate.copy(aggregate.getTraitSet(), project.getChild(), newGroupSet,
            aggCalls.build());

    // Add a project if the group set is not in the same order or
    // contains duplicates.
    RelNode rel = newAggregate;
    if (!BitSets.toList(newGroupSet).equals(newKeys)) {
      final List<Integer> posList = Lists.newArrayList();
      for (int newKey : newKeys) {
        posList.add(BitSets.toList(newGroupSet).indexOf(newKey));
      }
      for (int i = newAggregate.getGroupSet().cardinality();
           i < newAggregate.getRowType().getFieldCount(); i++) {
        posList.add(i);
      }
      rel = RelOptUtil.createProject(RelFactories.DEFAULT_PROJECT_FACTORY,
          rel, posList);
    }
View Full Code Here

TOP

Related Classes of org.eigenbase.rel.AggregateRelBase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.