/** * Returns whether any of the aggregates are calls to AVG, STDDEV_*, VAR_*. * * @param aggCallList List of aggregate calls */ private boolean containsAvgStddevVarCall(List<AggregateCall> aggCallList) { for (AggregateCall call : aggCallList) { if (isReducible(call.getAggregation().getKind())) { return true; } } return false; }
private boolean isAggZeroOnEmpty(RexSubQuery e) { //as this is corr scalar subquery with agg we expect one aggregate assert(e.getKind() == SqlKind.SCALAR_QUERY); assert(e.rel.getInputs().size() == 1); Aggregate relAgg = (Aggregate)e.rel.getInput(0); assert(relAgg.getAggCallList().size() == 1); //should only have one aggregate if(relAgg.getAggCallList().get(0).getAggregation().getKind() == SqlKind.COUNT) { return true; } return false; }
private boolean isAggZeroOnEmpty(RexSubQuery e) { //as this is corr scalar subquery with agg we expect one aggregate assert(e.getKind() == SqlKind.SCALAR_QUERY); assert(e.rel.getInputs().size() == 1); Aggregate relAgg = (Aggregate)e.rel.getInput(0); assert( relAgg.getAggCallList().size() == 1); //should only have one aggregate if( relAgg.getAggCallList().get(0).getAggregation().getKind() == SqlKind.COUNT ) { return true; } return false; } private SqlTypeName getAggTypeForScalarSub(RexSubQuery e) {
@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; }
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 (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());
switch (aggCall.getKind()) { case SUM:
if (aggCall.getAggregation().getKind() == SqlKind.COUNT) { newCall = AggregateCall.create(new SqlSumEmptyIsZeroAggFunction(), false,
Map<AggregateCall, RexNode> aggCallMapping, List<RexNode> inputExprs) { final SqlKind kind = oldCall.getAggregation().getKind(); if (isReducible(kind)) { switch (kind) {
/** Returns whether this JDBC data source can implement a given aggregate * function. */ private static boolean canImplement(SqlAggFunction aggregation, SqlDialect sqlDialect) { return sqlDialect.supportsAggregateFunction(aggregation.getKind()); }
/** Returns whether this JDBC data source can implement a given aggregate * function. */ private static boolean canImplement(SqlAggFunction aggregation, SqlDialect sqlDialect) { return sqlDialect.supportsAggregateFunction(aggregation.getKind()); }
/** * Returns whether any of the aggregates are calls to AVG, STDDEV_*, VAR_*. * * @param aggCallList List of aggregate calls */ private boolean containsAvgStddevVarCall(List<AggregateCall> aggCallList) { for (AggregateCall call : aggCallList) { if (isReducible(call.getAggregation().getKind())) { return true; } } return false; }
/** * Returns whether any of the aggregates are calls to AVG, STDDEV_*, VAR_*. * * @param aggCallList List of aggregate calls */ private boolean containsAvgStddevVarCall(List<AggregateCall> aggCallList) { for (AggregateCall call : aggCallList) { if (isReducible(call.getAggregation().getKind())) { return true; } } return false; }
/** * Returns true if and only if this <code>ComplexMetric</code> * can be used in the given {@link AggregateCall}. */ public boolean canBeUsed(AggregateCall call) { switch (type) { case HYPER_UNIQUE: case THETA_SKETCH: return call != null && call.getAggregation().getKind() == SqlKind.COUNT && call.isDistinct(); default: return false; } } }
/** * Returns true if and only if this <code>ComplexMetric</code> * can be used in the given {@link AggregateCall}. * */ public boolean canBeUsed(AggregateCall call) { switch (type) { case HYPER_UNIQUE: case THETA_SKETCH: return call != null && call.getAggregation().getKind() == SqlKind.COUNT && call.isDistinct(); default: return false; } } }
void validateAggregateFunctions(final LogicalAggregate aggregate) { if (aggregate.getAggCallList().size() != 1) { String errMsg = "Windowing is supported ONLY with one aggregate function but the number of given functions are " + aggregate.getAggCallList().size(); log.error(errMsg); throw new SamzaException(errMsg); } if (aggregate.getAggCallList().get(0).getAggregation().getKind() != SqlKind.COUNT) { String errMsg = "Windowing is supported ONLY with COUNT aggregate function"; log.error(errMsg); throw new SamzaException(errMsg); } } }
void validateAggregateFunctions(final LogicalAggregate aggregate) { if (aggregate.getAggCallList().size() != 1) { String errMsg = "Windowing is supported ONLY with one aggregate function but the number of given functions are " + aggregate.getAggCallList().size(); log.error(errMsg); throw new SamzaException(errMsg); } if (aggregate.getAggCallList().get(0).getAggregation().getKind() != SqlKind.COUNT) { String errMsg = "Windowing is supported ONLY with COUNT aggregate function"; log.error(errMsg); throw new SamzaException(errMsg); } } }
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery relMetadataQuery) { for (AggregateCall aggCall : getAggCallList()) { // For avg, stddev_pop, stddev_samp, var_pop and var_samp, the ReduceAggregatesRule is supposed // to convert them to use sum and count. Here, we make the cost of the original functions high // enough such that the planner does not choose them and instead chooses the rewritten functions. if (aggCall.getAggregation().getKind() == SqlKind.AVG || aggCall.getAggregation().getKind() == SqlKind.STDDEV_SAMP || aggCall.getAggregation().getKind() == SqlKind.STDDEV_POP || aggCall.getAggregation().getKind() == SqlKind.VAR_POP || aggCall.getAggregation().getKind() == SqlKind.VAR_SAMP) { return planner.getCostFactory().makeHugeCost(); } } final double rowCount = relMetadataQuery.getRowCount(this); final double childRowCount = relMetadataQuery.getRowCount(this.getInput()); // Aggregates with more aggregate functions cost a bit more float multiplier = 1f + (float) aggCalls.size() * 0.125f; return ((Factory) planner.getCostFactory()).makeCost(rowCount,childRowCount * multiplier * DremioCost.FUNC_CPU_COST, 0, 0); }
private DrillCalciteSqlAggFunctionWrapper( SqlAggFunction sqlAggFunction, SqlReturnTypeInference sqlReturnTypeInference) { super(sqlAggFunction.getName(), sqlAggFunction.getSqlIdentifier(), sqlAggFunction.getKind(), sqlReturnTypeInference, sqlAggFunction.getOperandTypeInference(), Checker.ANY_CHECKER, sqlAggFunction.getFunctionType(), sqlAggFunction.requiresOrder(), sqlAggFunction.requiresOver()); this.operator = sqlAggFunction; }