当前位置: 首页>>代码示例>>Java>>正文


Java Aggregate.getGroupCount方法代码示例

本文整理汇总了Java中org.apache.calcite.rel.core.Aggregate.getGroupCount方法的典型用法代码示例。如果您正苦于以下问题:Java Aggregate.getGroupCount方法的具体用法?Java Aggregate.getGroupCount怎么用?Java Aggregate.getGroupCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.rel.core.Aggregate的用法示例。


在下文中一共展示了Aggregate.getGroupCount方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setAggChildKeys

import org.apache.calcite.rel.core.Aggregate; //导入方法依赖的package包/类
/**
 * Takes a bitmap representing a set of input references and extracts the
 * ones that reference the group by columns in an aggregate.
 *
 * @param groupKey the original bitmap
 * @param aggRel   the aggregate
 * @param childKey sets bits from groupKey corresponding to group by columns
 */
public static void setAggChildKeys(
    ImmutableBitSet groupKey,
    Aggregate aggRel,
    ImmutableBitSet.Builder childKey) {
  List<AggregateCall> aggCalls = aggRel.getAggCallList();
  for (int bit : groupKey) {
    if (bit < aggRel.getGroupCount()) {
      // group by column
      childKey.set(bit);
    } else {
      // aggregate column -- set a bit for each argument being
      // aggregated
      AggregateCall agg = aggCalls.get(bit
          - (aggRel.getGroupCount() + aggRel.getIndicatorCount()));
      for (Integer arg : agg.getArgList()) {
        childKey.set(arg);
      }
    }
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:29,代码来源:RelMdUtil.java

示例2: createAggregateCallWithBinding

import org.apache.calcite.rel.core.Aggregate; //导入方法依赖的package包/类
private AggregateCall createAggregateCallWithBinding(
    RelDataTypeFactory typeFactory,
    SqlAggFunction aggFunction,
    RelDataType operandType,
    Aggregate oldAggRel,
    AggregateCall oldCall,
    int argOrdinal) {
  final Aggregate.AggCallBinding binding =
      new Aggregate.AggCallBinding(typeFactory, aggFunction,
          ImmutableList.of(operandType), oldAggRel.getGroupCount(),
          oldCall.filterArg >= 0);
  return AggregateCall.create(aggFunction,
      oldCall.isDistinct(),
      oldCall.isApproximate(),
      ImmutableIntList.of(argOrdinal),
      oldCall.filterArg,
      aggFunction.inferReturnType(binding),
      null);
}
 
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:AggregateReduceFunctionsRule.java

示例3: getColumnOrigins

import org.apache.calcite.rel.core.Aggregate; //导入方法依赖的package包/类
public Set<RelColumnOrigin> getColumnOrigins(Aggregate rel,
    RelMetadataQuery mq, int iOutputColumn) {
  if (iOutputColumn < rel.getGroupCount()) {
    // Group columns pass through directly.
    return mq.getColumnOrigins(rel.getInput(), iOutputColumn);
  }

  if (rel.indicator) {
    if (iOutputColumn < rel.getGroupCount() + rel.getIndicatorCount()) {
      // The indicator column is originated here.
      return ImmutableSet.of();
    }
  }

  // Aggregate columns are derived from input columns
  AggregateCall call =
      rel.getAggCallList().get(iOutputColumn
              - rel.getGroupCount() - rel.getIndicatorCount());

  final Set<RelColumnOrigin> set = new HashSet<>();
  for (Integer iInput : call.getArgList()) {
    Set<RelColumnOrigin> inputSet =
        mq.getColumnOrigins(rel.getInput(), iInput);
    inputSet = createDerivedColumnOrigins(inputSet);
    if (inputSet != null) {
      set.addAll(inputSet);
    }
  }
  return set;
}
 
开发者ID:apache,项目名称:calcite,代码行数:31,代码来源:RelMdColumnOrigins.java

示例4: extractReferences

import org.apache.calcite.rel.core.Aggregate; //导入方法依赖的package包/类
/**
 * If the node is an Aggregate, it returns a list of references to the grouping columns.
 * Otherwise, it returns a list of references to all columns in the node.
 * The returned list is immutable.
 */
private static List<RexNode> extractReferences(RexBuilder rexBuilder, RelNode node) {
  ImmutableList.Builder<RexNode> exprs = ImmutableList.builder();
  if (node instanceof Aggregate) {
    Aggregate aggregate = (Aggregate) node;
    for (int i = 0; i < aggregate.getGroupCount(); i++) {
      exprs.add(rexBuilder.makeInputRef(aggregate, i));
    }
  } else {
    for (int i = 0; i < node.getRowType().getFieldCount(); i++) {
      exprs.add(rexBuilder.makeInputRef(node, i));
    }
  }
  return exprs.build();
}
 
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:AbstractMaterializedViewRule.java

示例5: reduceAggs

import org.apache.calcite.rel.core.Aggregate; //导入方法依赖的package包/类
/**
 * Reduces all calls to AVG, STDDEV_POP, STDDEV_SAMP, VAR_POP, VAR_SAMP in
 * the aggregates list to.
 *
 * <p>It handles newly generated common subexpressions since this was done
 * at the sql2rel stage.
 */
private void reduceAggs(
    RelOptRuleCall ruleCall,
    Aggregate oldAggRel) {
  RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder();

  List<AggregateCall> oldCalls = oldAggRel.getAggCallList();
  final int nGroups = oldAggRel.getGroupCount();

  List<AggregateCall> newCalls = new ArrayList<AggregateCall>();
  Map<AggregateCall, RexNode> aggCallMapping =
      new HashMap<AggregateCall, RexNode>();

  List<RexNode> projList = new ArrayList<RexNode>();

  // pass through group key
  for (int i = 0; i < nGroups; ++i) {
    projList.add(
        rexBuilder.makeInputRef(
            getFieldType(oldAggRel, i),
            i));
  }

  // List of input expressions. If a particular aggregate needs more, it
  // will add an expression to the end, and we will create an extra
  // project.
  RelNode input = oldAggRel.getInput();
  List<RexNode> inputExprs = new ArrayList<RexNode>();
  for (RelDataTypeField field : input.getRowType().getFieldList()) {
    inputExprs.add(
        rexBuilder.makeInputRef(
            field.getType(), inputExprs.size()));
  }

  // create new agg function calls and rest of project list together
  for (AggregateCall oldCall : oldCalls) {
    projList.add(
        reduceAgg(
            oldAggRel, oldCall, newCalls, aggCallMapping, inputExprs));
  }

  final int extraArgCount =
      inputExprs.size() - input.getRowType().getFieldCount();
  if (extraArgCount > 0) {
    input =
        RelOptUtil.createProject(
            input,
            inputExprs,
            CompositeList.of(
                input.getRowType().getFieldNames(),
                Collections.<String>nCopies(
                    extraArgCount,
                    null)));
  }
  Aggregate newAggRel =
      newAggregateRel(
          oldAggRel, input, newCalls);

  RelNode projectRel =
      RelOptUtil.createProject(
          newAggRel,
          projList,
          oldAggRel.getRowType().getFieldNames());

  ruleCall.transformTo(projectRel);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:73,代码来源:DrillReduceAggregatesRule.java

示例6: reduceSum

import org.apache.calcite.rel.core.Aggregate; //导入方法依赖的package包/类
private RexNode reduceSum(
    Aggregate oldAggRel,
    AggregateCall oldCall,
    List<AggregateCall> newCalls,
    Map<AggregateCall, RexNode> aggCallMapping) {
  final int nGroups = oldAggRel.getGroupCount();
  RelDataTypeFactory typeFactory =
      oldAggRel.getCluster().getTypeFactory();
  RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder();
  int arg = oldCall.getArgList().get(0);
  RelDataType argType =
      getFieldType(
          oldAggRel.getInput(),
          arg);
  RelDataType sumType =
      typeFactory.createTypeWithNullability(
          argType, argType.isNullable());
  SqlAggFunction sumZeroAgg = new SqlSumEmptyIsZeroAggFunction();
  AggregateCall sumZeroCall =
      new AggregateCall(
          sumZeroAgg,
          oldCall.isDistinct(),
          oldCall.getArgList(),
          sumType,
          null);
  final SqlCountAggFunction countAgg = (SqlCountAggFunction) SqlStdOperatorTable.COUNT;
  final RelDataType countType = countAgg.getReturnType(typeFactory);
  AggregateCall countCall =
      new AggregateCall(
          countAgg,
          oldCall.isDistinct(),
          oldCall.getArgList(),
          countType,
          null);

  // NOTE:  these references are with respect to the output
  // of newAggRel
  RexNode sumZeroRef =
      rexBuilder.addAggCall(
          sumZeroCall,
          nGroups,
          oldAggRel.indicator,
          newCalls,
          aggCallMapping,
          ImmutableList.of(argType));
  if (!oldCall.getType().isNullable()) {
    // If SUM(x) is not nullable, the validator must have determined that
    // nulls are impossible (because the group is never empty and x is never
    // null). Therefore we translate to SUM0(x).
    return sumZeroRef;
  }
  RexNode countRef =
      rexBuilder.addAggCall(
          countCall,
          nGroups,
          oldAggRel.indicator,
          newCalls,
          aggCallMapping,
          ImmutableList.of(argType));
  return rexBuilder.makeCall(SqlStdOperatorTable.CASE,
      rexBuilder.makeCall(SqlStdOperatorTable.EQUALS,
          countRef, rexBuilder.makeExactLiteral(BigDecimal.ZERO)),
          rexBuilder.constantNull(),
          sumZeroRef);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:66,代码来源:DrillReduceAggregatesRule.java

示例7: reduceAggs

import org.apache.calcite.rel.core.Aggregate; //导入方法依赖的package包/类
/**
 * Reduces all calls to AVG, STDDEV_POP, STDDEV_SAMP, VAR_POP, VAR_SAMP in
 * the aggregates list to.
 *
 * <p>It handles newly generated common subexpressions since this was done
 * at the sql2rel stage.
 */
private void reduceAggs(
    RelOptRuleCall ruleCall,
    Aggregate oldAggRel) {
  RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder();

  List<AggregateCall> oldCalls = oldAggRel.getAggCallList();
  final int nGroups = oldAggRel.getGroupCount();

  List<AggregateCall> newCalls = new ArrayList<>();
  Map<AggregateCall, RexNode> aggCallMapping =
      new HashMap<>();

  List<RexNode> projList = new ArrayList<>();

  // pass through group key
  for (int i = 0; i < nGroups; ++i) {
    projList.add(
        rexBuilder.makeInputRef(
            getFieldType(oldAggRel, i),
            i));
  }

  // List of input expressions. If a particular aggregate needs more, it
  // will add an expression to the end, and we will create an extra
  // project.
  RelNode input = oldAggRel.getInput();
  List<RexNode> inputExprs = new ArrayList<>();
  for (RelDataTypeField field : input.getRowType().getFieldList()) {
    inputExprs.add(
        rexBuilder.makeInputRef(
            field.getType(), inputExprs.size()));
  }

  // create new agg function calls and rest of project list together
  for (AggregateCall oldCall : oldCalls) {
    projList.add(
        reduceAgg(
            oldAggRel, oldCall, newCalls, aggCallMapping, inputExprs));
  }

  final int extraArgCount =
      inputExprs.size() - input.getRowType().getFieldCount();
  if (extraArgCount > 0) {
    input =
        RelOptUtil.createProject(
            input,
            inputExprs,
            CompositeList.of(
                input.getRowType().getFieldNames(),
                Collections.<String>nCopies(
                    extraArgCount,
                    null)));
  }
  Aggregate newAggRel =
      newAggregateRel(
          oldAggRel, input, newCalls);

  RelNode projectRel =
      RelOptUtil.createProject(
          newAggRel,
          projList,
          oldAggRel.getRowType().getFieldNames());

  ruleCall.transformTo(projectRel);
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:73,代码来源:DrillReduceAggregatesRule.java

示例8: reduceAggs

import org.apache.calcite.rel.core.Aggregate; //导入方法依赖的package包/类
/**
 * Reduces all calls to AVG, STDDEV_POP, STDDEV_SAMP, VAR_POP, VAR_SAMP in
 * the aggregates list to.
 *
 * <p>It handles newly generated common subexpressions since this was done
 * at the sql2rel stage.
 */
private void reduceAggs(
    RelOptRuleCall ruleCall,
    Aggregate oldAggRel) {
  RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder();

  List<AggregateCall> oldCalls = oldAggRel.getAggCallList();
  final int groupCount = oldAggRel.getGroupCount();
  final int indicatorCount = oldAggRel.getIndicatorCount();

  final List<AggregateCall> newCalls = Lists.newArrayList();
  final Map<AggregateCall, RexNode> aggCallMapping = Maps.newHashMap();

  final List<RexNode> projList = Lists.newArrayList();

  // pass through group key (+ indicators if present)
  for (int i = 0; i < groupCount + indicatorCount; ++i) {
    projList.add(
        rexBuilder.makeInputRef(
            getFieldType(oldAggRel, i),
            i));
  }

  // List of input expressions. If a particular aggregate needs more, it
  // will add an expression to the end, and we will create an extra
  // project.
  final RelBuilder relBuilder = ruleCall.builder();
  relBuilder.push(oldAggRel.getInput());
  final List<RexNode> inputExprs = new ArrayList<>(relBuilder.fields());

  // create new agg function calls and rest of project list together
  for (AggregateCall oldCall : oldCalls) {
    projList.add(
        reduceAgg(
            oldAggRel, oldCall, newCalls, aggCallMapping, inputExprs));
  }

  final int extraArgCount =
      inputExprs.size() - relBuilder.peek().getRowType().getFieldCount();
  if (extraArgCount > 0) {
    relBuilder.project(inputExprs,
        CompositeList.of(
            relBuilder.peek().getRowType().getFieldNames(),
            Collections.<String>nCopies(extraArgCount, null)));
  }
  newAggregateRel(relBuilder, oldAggRel, newCalls);
  relBuilder.project(projList, oldAggRel.getRowType().getFieldNames());
  ruleCall.transformTo(relBuilder.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:56,代码来源:AggregateReduceFunctionsRule.java

示例9: reduceAgg

import org.apache.calcite.rel.core.Aggregate; //导入方法依赖的package包/类
private RexNode reduceAgg(
    Aggregate oldAggRel,
    AggregateCall oldCall,
    List<AggregateCall> newCalls,
    Map<AggregateCall, RexNode> aggCallMapping,
    List<RexNode> inputExprs) {
  final SqlKind kind = oldCall.getAggregation().getKind();
  if (isReducible(kind)) {
    switch (kind) {
    case SUM:
      // replace original SUM(x) with
      // case COUNT(x) when 0 then null else SUM0(x) end
      return reduceSum(oldAggRel, oldCall, newCalls, aggCallMapping);
    case AVG:
      // replace original AVG(x) with SUM(x) / COUNT(x)
      return reduceAvg(oldAggRel, oldCall, newCalls, aggCallMapping, inputExprs);
    case STDDEV_POP:
      // replace original STDDEV_POP(x) with
      //   SQRT(
      //     (SUM(x * x) - SUM(x) * SUM(x) / COUNT(x))
      //     / COUNT(x))
      return reduceStddev(oldAggRel, oldCall, true, true, newCalls,
          aggCallMapping, inputExprs);
    case STDDEV_SAMP:
      // replace original STDDEV_POP(x) with
      //   SQRT(
      //     (SUM(x * x) - SUM(x) * SUM(x) / COUNT(x))
      //     / CASE COUNT(x) WHEN 1 THEN NULL ELSE COUNT(x) - 1 END)
      return reduceStddev(oldAggRel, oldCall, false, true, newCalls,
          aggCallMapping, inputExprs);
    case VAR_POP:
      // replace original VAR_POP(x) with
      //     (SUM(x * x) - SUM(x) * SUM(x) / COUNT(x))
      //     / COUNT(x)
      return reduceStddev(oldAggRel, oldCall, true, false, newCalls,
          aggCallMapping, inputExprs);
    case VAR_SAMP:
      // replace original VAR_POP(x) with
      //     (SUM(x * x) - SUM(x) * SUM(x) / COUNT(x))
      //     / CASE COUNT(x) WHEN 1 THEN NULL ELSE COUNT(x) - 1 END
      return reduceStddev(oldAggRel, oldCall, false, false, newCalls,
          aggCallMapping, inputExprs);
    default:
      throw Util.unexpected(kind);
    }
  } else {
    // anything else:  preserve original call
    RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder();
    final int nGroups = oldAggRel.getGroupCount();
    List<RelDataType> oldArgTypes =
        SqlTypeUtil.projectTypes(
            oldAggRel.getInput().getRowType(), oldCall.getArgList());
    return rexBuilder.addAggCall(oldCall,
        nGroups,
        oldAggRel.indicator,
        newCalls,
        aggCallMapping,
        oldArgTypes);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:61,代码来源:AggregateReduceFunctionsRule.java

示例10: reduceAvg

import org.apache.calcite.rel.core.Aggregate; //导入方法依赖的package包/类
private RexNode reduceAvg(
    Aggregate oldAggRel,
    AggregateCall oldCall,
    List<AggregateCall> newCalls,
    Map<AggregateCall, RexNode> aggCallMapping,
    List<RexNode> inputExprs) {
  final int nGroups = oldAggRel.getGroupCount();
  final RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder();
  final int iAvgInput = oldCall.getArgList().get(0);
  final RelDataType avgInputType =
      getFieldType(
          oldAggRel.getInput(),
          iAvgInput);
  final AggregateCall sumCall =
      AggregateCall.create(SqlStdOperatorTable.SUM,
          oldCall.isDistinct(),
          oldCall.isApproximate(),
          oldCall.getArgList(),
          oldCall.filterArg,
          oldAggRel.getGroupCount(),
          oldAggRel.getInput(),
          null,
          null);
  final AggregateCall countCall =
      AggregateCall.create(SqlStdOperatorTable.COUNT,
          oldCall.isDistinct(),
          oldCall.isApproximate(),
          oldCall.getArgList(),
          oldCall.filterArg,
          oldAggRel.getGroupCount(),
          oldAggRel.getInput(),
          null,
          null);

  // NOTE:  these references are with respect to the output
  // of newAggRel
  RexNode numeratorRef =
      rexBuilder.addAggCall(sumCall,
          nGroups,
          oldAggRel.indicator,
          newCalls,
          aggCallMapping,
          ImmutableList.of(avgInputType));
  final RexNode denominatorRef =
      rexBuilder.addAggCall(countCall,
          nGroups,
          oldAggRel.indicator,
          newCalls,
          aggCallMapping,
          ImmutableList.of(avgInputType));

  final RelDataTypeFactory typeFactory = oldAggRel.getCluster().getTypeFactory();
  final RelDataType avgType = typeFactory.createTypeWithNullability(
      oldCall.getType(), numeratorRef.getType().isNullable());
  numeratorRef = rexBuilder.ensureType(avgType, numeratorRef, true);
  final RexNode divideRef =
      rexBuilder.makeCall(SqlStdOperatorTable.DIVIDE, numeratorRef, denominatorRef);
  return rexBuilder.makeCast(oldCall.getType(), divideRef);
}
 
开发者ID:apache,项目名称:calcite,代码行数:60,代码来源:AggregateReduceFunctionsRule.java

示例11: reduceSum

import org.apache.calcite.rel.core.Aggregate; //导入方法依赖的package包/类
private RexNode reduceSum(
    Aggregate oldAggRel,
    AggregateCall oldCall,
    List<AggregateCall> newCalls,
    Map<AggregateCall, RexNode> aggCallMapping) {
  final int nGroups = oldAggRel.getGroupCount();
  RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder();
  int arg = oldCall.getArgList().get(0);
  RelDataType argType =
      getFieldType(
          oldAggRel.getInput(),
          arg);
  final AggregateCall sumZeroCall =
      AggregateCall.create(SqlStdOperatorTable.SUM0, oldCall.isDistinct(),
          oldCall.isApproximate(), oldCall.getArgList(), oldCall.filterArg,
          oldAggRel.getGroupCount(), oldAggRel.getInput(), null,
          oldCall.name);
  final AggregateCall countCall =
      AggregateCall.create(SqlStdOperatorTable.COUNT,
          oldCall.isDistinct(),
          oldCall.isApproximate(),
          oldCall.getArgList(),
          oldCall.filterArg,
          oldAggRel.getGroupCount(),
          oldAggRel,
          null,
          null);

  // NOTE:  these references are with respect to the output
  // of newAggRel
  RexNode sumZeroRef =
      rexBuilder.addAggCall(sumZeroCall,
          nGroups,
          oldAggRel.indicator,
          newCalls,
          aggCallMapping,
          ImmutableList.of(argType));
  if (!oldCall.getType().isNullable()) {
    // If SUM(x) is not nullable, the validator must have determined that
    // nulls are impossible (because the group is never empty and x is never
    // null). Therefore we translate to SUM0(x).
    return sumZeroRef;
  }
  RexNode countRef =
      rexBuilder.addAggCall(countCall,
          nGroups,
          oldAggRel.indicator,
          newCalls,
          aggCallMapping,
          ImmutableList.of(argType));
  return rexBuilder.makeCall(SqlStdOperatorTable.CASE,
      rexBuilder.makeCall(SqlStdOperatorTable.EQUALS,
          countRef, rexBuilder.makeExactLiteral(BigDecimal.ZERO)),
      rexBuilder.makeCast(sumZeroRef.getType(), rexBuilder.constantNull()),
      sumZeroRef);
}
 
开发者ID:apache,项目名称:calcite,代码行数:57,代码来源:AggregateReduceFunctionsRule.java


注:本文中的org.apache.calcite.rel.core.Aggregate.getGroupCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。