public static AggregateFunctionCallExpression makeAggregateFunctionExpression(FunctionIdentifier fi, List<Mutable<ILogicalExpression>> args) { IFunctionInfo finfo = getAsterixFunctionInfo(fi); IFunctionInfo fiLocal = aggregateToLocalAggregate.get(finfo); IFunctionInfo fiGlobal = aggregateToGlobalAggregate.get(finfo); if (fiLocal != null && fiGlobal != null) { AggregateFunctionCallExpression fun = new AggregateFunctionCallExpression(finfo, true, args); fun.setStepTwoAggregate(fiGlobal); fun.setStepOneAggregate(fiLocal); return fun; } else { return new AggregateFunctionCallExpression(finfo, false, args); } }
public static AggregateFunctionCallExpression makeSerializableAggregateFunctionExpression(FunctionIdentifier fi, List<Mutable<ILogicalExpression>> args) { IFunctionInfo finfo = getAsterixFunctionInfo(fi); IFunctionInfo serializableFinfo = aggregateToSerializableAggregate.get(finfo); if (serializableFinfo == null) { throw new IllegalStateException( "no serializable implementation for aggregate function " + serializableFinfo); } IFunctionInfo fiLocal = aggregateToLocalAggregate.get(serializableFinfo); IFunctionInfo fiGlobal = aggregateToGlobalAggregate.get(serializableFinfo); if (fiLocal != null && fiGlobal != null) { AggregateFunctionCallExpression fun = new AggregateFunctionCallExpression(serializableFinfo, true, args); fun.setStepTwoAggregate(fiGlobal); fun.setStepOneAggregate(fiLocal); return fun; } else { return new AggregateFunctionCallExpression(serializableFinfo, false, args); } }
@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 AggregateFunctionCallExpression cloneExpression() { cloneAnnotations(); List<Mutable<ILogicalExpression>> clonedArgs = cloneArguments(); AggregateFunctionCallExpression fun = new AggregateFunctionCallExpression(finfo, twoStep, clonedArgs); fun.setStepTwoAggregate(stepTwoAggregate); fun.setStepOneAggregate(stepOneAggregate); fun.setSourceLocation(sourceLoc); // opaqueParameters are not really cloned fun.setOpaqueParameters(getOpaqueParameters()); return fun; }
@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; }