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


Java AggregateCall.create方法代码示例

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


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

示例1: visit

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
@Override
public RelNode visit(LogicalAggregate aggregate) {
  RelNode input = aggregate.getInput().accept(this);
  RelDataType incomingRowType = input.getRowType();
  RelDataTypeField modField = incomingRowType.getField(UPDATE_COLUMN, false, false);
  if (modField == null) {
    return aggregate;
  }

  final AggregateCall aggCall = AggregateCall.create(SqlStdOperatorTable.MAX, false, ImmutableList.of(modField.getIndex()), -1, modField.getType(), UPDATE_COLUMN);
  final List<AggregateCall> aggCalls = FluentIterable.from(aggregate.getAggCallList())
    .append(aggCall)
    .toList();
  return aggregate.copy(
    aggregate.getTraitSet(),
    input,
    aggregate.indicator,
    aggregate.getGroupSet(),
    null,
    aggCalls
  );
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:IncrementalUpdateUtils.java

示例2: convertAggCallList

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
protected List<AggregateCall> convertAggCallList(AggregateRel aggregate, List<AggregateCall> aggCalls) {
  List<AggregateCall> convertedCalls = new ArrayList<>();
  for (Ord<AggregateCall> aggCall : Ord.zip(aggCalls)) {
    AggregateCall newCall;
    if ("NDV".equals(aggCall.e.getAggregation().getName())) {
      newCall = AggregateCall.create(
        new SqlHllAggFunction(),
        aggCall.e.isDistinct(),
        aggCall.e.getArgList(),
        -1,
        aggregate.getCluster().getTypeFactory().createSqlType(SqlTypeName.BINARY),
        aggCall.e.getName());
    } else {
      newCall = aggCall.e;
    }
    convertedCalls.add(newCall);
  }
  return convertedCalls;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:20,代码来源:AggPruleBase.java

示例3: createAggregateCallWithBinding

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的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

示例4: copyOf

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private AggregateCall copyOf(AggregateCall call) {
  return AggregateCall.create(
    call.getAggregation(), // doesn't look we need to copy this
    call.isDistinct(),
    call.getArgList(),
    call.filterArg,
    copyOf(call.getType()),
    call.getName());
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:10,代码来源:CopyWithCluster.java

示例5: rewriteAggCalls

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private static void rewriteAggCalls(
		List<AggregateCall> newAggCalls,
		List<Integer> argList,
		Map<Integer, Integer> sourceOf) {
	// Rewrite the agg calls. Each distinct agg becomes a non-distinct call
	// to the corresponding field from the right; for example,
	// "COUNT(DISTINCT e.sal)" becomes   "COUNT(distinct_e.sal)".
	for (int i = 0; i < newAggCalls.size(); i++) {
		final AggregateCall aggCall = newAggCalls.get(i);

		// Ignore agg calls which are not distinct or have the wrong set
		// arguments. If we're rewriting aggregates whose args are {sal}, we will
		// rewrite COUNT(DISTINCT sal) and SUM(DISTINCT sal) but ignore
		// COUNT(DISTINCT gender) or SUM(sal).
		if (!aggCall.isDistinct()) {
			continue;
		}
		if (!aggCall.getArgList().equals(argList)) {
			continue;
		}

		// Re-map arguments.
		final int argCount = aggCall.getArgList().size();
		final List<Integer> newArgs = new ArrayList<>(argCount);
		for (int j = 0; j < argCount; j++) {
			final Integer arg = aggCall.getArgList().get(j);
			newArgs.add(sourceOf.get(arg));
		}
		final AggregateCall newAggCall =
				AggregateCall.create(aggCall.getAggregation(), false, newArgs, -1,
						aggCall.getType(), aggCall.getName());
		newAggCalls.set(i, newAggCall);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:35,代码来源:FlinkAggregateExpandDistinctAggregatesRule.java

示例6: toAggCall

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private AggregateCall toAggCall(Map<String, Object> jsonAggCall) {
  final String aggName = (String) jsonAggCall.get("agg");
  final SqlAggFunction aggregation =
      relJson.toAggregation(aggName, jsonAggCall);
  final Boolean distinct = (Boolean) jsonAggCall.get("distinct");
  @SuppressWarnings("unchecked")
  final List<Integer> operands = (List<Integer>) jsonAggCall.get("operands");
  final Integer filterOperand = (Integer) jsonAggCall.get("filter");
  final RelDataType type =
      relJson.toType(cluster.getTypeFactory(), jsonAggCall.get("type"));
  return AggregateCall.create(aggregation, distinct, false, operands,
      filterOperand == null ? -1 : filterOperand, type, null);
}
 
开发者ID:apache,项目名称:calcite,代码行数:14,代码来源:RelJsonReader.java

示例7: rewriteAggCalls

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private static void rewriteAggCalls(
    List<AggregateCall> newAggCalls,
    List<Integer> argList,
    Map<Integer, Integer> sourceOf) {
  // Rewrite the agg calls. Each distinct agg becomes a non-distinct call
  // to the corresponding field from the right; for example,
  // "COUNT(DISTINCT e.sal)" becomes   "COUNT(distinct_e.sal)".
  for (int i = 0; i < newAggCalls.size(); i++) {
    final AggregateCall aggCall = newAggCalls.get(i);

    // Ignore agg calls which are not distinct or have the wrong set
    // arguments. If we're rewriting aggregates whose args are {sal}, we will
    // rewrite COUNT(DISTINCT sal) and SUM(DISTINCT sal) but ignore
    // COUNT(DISTINCT gender) or SUM(sal).
    if (!aggCall.isDistinct()) {
      continue;
    }
    if (!aggCall.getArgList().equals(argList)) {
      continue;
    }

    // Re-map arguments.
    final int argCount = aggCall.getArgList().size();
    final List<Integer> newArgs = new ArrayList<>(argCount);
    for (int j = 0; j < argCount; j++) {
      final Integer arg = aggCall.getArgList().get(j);
      newArgs.add(sourceOf.get(arg));
    }
    final AggregateCall newAggCall =
        AggregateCall.create(aggCall.getAggregation(), false,
            aggCall.isApproximate(), newArgs, -1,
            aggCall.getType(), aggCall.getName());
    newAggCalls.set(i, newAggCall);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:36,代码来源:AggregateExpandDistinctAggregatesRule.java

示例8: transformAggCalls

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private List<AggregateCall> transformAggCalls(RelNode input, int groupCount,
    List<AggregateCall> origCalls) {
  final List<AggregateCall> newCalls = Lists.newArrayList();
  for (Ord<AggregateCall> ord : Ord.zip(origCalls)) {
    final AggregateCall origCall = ord.e;
    if (origCall.isDistinct()
        || !SUPPORTED_AGGREGATES.containsKey(origCall.getAggregation()
            .getClass())) {
      return null;
    }
    final SqlAggFunction aggFun;
    final RelDataType aggType;
    if (origCall.getAggregation() == SqlStdOperatorTable.COUNT) {
      aggFun = SqlStdOperatorTable.SUM0;
      // count(any) is always not null, however nullability of sum might
      // depend on the number of columns in GROUP BY.
      // Here we use SUM0 since we are sure we will not face nullable
      // inputs nor we'll face empty set.
      aggType = null;
    } else {
      aggFun = origCall.getAggregation();
      aggType = origCall.getType();
    }
    AggregateCall newCall =
        AggregateCall.create(aggFun, origCall.isDistinct(),
            origCall.isApproximate(),
            ImmutableList.of(groupCount + ord.i), -1, groupCount, input,
            aggType, origCall.getName());
    newCalls.add(newCall);
  }
  return newCalls;
}
 
开发者ID:apache,项目名称:calcite,代码行数:33,代码来源:AggregateUnionTransposeRule.java

示例9: topSplit

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
public AggregateCall topSplit(RexBuilder rexBuilder,
    Registry<RexNode> extra, int offset, RelDataType inputRowType,
    AggregateCall aggregateCall, int leftSubTotal, int rightSubTotal) {
  final List<RexNode> merges = new ArrayList<>();
  if (leftSubTotal >= 0) {
    merges.add(
        rexBuilder.makeInputRef(aggregateCall.type, leftSubTotal));
  }
  if (rightSubTotal >= 0) {
    merges.add(
        rexBuilder.makeInputRef(aggregateCall.type, rightSubTotal));
  }
  RexNode node;
  switch (merges.size()) {
  case 1:
    node = merges.get(0);
    break;
  case 2:
    node = rexBuilder.makeCall(SqlStdOperatorTable.MULTIPLY, merges);
    break;
  default:
    throw new AssertionError("unexpected count " + merges);
  }
  int ordinal = extra.register(node);
  return AggregateCall.create(SqlStdOperatorTable.SUM0, false, false,
      ImmutableList.of(ordinal), -1, aggregateCall.type,
      aggregateCall.name);
}
 
开发者ID:apache,项目名称:calcite,代码行数:29,代码来源:SqlSplittableAggFunction.java

示例10: onMatch

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
  final DrillAggregateRel oldAggRel = (DrillAggregateRel) call.rels[0];

  final Map<AggregateCall, RexNode> aggCallMapping = Maps.newHashMap();
  final List<AggregateCall> newAggregateCalls = Lists.newArrayList();
  for (AggregateCall oldAggregateCall : oldAggRel.getAggCallList()) {
    if(isConversionToSumZeroNeeded(oldAggregateCall.getAggregation(), oldAggregateCall.getType())) {
      final RelDataType argType = oldAggregateCall.getType();
      final RelDataType sumType = oldAggRel.getCluster().getTypeFactory()
          .createTypeWithNullability(argType, argType.isNullable());
      final SqlAggFunction sumZeroAgg = new DrillCalciteSqlAggFunctionWrapper(
          new SqlSumEmptyIsZeroAggFunction(), sumType);
      AggregateCall sumZeroCall =
          AggregateCall.create(
              sumZeroAgg,
              oldAggregateCall.isDistinct(),
              oldAggregateCall.getArgList(),
              -1,
              sumType,
              oldAggregateCall.getName());
      oldAggRel.getCluster().getRexBuilder()
          .addAggCall(sumZeroCall,
              oldAggRel.getGroupCount(),
              oldAggRel.indicator,
              newAggregateCalls,
              aggCallMapping,
              ImmutableList.of(argType));
    } else {
      newAggregateCalls.add(oldAggregateCall);
    }
  }

  try {
    call.transformTo(new DrillAggregateRel(
        oldAggRel.getCluster(),
        oldAggRel.getTraitSet(),
        oldAggRel.getInput(),
        oldAggRel.indicator,
        oldAggRel.getGroupSet(),
        oldAggRel.getGroupSets(),
        newAggregateCalls));
  } catch (InvalidRelException e) {
    tracer.warning(e.toString());
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:47,代码来源:DrillReduceAggregatesRule.java

示例11: reduceAvg

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的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

示例12: reduceSum

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的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

示例13: rollUp

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private static AggregateCall rollUp(int groupCount, RelBuilder relBuilder,
    AggregateCall aggregateCall, TileKey tileKey) {
  if (aggregateCall.isDistinct()) {
    return null;
  }
  final SqlAggFunction aggregation = aggregateCall.getAggregation();
  final Pair<SqlAggFunction, List<Integer>> seek =
      Pair.of(aggregation, aggregateCall.getArgList());
  final int offset = tileKey.dimensions.cardinality();
  final ImmutableList<Lattice.Measure> measures = tileKey.measures;

  // First, try to satisfy the aggregation by rolling up an aggregate in the
  // materialization.
  final int i = find(measures, seek);
tryRoll:
  if (i >= 0) {
    final SqlAggFunction roll = SubstitutionVisitor.getRollup(aggregation);
    if (roll == null) {
      break tryRoll;
    }
    return AggregateCall.create(roll, false,
        aggregateCall.isApproximate(), ImmutableList.of(offset + i), -1,
        groupCount, relBuilder.peek(), null, aggregateCall.name);
  }

  // Second, try to satisfy the aggregation based on group set columns.
tryGroup:
  {
    List<Integer> newArgs = Lists.newArrayList();
    for (Integer arg : aggregateCall.getArgList()) {
      int z = tileKey.dimensions.indexOf(arg);
      if (z < 0) {
        break tryGroup;
      }
      newArgs.add(z);
    }
    return AggregateCall.create(aggregation, false,
        aggregateCall.isApproximate(), newArgs, -1,
        groupCount, relBuilder.peek(), null, aggregateCall.name);
  }

  // No roll up possible.
  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:45,代码来源:AggregateStarTableRule.java

示例14: other

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
public AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e) {
  return AggregateCall.create(SqlStdOperatorTable.COUNT, false, false,
      ImmutableIntList.of(), -1,
      typeFactory.createSqlType(SqlTypeName.BIGINT), null);
}
 
开发者ID:apache,项目名称:calcite,代码行数:6,代码来源:SqlSplittableAggFunction.java


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