private static boolean isOneArgAggregateCall(final AggregateCall aggregateCall) { return aggregateCall.getArgList().size() == 1; }
@Nullable public static List<DruidExpression> getArgumentsForSimpleAggregator( final PlannerContext plannerContext, final RowSignature rowSignature, final AggregateCall call, final Project project ) { return call.getArgList().stream() .map(i -> Expressions.fromFieldAccess(rowSignature, project, i)) .map(rexNode -> toDruidExpressionForSimpleAggregator(plannerContext, rowSignature, rexNode)) .collect(Collectors.toList()); }
public KylinAggregateCall(AggregateCall aggCall, FunctionDesc func) { super(aggCall.getAggregation(), aggCall.isDistinct(), aggCall.getArgList(), aggCall.type, aggCall.name); this.func = func; }
continue; if (!aggCall.getArgList().equals(argList)) { continue; final int argCount = aggCall.getArgList().size(); final List<Integer> newArgs = new ArrayList<Integer>(argCount); for (int j = 0; j < argCount; j++) { final Integer arg = aggCall.getArgList().get(j); newArgs.add(sourceOf.get(arg));
continue; if (!aggCall.getArgList().equals(argList)) { continue; final int argCount = aggCall.getArgList().size(); final List<Integer> newArgs = new ArrayList<Integer>(argCount); for (int j = 0; j < argCount; j++) { final Integer arg = aggCall.getArgList().get(j); newArgs.add(sourceOf.get(arg));
@Override public boolean matches(final RelOptRuleCall call) { final Aggregate aggregate = call.rel(0); final Project project = call.rel(1); if (aggregate.indicator || aggregate.getGroupSets().size() != 1) { return false; } for (AggregateCall aggregateCall : aggregate.getAggCallList()) { if (isOneArgAggregateCall(aggregateCall) && isThreeArgCase(project.getChildExps().get(Iterables.getOnlyElement(aggregateCall.getArgList())))) { return true; } } return false; }
SQLCall toSqlCall(AggregateCall aggCall) { ColumnRowType inputColumnRowType = ((OLAPRel) getInput()).getColumnRowType(); String function = getSqlFuncName(aggCall); List<Object> args = Lists.newArrayList(); for (Integer index : aggCall.getArgList()) { TblColRef col = inputColumnRowType.getColumnByIndexNullable(index); args.add(col); } return new SQLCall(function, args); }
public AggregateCall apply(AggregateCall call) { return call.copy(Mappings.apply2(mapping, call.getArgList()), Mappings.apply(mapping, call.filterArg)); } });
} else { AggregateCall aggCall = this.rewriteAggCalls.get(i); int index = aggCall.getArgList().get(0); aggOutName = getSqlFuncName(aggCall) + "_" + inputColumnRowType.getColumnByIndex(index).getIdentity().replace('.', '_') + "_";
void buildRewriteFieldsAndMetricsColumns() { ColumnRowType inputColumnRowType = ((OLAPRel) getInput()).getColumnRowType(); RelDataTypeFactory typeFactory = getCluster().getTypeFactory(); for (int i = 0; i < this.aggregations.size(); i++) { FunctionDesc aggFunc = this.aggregations.get(i); if (aggFunc.isDimensionAsMetric()) { addToContextGroupBy(aggFunc.getParameter().getColRefs()); continue; // skip rewrite, let calcite handle } if (aggFunc.needRewriteField()) { String rewriteFieldName = aggFunc.getRewriteFieldName(); RelDataType rewriteFieldType = OLAPTable.createSqlType(typeFactory, aggFunc.getRewriteFieldType(), true); this.context.rewriteFields.put(rewriteFieldName, rewriteFieldType); TblColRef column = buildRewriteColumn(aggFunc); this.context.metricsColumns.add(column); } AggregateCall aggCall = this.rewriteAggCalls.get(i); if (!aggCall.getArgList().isEmpty()) { for (Integer index : aggCall.getArgList()) { TblColRef column = inputColumnRowType.getColumnByIndex(index); if (!column.isInnerColumn() && this.context.belongToContextTables(column)) { this.context.metricsColumns.add(column); } } } } }
List<Integer> newArgList = Lists.newArrayList(aggCall.getArgList()); if (udafMap != null && udafMap.containsKey(callName)) { newArgList = truncArgList(newArgList, udafMap.get(callName));
for (AggregateCall aggrCall : aggr.getAggCallList()) { final ImmutableList.Builder<Integer> newArgs = ImmutableList.builder(); for (int key : aggrCall.getArgList()) { mappingKeys(key, projects.get(key), newProjects, mapping); newArgs.add(mapping.get(key));
@Override public boolean matches(RelOptRuleCall call) { final HiveAggregate agg = call.rel(0); final HiveJdbcConverter converter = call.rel(1); for (AggregateCall relOptRuleOperand : agg.getAggCallList()) { SqlAggFunction f = relOptRuleOperand.getAggregation(); if (f instanceof HiveSqlCountAggFunction) { //count distinct with more that one argument is not supported HiveSqlCountAggFunction countAgg = (HiveSqlCountAggFunction)f; if (countAgg.isDistinct() && 1 < relOptRuleOperand.getArgList().size()) { return false; } } SqlKind kind = f.getKind(); if (!converter.getJdbcDialect().supportsAggregateFunction(kind)) { return false; } } return true; }
final RexNode rexNode = project.getChildExps().get(Iterables.getOnlyElement(aggregateCall.getArgList()));
rowSignature, project, Iterables.getOnlyElement(aggregateCall.getArgList()) );
rowSignature, project, Iterables.getOnlyElement(aggregateCall.getArgList()) );
@Override public void onMatch(RelOptRuleCall call) { final Aggregate topAggregate = call.rel(0); final Join join = call.rel(1); final RelNode left = call.rel(2); final Aggregate aggregate = call.rel(3); // Gather columns used by aggregate operator final ImmutableBitSet.Builder topRefs = ImmutableBitSet.builder(); topRefs.addAll(topAggregate.getGroupSet()); for (AggregateCall aggCall : topAggregate.getAggCallList()) { topRefs.addAll(aggCall.getArgList()); if (aggCall.filterArg != -1) { topRefs.set(aggCall.filterArg); } } perform(call, topRefs.build(), topAggregate, join, left, aggregate); } }
Schema(Schema src, Aggregate gBy) { for (int i : gBy.getGroupSet()) { ColumnInfo cI = src.get(i); add(cI); } List<AggregateCall> aggs = gBy.getAggCallList(); for (AggregateCall agg : aggs) { if (agg.getAggregation() == HiveGroupingID.INSTANCE) { add(new ColumnInfo(null,VirtualColumn.GROUPINGID.getName())); continue; } int argCount = agg.getArgList().size(); ASTBuilder b = agg.isDistinct() ? ASTBuilder.construct(HiveParser.TOK_FUNCTIONDI, "TOK_FUNCTIONDI") : argCount == 0 ? ASTBuilder.construct(HiveParser.TOK_FUNCTIONSTAR, "TOK_FUNCTIONSTAR") : ASTBuilder.construct(HiveParser.TOK_FUNCTION, "TOK_FUNCTION"); b.add(HiveParser.Identifier, agg.getAggregation().getName()); for (int i : agg.getArgList()) { RexInputRef iRef = new RexInputRef(i, gBy.getCluster().getTypeFactory() .createSqlType(SqlTypeName.ANY)); b.add(iRef.accept(new RexVisitor(src, false, gBy.getCluster().getRexBuilder()))); } add(new ColumnInfo(null, b.node())); } }
final RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder(); final RelDataTypeFactory typeFactory = oldAggRel.getCluster().getTypeFactory(); final int iAvgInput = oldCall.getArgList().get(0); final RelDataType sum0InputType = typeFactory.createTypeWithNullability( getFieldType(oldAggRel.getInput(), iAvgInput), true); oldCall.getArgList(), oldCall.filterArg, oldAggRel.getGroupCount(),
continue; int argCount = agg.getArgList().size(); ASTBuilder b = agg.isDistinct() ? ASTBuilder.construct(HiveParser.TOK_FUNCTIONDI, "TOK_FUNCTIONDI") : argCount == 0 ? ASTBuilder.construct(HiveParser.TOK_FUNCTIONSTAR, "TOK_FUNCTIONSTAR") : ASTBuilder.construct(HiveParser.TOK_FUNCTION, "TOK_FUNCTION"); b.add(HiveParser.Identifier, agg.getAggregation().getName()); for (int i : agg.getArgList()) { RexInputRef iRef = new RexInputRef(i, gBy.getCluster().getTypeFactory() .createSqlType(SqlTypeName.ANY));