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); }
final AggregateCall newCall = AggregateCall.create(aggCall.getAggregation(), false, aggCall.isApproximate(), aggCall.getArgList(), -1, ImmutableBitSet.of(bottomGroupSet).cardinality(), relBuilder.peek(), null, aggCall.name); AggregateCall.create(aggCall.getAggregation(), false, aggCall.isApproximate(), newArgList, -1, newCall = AggregateCall.create(new SqlSumEmptyIsZeroAggFunction(), false, aggCall.isApproximate(), newArgs, -1, originalGroupSet.cardinality(), relBuilder.peek(), aggCall.getType(), aggCall.getName()); newCall = AggregateCall.create(aggCall.getAggregation(), false, aggCall.isApproximate(), newArgs, -1, originalGroupSet.cardinality(), relBuilder.peek(), aggCall.getType(), aggCall.name);
oldCall.isApproximate(), oldCall.getArgList(), oldCall.filterArg, oldCall.isApproximate(), oldCall.getArgList(), oldCall.filterArg,
oldCall.isApproximate(), oldCall.getArgList(), oldCall.filterArg,
oldCall.isApproximate(), ImmutableIntList.of(argRefOrdinal), oldCall.filterArg, oldCall.isApproximate(), oldCall.getArgList(), oldCall.filterArg,
RelBuilder.AggCall newAggCall = relBuilder.aggregateCall(aggCall.getAggregation(), aggCall.isDistinct(), aggCall.isApproximate(), filterArg, aggCall.name, args); mapping.set(j, updatedGroupCount + newAggCallList.size());
/** * Most of the aggregations can be retrieved with single * <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html">stats</a> * function. But currently only one-to-one mapping is supported between sql agg and elastic * aggregation. */ private String toElasticAggregate(AggregateCall call) { SqlKind kind = call.getAggregation().getKind(); switch (kind) { case COUNT: return call.isApproximate() ? "cardinality" : "value_count"; case SUM: return "sum"; case MIN: return "min"; case MAX: return "max"; case AVG: return "avg"; case ANY_VALUE: return "terms"; default: throw new IllegalArgumentException("Unknown aggregation kind " + kind + " for " + call); } }
aggCall.isApproximate(), newArgs, -1, aggCall.getType(), aggCall.getName()); newAggCalls.set(i, newAggCall);
aggCall.isApproximate(), newArgs, -1, aggCall.getType(), aggCall.getName()); newAggCalls.set(i, newAggCall);
aggCall.isApproximate(), newArgs, -1, aggCall.collation, aggCall.getType(), aggCall.getName()); newAggCalls.set(i, newAggCall);
@Override public Prel prepareForLateralUnnestPipeline(List<RelNode> children) { List<Integer> groupingCols = Lists.newArrayList(); groupingCols.add(0); for (int groupingCol : groupSet.asList()) { groupingCols.add(groupingCol + 1); } ImmutableBitSet groupingSet = ImmutableBitSet.of(groupingCols); List<ImmutableBitSet> groupingSets = Lists.newArrayList(); groupingSets.add(groupingSet); List<AggregateCall> aggregateCalls = Lists.newArrayList(); for (AggregateCall aggCall : aggCalls) { List<Integer> arglist = Lists.newArrayList(); for (int arg : aggCall.getArgList()) { arglist.add(arg + 1); } aggregateCalls.add(AggregateCall.create(aggCall.getAggregation(), aggCall.isDistinct(), aggCall.isApproximate(), arglist, aggCall.filterArg, aggCall.type, aggCall.name)); } return (Prel) copy(traitSet, children.get(0),indicator,groupingSet,groupingSets, aggregateCalls); } }
origCall.isApproximate(), ImmutableList.of(groupCount + ord.i), -1, origCall.collation,
origCall.isApproximate(), ImmutableList.of(groupCount + ord.i), -1, groupCount, input, aggType, origCall.getName());
private AggregateCall createAggregateCallWithBinding( RelDataTypeFactory typeFactory, SqlAggFunction aggFunction, RelDataType operandType, Aggregate oldAggRel, AggregateCall oldCall, int argOrdinal, int filter) { final Aggregate.AggCallBinding binding = new Aggregate.AggCallBinding(typeFactory, aggFunction, ImmutableList.of(operandType), oldAggRel.getGroupCount(), filter >= 0); return AggregateCall.create(aggFunction, oldCall.isDistinct(), oldCall.isApproximate(), ImmutableIntList.of(argOrdinal), filter, oldCall.collation, aggFunction.inferReturnType(binding), null); }
private AggregateCall createAggregateCallWithBinding( RelDataTypeFactory typeFactory, SqlAggFunction aggFunction, RelDataType operandType, Aggregate oldAggRel, AggregateCall oldCall, int argOrdinal, int filter) { final Aggregate.AggCallBinding binding = new Aggregate.AggCallBinding(typeFactory, aggFunction, ImmutableList.of(operandType), oldAggRel.getGroupCount(), filter >= 0); return AggregateCall.create(aggFunction, oldCall.isDistinct(), oldCall.isApproximate(), ImmutableIntList.of(argOrdinal), filter, aggFunction.inferReturnType(binding), null); }
aggregateCall.isApproximate(), ImmutableList.of(offset + i), -1, groupCount, relBuilder.peek(), null, aggregateCall.name); aggregateCall.isApproximate(), newArgs, -1, groupCount, relBuilder.peek(), null, aggregateCall.name);
private RexNode getSumAggregatedRexNode(Aggregate oldAggRel, AggregateCall oldCall, List<AggregateCall> newCalls, Map<AggregateCall, RexNode> aggCallMapping, RexBuilder rexBuilder, int argOrdinal, int filterArg) { final AggregateCall aggregateCall = AggregateCall.create(SqlStdOperatorTable.SUM, oldCall.isDistinct(), oldCall.isApproximate(), ImmutableIntList.of(argOrdinal), filterArg, oldCall.collation, oldAggRel.getGroupCount(), oldAggRel.getInput(), null, null); return rexBuilder.addAggCall(aggregateCall, oldAggRel.getGroupCount(), oldAggRel.indicator, newCalls, aggCallMapping, ImmutableList.of(aggregateCall.getType())); }
private RexNode getSumAggregatedRexNode(Aggregate oldAggRel, AggregateCall oldCall, List<AggregateCall> newCalls, Map<AggregateCall, RexNode> aggCallMapping, RexBuilder rexBuilder, int argOrdinal, int filterArg) { final AggregateCall aggregateCall = AggregateCall.create(SqlStdOperatorTable.SUM, oldCall.isDistinct(), oldCall.isApproximate(), ImmutableIntList.of(argOrdinal), filterArg, oldAggRel.getGroupCount(), oldAggRel.getInput(), null, null); return rexBuilder.addAggCall(aggregateCall, oldAggRel.getGroupCount(), oldAggRel.indicator, newCalls, aggCallMapping, ImmutableList.of(aggregateCall.getType())); }
private RexNode getRegrCountRexNode(Aggregate oldAggRel, AggregateCall oldCall, List<AggregateCall> newCalls, Map<AggregateCall, RexNode> aggCallMapping, ImmutableIntList argOrdinals, ImmutableList<RelDataType> operandTypes, int filterArg) { final AggregateCall countArgAggCall = AggregateCall.create(SqlStdOperatorTable.REGR_COUNT, oldCall.isDistinct(), oldCall.isApproximate(), argOrdinals, filterArg, oldCall.collation, oldAggRel.getGroupCount(), oldAggRel, null, null); return oldAggRel.getCluster().getRexBuilder().addAggCall(countArgAggCall, oldAggRel.getGroupCount(), oldAggRel.indicator, newCalls, aggCallMapping, operandTypes); }
private RexNode getRegrCountRexNode(Aggregate oldAggRel, AggregateCall oldCall, List<AggregateCall> newCalls, Map<AggregateCall, RexNode> aggCallMapping, ImmutableIntList argOrdinals, ImmutableList<RelDataType> operandTypes, int filterArg) { final AggregateCall countArgAggCall = AggregateCall.create(SqlStdOperatorTable.REGR_COUNT, oldCall.isDistinct(), oldCall.isApproximate(), argOrdinals, filterArg, oldAggRel.getGroupCount(), oldAggRel, null, null); return oldAggRel.getCluster().getRexBuilder().addAggCall(countArgAggCall, oldAggRel.getGroupCount(), oldAggRel.indicator, newCalls, aggCallMapping, operandTypes); }