Search in sources :

Example 1 with GroupKey

use of org.apache.calcite.tools.RelBuilder.GroupKey in project hive by apache.

the class HiveSemiJoinRule method recreateAggregateOperator.

protected static RelNode recreateAggregateOperator(RelBuilder builder, int[] adjustments, Aggregate topAggregate, RelNode newInputOperator) {
    builder.push(newInputOperator);
    ImmutableBitSet.Builder newGroupSet = ImmutableBitSet.builder();
    for (int pos : topAggregate.getGroupSet()) {
        newGroupSet.set(pos + adjustments[pos]);
    }
    GroupKey groupKey;
    if (topAggregate.getGroupType() == Group.SIMPLE) {
        groupKey = builder.groupKey(newGroupSet.build());
    } else {
        List<ImmutableBitSet> newGroupSets = new ArrayList<>();
        for (ImmutableBitSet groupingSet : topAggregate.getGroupSets()) {
            ImmutableBitSet.Builder newGroupingSet = ImmutableBitSet.builder();
            for (int pos : groupingSet) {
                newGroupingSet.set(pos + adjustments[pos]);
            }
            newGroupSets.add(newGroupingSet.build());
        }
        groupKey = builder.groupKey(newGroupSet.build(), newGroupSets);
    }
    List<AggregateCall> newAggCallList = new ArrayList<>();
    for (AggregateCall aggregateCall : topAggregate.getAggCallList()) {
        List<Integer> newArgList = aggregateCall.getArgList().stream().map(pos -> pos + adjustments[pos]).collect(Collectors.toList());
        int newFilterArg = aggregateCall.filterArg != -1 ? aggregateCall.filterArg + adjustments[aggregateCall.filterArg] : -1;
        RelCollation newCollation = aggregateCall.getCollation() != null ? RelCollations.of(aggregateCall.getCollation().getFieldCollations().stream().map(fc -> fc.withFieldIndex(fc.getFieldIndex() + adjustments[fc.getFieldIndex()])).collect(Collectors.toList())) : null;
        newAggCallList.add(aggregateCall.copy(newArgList, newFilterArg, newCollation));
    }
    return builder.push(newInputOperator).aggregate(groupKey, newAggCallList).build();
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) Project(org.apache.calcite.rel.core.Project) LoggerFactory(org.slf4j.LoggerFactory) GroupKey(org.apache.calcite.tools.RelBuilder.GroupKey) RelOptUtil(org.apache.calcite.plan.RelOptUtil) Join(org.apache.calcite.rel.core.Join) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) RelOptRuleOperand(org.apache.calcite.plan.RelOptRuleOperand) RexNode(org.apache.calcite.rex.RexNode) RelBuilder(org.apache.calcite.tools.RelBuilder) RelBuilderFactory(org.apache.calcite.tools.RelBuilderFactory) Group(org.apache.calcite.rel.core.Aggregate.Group) HiveRelFactories(org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelFactories) RelOptCluster(org.apache.calcite.plan.RelOptCluster) RelCollations(org.apache.calcite.rel.RelCollations) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) Logger(org.slf4j.Logger) ImmutableIntList(org.apache.calcite.util.ImmutableIntList) RexBuilder(org.apache.calcite.rex.RexBuilder) RelNode(org.apache.calcite.rel.RelNode) Collectors(java.util.stream.Collectors) Aggregate(org.apache.calcite.rel.core.Aggregate) JoinInfo(org.apache.calcite.rel.core.JoinInfo) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) RelOptRule(org.apache.calcite.plan.RelOptRule) HiveCalciteUtil(org.apache.hadoop.hive.ql.optimizer.calcite.HiveCalciteUtil) List(java.util.List) RelCollation(org.apache.calcite.rel.RelCollation) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) JoinRelType(org.apache.calcite.rel.core.JoinRelType) AggregateCall(org.apache.calcite.rel.core.AggregateCall) RelCollation(org.apache.calcite.rel.RelCollation) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) GroupKey(org.apache.calcite.tools.RelBuilder.GroupKey) ArrayList(java.util.ArrayList)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 RelOptRule (org.apache.calcite.plan.RelOptRule)1 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)1 RelOptRuleOperand (org.apache.calcite.plan.RelOptRuleOperand)1 RelOptUtil (org.apache.calcite.plan.RelOptUtil)1 RelCollation (org.apache.calcite.rel.RelCollation)1 RelCollations (org.apache.calcite.rel.RelCollations)1 RelNode (org.apache.calcite.rel.RelNode)1 Aggregate (org.apache.calcite.rel.core.Aggregate)1 Group (org.apache.calcite.rel.core.Aggregate.Group)1 AggregateCall (org.apache.calcite.rel.core.AggregateCall)1 Join (org.apache.calcite.rel.core.Join)1 JoinInfo (org.apache.calcite.rel.core.JoinInfo)1 JoinRelType (org.apache.calcite.rel.core.JoinRelType)1 Project (org.apache.calcite.rel.core.Project)1 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1