Refine search
final RelBuilder relBuilder = call.builder(); final Aggregate aggRel = (Aggregate) call.rel(0); final RexBuilder rexBuilder = aggRel.getCluster().getRexBuilder(); final Map<AggregateCall, Integer> mapping = new HashMap<>(); final List<Integer> indexes = new ArrayList<>(); final List<AggregateCall> aggCalls = aggRel.getAggCallList(); final List<AggregateCall> newAggCalls = new ArrayList<>(aggCalls.size()); int nextIdx = aggRel.getGroupCount() + aggRel.getIndicatorCount(); for (int i = 0; i < aggCalls.size(); i++) { AggregateCall aggCall = aggCalls.get(i); if (aggCall.getAggregation().getKind() == SqlKind.COUNT && !aggCall.isDistinct()) { final List<Integer> args = aggCall.getArgList(); final List<Integer> nullableArgs = new ArrayList<>(args.size()); for (int arg : args) { if (aggRel.getInput().getRowType().getFieldList().get(arg).getType().isNullable()) { nullableArgs.add(arg); projList.add( rexBuilder.makeInputRef( aggRel.getRowType().getFieldList().get(i).getType(), i)); for (int i = offset; i < aggRel.getRowType().getFieldCount(); ++i) {
gbInfo.outputColNames.addAll(aggRel.getRowType().getFieldNames()); aggInputRel.getRowType(), new HashSet<Integer>(), aggRel.getCluster().getTypeFactory(), true); RexInputRef iRef = new RexInputRef(i, aggInputRel.getRowType().getFieldList() .get(i).getType()); tmpExprNodeDesc = iRef.accept(exprConv); gbInfo.gbKeys.add(tmpExprNodeDesc); gbInfo.gbKeyColNamesInInput.add(aggInputRel.getRowType().getFieldNames().get(i)); gbInfo.gbKeyTypes.add(tmpExprNodeDesc.getTypeInfo()); && (aggRel.getAggCallList().get(aggRel.getAggCallList().size() - 1).getAggregation() == HiveGroupingID.INSTANCE)) { gbInfo.grpIdFunctionNeeded = true; Map<Integer, Integer> distParamInRefsToOutputPos = new HashMap<Integer, Integer>(); for (AggregateCall aggCall : aggRel.getAggCallList()) { if ((aggCall.getAggregation() == HiveGroupingID.INSTANCE) || !aggCall.isDistinct()) { continue; inputOpAf.tabAlias); udafAttrs.udafParams.addAll(argExps); udafAttrs.udafName = aggCall.getAggregation().getName(); udafAttrs.argList = aggCall.getArgList(); udafAttrs.isDistinctUDAF = aggCall.isDistinct();
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); }
for (int fieldNumber : aggregate.getGroupSet()) { final RexNode rexNode = project.getChildExps().get(Iterables.getOnlyElement(aggregateCall.getArgList())); if (aggregateCall.isDistinct()) { if (aggregateCall.getAggregation().getKind() == SqlKind.COUNT && RexLiteral.isNullLiteral(arg2)) { newProjects.add(arg1); newProjects.add(filter); if (aggregateCall.getAggregation().getKind() == SqlKind.COUNT && arg1.isA(SqlKind.LITERAL) && !RexLiteral.isNullLiteral(arg1) aggregateCall.getName() ); } else if (aggregateCall.getAggregation().getKind() == SqlKind.SUM && Calcites.isIntLiteral(arg1) && RexLiteral.intValue(arg1) == 1 && Calcites.isIntLiteral(arg2) && RexLiteral.intValue(arg2) == 0) { ); } else if (RexLiteral.isNullLiteral(arg2) /* Case A1 */ || (aggregateCall.getAggregation().getKind() == SqlKind.SUM && Calcites.isIntLiteral(arg2) && RexLiteral.intValue(arg2) == 0) /* Case A2 */) {
for (AggregateCall aggregateCall : aggregate.getAggCallList()) { if (aggregateCall.getAggregation().unwrap(SqlSplittableAggFunction.class) == null) { return; if (!allowFunctions && !aggregate.getAggCallList().isEmpty()) { return; final SqlAggFunction aggregation = aggCall.e.getAggregation(); final SqlSplittableAggFunction splitter = Preconditions.checkNotNull( aggregation.unwrap(SqlSplittableAggFunction.class)); final AggregateCall call1; if (fieldSet.contains(ImmutableBitSet.of(aggCall.e.getArgList()))) { call1 = splitter.split(aggCall.e, mapping); } else { final SqlSplittableAggFunction splitter = Preconditions.checkNotNull( aggregation.unwrap(SqlSplittableAggFunction.class)); final Integer leftSubTotal = sides.get(0).split.get(aggCall.i); final Integer rightSubTotal = sides.get(1).split.get(aggCall.i); newAggCall.getAggregation().unwrap(SqlSplittableAggFunction.class); if (splitter != null) { final RelDataType rowType = relBuilder.peek().getRowType();
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())); } }
relBuilder.push(aggregate.getInput()); final List<AggregateCall> originalAggCalls = aggregate.getAggCallList(); final ImmutableBitSet originalGroupSet = aggregate.getGroupSet(); bottomGroupSet.addAll(aggregate.getGroupSet().asList()); for (AggregateCall aggCall : originalAggCalls) { if (aggCall.isDistinct()) { bottomGroupSet.addAll(aggCall.getArgList()); break; // since we only have single distinct call if (!aggCall.isDistinct()) { final AggregateCall newCall = AggregateCall.create(aggCall.getAggregation(), false, if (aggCall.getAggregation().getKind() == SqlKind.COUNT) { newCall = AggregateCall.create(new SqlSumEmptyIsZeroAggFunction(), false,
if (aggCall.getAggregation().getName().equals("COUNT") ) { if (aggCall.getArgList().isEmpty() || (aggCall.getArgList().size() == 1 && ! agg.getInput().getRowType().getFieldList().get(aggCall.getArgList().get(0).intValue()).getType().isNullable())) { cnt = getAccurateRowCount(scan.getTableMetadata().getSplits()); } else if (aggCall.getArgList().size() == 1) { String columnName = scan.getRowType().getFieldNames().get(index).toLowerCase(); RelDataType scanRowType = getCountRowType(agg.getCluster().getTypeFactory()); final ValuesPrel values = new ValuesPrel(agg.getCluster(), scan.getTraitSet().plus(Prel.PHYSICAL).plus(DistributionTrait.SINGLETON), scanRowType, new JSONOptions(getResultsNode(cnt))); List<RexNode> exprs = Lists.newArrayList();
for (AggregateCall aggregateCall : aggregate.getAggCallList()) { switch (aggregateCall.getAggregation().getKind()) { case COUNT: if (checkAggregateOnMetric(ImmutableBitSet.of(aggregateCall.getArgList()), node, query)) { return true; if (aggregateCall.getArgList().isEmpty()) { continue; case MAX: final RelDataType type = aggregateCall.getType(); final SqlTypeName sqlTypeName = type.getSqlTypeName(); if (SqlTypeFamily.APPROXIMATE_NUMERIC.getTypeNames().contains(sqlTypeName) || SqlTypeFamily.INTEGER.getTypeNames().contains(sqlTypeName)) { if (type.getScale() == 0 || config.approximateDecimal()) {
final Boolean[] memo = new Boolean[agg.getInput().getRowType().getFieldCount()]; for (AggregateCall c : agg.getAggCallList()) { final boolean candidate = c.isDistinct() && c.getArgList().size() == 1 && "COUNT".equals(c.getAggregation().getName()); } else { if(query == null) { query = agg.getCluster().getMetadataQuery();
final Union union = call.rel(1); final RexBuilder rexBuilder = agg.getCluster().getRexBuilder(); List<RexNode> joinConjs = new ArrayList<>(); List<RexNode> filterConjs = new ArrayList<>(); int groupCount = agg.getGroupCount(); int totalCount = agg.getGroupCount() + agg.getAggCallList().size(); for (int leftPos = 0, rightPos = totalCount; leftPos < groupCount; leftPos++, rightPos++) { RexNode leftRef = rexBuilder.makeInputRef( joinLeftInput.getRowType().getFieldList().get(leftPos).getType(), leftPos); RexNode rightRef = rexBuilder.makeInputRef( joinRightInput.getRowType().getFieldList().get(leftPos).getType(), rightPos); projExprs.add(rightRef); joinConjs.add(rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, joinLeftInput.getRowType().getFieldList().get(leftPos).getType(), leftPos); RexNode rightRef = rexBuilder.makeInputRef( joinRightInput.getRowType().getFieldList().get(leftPos).getType(), rightPos); SqlAggFunction aggCall = agg.getAggCallList().get(i).getAggregation(); switch (aggCall.getKind()) { case SUM:
@Override public void onMatch(RelOptRuleCall call) { final LogicalAggregate agg = call.rel(0); final RelDataTypeFactory typeFactory = agg.getCluster().getTypeFactory(); i++; if(!"NDV".equals(c.getAggregation().getName())) { calls.add(c); continue; calls.add(AggregateCall.create(HyperLogLog.HLL, false, c.getArgList(), -1, typeFactory.createSqlType(SqlTypeName.VARBINARY, HyperLogLog.HLL_VARBINARY_SIZE), c.getName())); for(int field = 0; field < agg.getRowType().getFieldCount(); field++) { if(!hllApplications.contains(field)) { nodes.add(builder.field(field));
type.getSqlTypeName() == SqlTypeName.DECIMAL; rexBuilder.makeOver( SqlStdOperatorTable.HISTOGRAM_AGG .inferReturnType(bind), SqlStdOperatorTable.HISTOGRAM_AGG, exprs, } else { boolean needSum0 = aggOp == SqlStdOperatorTable.SUM && type.isNullable(); SqlAggFunction aggOpToUse = needSum0 ? SqlStdOperatorTable.SUM0
- ((Aggregate) rel).getGroupCount(); AggregateCall aggCall = ((Aggregate) rel).getAggCallList().get(indexSkipGroup); if (aggCall.isDistinct() && aggCall.getAggregation().getKind() == SqlKind.COUNT) { final String fieldName = rel.getRowType().getFieldNames() .get(((RexInputRef) rexNode).getIndex()); List<String> fieldNames = ((Aggregate) rel).getInput().getRowType().getFieldNames(); String complexName = fieldNames.get(aggCall.getArgList().get(0)); ComplexMetric metric = druidTable.resolveComplexMetric(complexName, aggCall); rel.getRowType().getFieldNames().get(((RexInputRef) rexNode).getIndex())); } else if (rexNode instanceof RexLiteral) {
protected void createKeysAndExprs() { final List<String> childFields = getInput().getRowType().getFieldNames(); final List<String> fields = getRowType().getFieldNames(); if (aggCall.e.getAggregation().getName().equals("COUNT")) { SqlAggFunction sumAggFun = new SqlSumCountAggFunction(aggCall.e.getType()); AggregateCall newAggCall = AggregateCall.create( sumAggFun, aggCall.e.isDistinct(),
Map<AggregateCall, RexNode> aggCallMapping, List<RexNode> inputExprs) { final SqlKind kind = oldCall.getAggregation().getKind(); if (isReducible(kind)) { switch (kind) { 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,
AggregateCall aggCall = AggregateCall.create(HiveGroupingID.INSTANCE, false, new ImmutableList.Builder<Integer>().build(), -1, this.cluster.getTypeFactory() .createSqlType(SqlTypeName.INTEGER), HiveGroupingID.INSTANCE.getName()); aggregateCalls.add(aggCall); return new HiveAggregate(cluster, cluster.traitSetOf(HiveRelNode.CONVENTION), aggregate.getInput(), true, groupSet, origGroupSets, aggregateCalls);
AggregateCall aggCall = new AggregateCall(HiveGroupingID.INSTANCE, false, new ImmutableList.Builder<Integer>().build(), this.cluster.getTypeFactory().createSqlType(SqlTypeName.INTEGER), HiveGroupingID.INSTANCE.getName()); aggregateCalls.add(aggCall); gbChildProjLst.add(this.cluster.getRexBuilder().makeInputRef(srcRel, 0)); HiveRelNode aggregateRel = new HiveAggregate(cluster, cluster.traitSetOf(HiveRelNode.CONVENTION), gbInputRel, (transformedGroupSets!=null ? true:false), groupSet, transformedGroupSets, aggregateCalls);
public static LogicalExpression toExpr(AggregateCall call, List<String> fn, LogicalPlanImplementor implementor) { List<LogicalExpression> args = Lists.newArrayList(); for(Integer i : call.getArgList()) { args.add(new FieldReference(fn.get(i))); } // for count(1). if (args.isEmpty()) { args.add(new ValueExpressions.LongExpression(1l)); } LogicalExpression expr = FunctionCallFactory.createExpression(call.getAggregation().getName().toLowerCase(), args); return expr; }
@Override public void onMatch(RelOptRuleCall call) { Aggregate aggregate = call.rel(0); if (!aggregate.containsDistinctCall()) { return; final long numCountDistinct = aggregate.getAggCallList() .stream() .filter(aggregateCall -> aggregateCall.getAggregation().getKind().equals(SqlKind.COUNT) && aggregateCall.isDistinct()) .count(); if (numCountDistinct != 1) { int unsupportedNonDistinctAggCallCount = 0; final Set<Pair<List<Integer>, Integer>> argLists = new LinkedHashSet<>(); for (AggregateCall aggCall : aggregate.getAggCallList()) { if (aggCall.filterArg >= 0) { ++filterCount; if (!aggCall.isDistinct()) { ++nonDistinctAggCallCount; final SqlKind aggCallKind = aggCall.getAggregation().getKind();