@Override public String visitAggregateFunctionCallExpression(AggregateFunctionCallExpression expr, Integer indent) throws AlgebricksException { if (expr.isTwoStep()) { IFunctionInfo step1Agg = expr.getStepOneAggregate(); String step1 = (step1Agg != null ? step1Agg.getFunctionIdentifier().toString() : "null"); IFunctionInfo step2Agg = expr.getStepTwoAggregate(); String step2 = (step2Agg != null ? step2Agg.getFunctionIdentifier().toString() : "null"); StringBuilder sb = new StringBuilder(); sb.append("function-call: [" + step1 + "|" + step2 + "], Args:"); appendArguments(sb, expr.getArguments(), indent + 2); return sb.toString(); } else if (expr.getFunctionInfo() == null) { StringBuilder sb = new StringBuilder(); sb.append("function-call: [null], Args:"); appendArguments(sb, expr.getArguments(), indent + 2); return sb.toString(); } else { return appendFunction(new StringBuilder(), expr, indent).toString(); } }
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { // Check if aggregate function. AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.AGGREGATE) { return false; } AggregateOperator aggregate = (AggregateOperator) op; Mutable<ILogicalExpression> mutableLogicalExpression = aggregate.getExpressions().get(0); ILogicalExpression logicalExpression = mutableLogicalExpression.getValue(); if (logicalExpression.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { return false; } AbstractFunctionCallExpression functionCall = (AbstractFunctionCallExpression) logicalExpression; if (AGGREGATE_MAP.containsKey(functionCall.getFunctionIdentifier())) { AggregateFunctionCallExpression aggregateFunctionCall = (AggregateFunctionCallExpression) functionCall; if (aggregateFunctionCall.isTwoStep()) { return false; } aggregateFunctionCall.setTwoStep(true); aggregateFunctionCall.setStepOneAggregate(AGGREGATE_MAP.get(functionCall.getFunctionIdentifier()).first); aggregateFunctionCall.setStepTwoAggregate(AGGREGATE_MAP.get(functionCall.getFunctionIdentifier()).second); return true; } return false; }
@Override public ILogicalExpression visitAggregateFunctionCallExpression(AggregateFunctionCallExpression expr, Void arg) throws AlgebricksException { AggregateFunctionCallExpression exprCopy = new AggregateFunctionCallExpression(expr.getFunctionInfo(), expr.isTwoStep(), deepCopyExpressionReferenceList(expr.getArguments())); exprCopy.setStepOneAggregate(expr.getStepOneAggregate()); exprCopy.setStepTwoAggregate(expr.getStepTwoAggregate()); deepCopyAnnotations(expr, exprCopy); deepCopyOpaqueParameters(expr, exprCopy); copySourceLocation(expr, exprCopy); return exprCopy; }
if (!aggFun.isTwoStep()) { return new Pair<>(false, null);