public static AggregateCall createSingleArgAggCall(String funcName, RelOptCluster cluster, PrimitiveTypeInfo typeInfo, Integer pos, RelDataType aggFnRetType) { ImmutableList.Builder<RelDataType> aggArgRelDTBldr = new ImmutableList.Builder<RelDataType>(); aggArgRelDTBldr.add(TypeConverter.convert(typeInfo, cluster.getTypeFactory())); SqlAggFunction aggFunction = SqlFunctionConverter.getCalciteAggFn(funcName, false, aggArgRelDTBldr.build(), aggFnRetType); List<Integer> argList = new ArrayList<Integer>(); argList.add(pos); return AggregateCall.create(aggFunction, false, argList, -1, aggFnRetType, null); }
@Override 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( new HiveSqlSumEmptyIsZeroAggFunction(isDistinct, returnTypeInference, operandTypeInference, operandTypeChecker), false, ImmutableList.of(ordinal), -1, aggregateCall.type, aggregateCall.name); } }
/** * Creates a LogicalAggregate that removes all duplicates from the result of * an underlying relational expression. * * @param rel underlying rel * @return rel implementing SingleValueAgg */ public static RelNode createSingleValueAggRel( RelOptCluster cluster, RelNode rel, RelFactories.AggregateFactory aggregateFactory) { // assert (rel.getRowType().getFieldCount() == 1); final int aggCallCnt = rel.getRowType().getFieldCount(); final List<AggregateCall> aggCalls = new ArrayList<>(); for (int i = 0; i < aggCallCnt; i++) { aggCalls.add( AggregateCall.create( SqlStdOperatorTable.SINGLE_VALUE, false, false, ImmutableList.of(i), -1, 0, rel, null, null)); } return aggregateFactory.createAggregate(rel, false, ImmutableBitSet.of(), null, aggCalls); }
AggregateCall aggCall = AggregateCall.create(HiveGroupingID.INSTANCE, false, new ImmutableList.Builder<Integer>().build(), -1, this.cluster.getTypeFactory() .createSqlType(SqlTypeName.BIGINT), HiveGroupingID.INSTANCE.getName());
@Override public AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e) { return AggregateCall.create( new HiveSqlCountAggFunction(isDistinct, returnTypeInference, operandTypeInference, operandTypeChecker), false, ImmutableIntList.of(), -1, typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), true), "count"); }
return AggregateCall.create(new HiveSqlSumAggFunction(isDistinct, returnTypeInference, operandTypeInference, operandTypeChecker), false, ImmutableList.of(ordinal), -1, aggregateCall.type, aggregateCall.name);
@Override public AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e) { return AggregateCall.create( new HiveSqlCountAggFunction(isDistinct, returnTypeInference, operandTypeInference, operandTypeChecker), false, ImmutableIntList.of(), -1, typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), true), "count"); } }
AggregateCall aggCall = AggregateCall.create(HiveGroupingID.INSTANCE, false, new ImmutableList.Builder<Integer>().build(), -1, this.cluster.getTypeFactory().createSqlType(SqlTypeName.BIGINT),
AggregateCall aggCall = AggregateCall.create(HiveGroupingID.INSTANCE, false, new ImmutableList.Builder<Integer>().build(), -1, this.cluster.getTypeFactory() .createSqlType(SqlTypeName.INTEGER), HiveGroupingID.INSTANCE.getName());
@Override public AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e) { RelDataType countRetType = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), true); return AggregateCall.create( new HiveSqlCountAggFunction(isDistinct, ReturnTypes.explicit(countRetType), operandTypeInference, operandTypeChecker), false, ImmutableIntList.of(), -1, countRetType, "count"); }
return AggregateCall.create(new HiveSqlSumAggFunction(isDistinct, returnTypeInference, operandTypeInference, operandTypeChecker), false, ImmutableList.of(ordinal), -1, aggregateCall.type, aggregateCall.name);
@Override public AggregateCall other(RelDataTypeFactory typeFactory, AggregateCall e) { RelDataType countRetType = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), true); return AggregateCall.create( new HiveSqlCountAggFunction(isDistinct, ReturnTypes.explicit(countRetType), operandTypeInference, operandTypeChecker), false, ImmutableIntList.of(), -1, countRetType, "count"); }
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); }
: registerExpression(extraNodes, aggCall1.filter); aggregateCall = AggregateCall.create(aggCall1.aggFunction, aggCall1.distinct, args, filterArg, groupSet.cardinality(), r, null, aggCall1.alias); } else {
newProjects.add(arg1); newProjects.add(filter); newCall = AggregateCall.create( SqlStdOperatorTable.COUNT, true, newCall = AggregateCall.create( SqlStdOperatorTable.COUNT, false, newCall = AggregateCall.create( SqlStdOperatorTable.COUNT, false, newProjects.add(arg1); newProjects.add(filter); newCall = AggregateCall.create( aggregateCall.getAggregation(), false,
AggregateCall newAggCall = AggregateCall.create(SqlStdOperatorTable.SUM, false, aggCall.getArgList(), -1, aggCall.getType(), aggCall.getName()); this.hackAggCalls.put(i, newAggCall);
: registerExpression(extraNodes, aggCall1.filter); aggregateCall = AggregateCall.create(aggCall1.aggFunction, aggCall1.distinct, args, filterArg, groupSet.cardinality(), r, null, aggCall1.alias); } else {
AggregateCall.create(getRollup(aggregateCall.getAggregation()), aggregateCall.isDistinct(), ImmutableList.of(target.groupSet.cardinality() + i), -1,
rexBuilder.getTypeFactory(), avgInputType, oldCall.getType()); final AggregateCall sumCall = AggregateCall.create( new HiveSqlSumAggFunction( oldCall.isDistinct(), typeFactory.createSqlType(SqlTypeName.BIGINT), true); final AggregateCall countCall = AggregateCall.create( new HiveSqlCountAggFunction( oldCall.isDistinct(),
rexBuilder.getTypeFactory(), sum0InputType, oldCall.getType()); final AggregateCall sumCall = AggregateCall.create( new HiveSqlSumAggFunction( oldCall.isDistinct(),