private void rewriteAggregateInNestedSubplan(LogicalVariable oldAggVar, AbstractOperatorWithNestedPlans nspOp, AggregateFunctionCallExpression aggFun, LogicalVariable newAggVar, IOptimizationContext context) throws AlgebricksException { for (int j = 0; j < nspOp.getNestedPlans().size(); j++) { AggregateOperator aggOp = (AggregateOperator) nspOp.getNestedPlans().get(j).getRoots().get(0).getValue(); int n = aggOp.getVariables().size(); for (int i = 0; i < n; i++) { LogicalVariable v = aggOp.getVariables().get(i); if (v.equals(oldAggVar)) { AbstractFunctionCallExpression oldAggExpr = (AbstractFunctionCallExpression) aggOp.getExpressions().get(i).getValue(); AggregateFunctionCallExpression newAggFun = BuiltinFunctions .makeAggregateFunctionExpression(aggFun.getFunctionIdentifier(), new ArrayList<>()); newAggFun.setSourceLocation(oldAggExpr.getSourceLocation()); for (Mutable<ILogicalExpression> arg : oldAggExpr.getArguments()) { ILogicalExpression cloned = arg.getValue().cloneExpression(); newAggFun.getArguments().add(new MutableObject<>(cloned)); } aggOp.getVariables().add(newAggVar); aggOp.getExpressions().add(new MutableObject<>(newAggFun)); context.computeAndSetTypeEnvironmentForOperator(aggOp); break; } } } }
@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 createMergeAggregation(LogicalVariable originalProducedVar, ILogicalExpression expr, IOptimizationContext env) throws AlgebricksException { AggregateFunctionCallExpression agg = (AggregateFunctionCallExpression) expr; FunctionIdentifier fid = agg.getFunctionIdentifier(); VariableReferenceExpression tempVarExpr = new VariableReferenceExpression(originalProducedVar); tempVarExpr.setSourceLocation(agg.getSourceLocation()); List<Mutable<ILogicalExpression>> arguments = new ArrayList<Mutable<ILogicalExpression>>(); Mutable<ILogicalExpression> mutableExpression = new MutableObject<ILogicalExpression>(tempVarExpr); arguments.add(mutableExpression); /** * For global aggregate, the merge function is ALWAYS the same as the original aggregate function. */ FunctionIdentifier mergeFid = BuiltinFunctions.isGlobalAggregateFunction(fid) ? fid : BuiltinFunctions.getIntermediateAggregateFunction(fid); if (mergeFid == null) { /** * In this case, no merge function (unimplemented) for the local-side aggregate function */ return null; } AggregateFunctionCallExpression mergeExpr = BuiltinFunctions.makeAggregateFunctionExpression(mergeFid, arguments); mergeExpr.setSourceLocation(agg.getSourceLocation()); return mergeExpr; } }
AggregateFunctionCallExpression aggFuncExpr = BuiltinFunctions.makeAggregateFunctionExpression(aggFuncIdent, aggArgs); aggFuncExpr.setSourceLocation(assignFuncExpr.getSourceLocation()); LogicalVariable newVar = context.newVar(); aggOp.getVariables().add(newVar);
protected ILogicalPlan createNestedPlanWithAggregate(LogicalVariable aggOutputVar, FunctionIdentifier aggFunc, ILogicalExpression aggFnInput, Mutable<ILogicalOperator> aggOpInput) { SourceLocation sourceLoc = aggFnInput.getSourceLocation(); AggregateFunctionCallExpression aggFnCall = BuiltinFunctions.makeAggregateFunctionExpression(aggFunc, mkSingletonArrayList(new MutableObject<>(aggFnInput))); aggFnCall.setSourceLocation(sourceLoc); AggregateOperator aggOp = new AggregateOperator(mkSingletonArrayList(aggOutputVar), mkSingletonArrayList(new MutableObject<>(aggFnCall))); aggOp.getInputs().add(aggOpInput); aggOp.setSourceLocation(sourceLoc); return new ALogicalPlanImpl(new MutableObject<>(aggOp)); }
protected Pair<ILogicalOperator, LogicalVariable> aggListifyForSubquery(LogicalVariable var, Mutable<ILogicalOperator> opRef, boolean bProject) { SourceLocation sourceLoc = opRef.getValue().getSourceLocation(); AggregateFunctionCallExpression funAgg = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.LISTIFY, new ArrayList<>()); funAgg.getArguments().add(new MutableObject<>(new VariableReferenceExpression(var))); funAgg.setSourceLocation(sourceLoc); LogicalVariable varListified = context.newSubplanOutputVar(); AggregateOperator agg = new AggregateOperator(mkSingletonArrayList(varListified), mkSingletonArrayList(new MutableObject<>(funAgg))); agg.getInputs().add(opRef); agg.setSourceLocation(sourceLoc); ILogicalOperator res; if (bProject) { ProjectOperator pr = new ProjectOperator(varListified); pr.getInputs().add(new MutableObject<>(agg)); pr.setSourceLocation(sourceLoc); res = pr; } else { res = agg; } return new Pair<>(res, varListified); }
AggregateFunctionCallExpression aggExpr = new AggregateFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.LISTIFY), false, aggArgList); aggExpr.setSourceLocation(sourceLoc); aggExprList.add(new MutableObject<>(aggExpr)); AggregateOperator aggOp = new AggregateOperator(aggVarList, aggExprList);
AggregateFunctionCallExpression aggFun = BuiltinFunctions.makeAggregateFunctionExpression(fi, fce.getArguments()); aggFun.setSourceLocation(expr.getSourceLocation()); rewriteAggregateInNestedSubplan(argVar, nspOp, aggFun, newVar, context); VariableReferenceExpression newVarExpr = new VariableReferenceExpression(newVar);
toReplaceSet.add(inf); AggregateFunctionCallExpression aggLocal = new AggregateFunctionCallExpression(fi1, false, newArgs); aggLocal.setSourceLocation(aggFunSourceLoc); pushedExprs.add(new MutableObject<>(aggLocal)); AggregateExprInfo aei = new AggregateExprInfo();
new AggregateFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.LISTIFY), false, new ArrayList<>(Collections.singletonList(aggArgExprRef))); aggExpr.setSourceLocation(sourceLoc); AggregateOperator aggregateOperator = new AggregateOperator(new ArrayList<>(Collections.singletonList(aggVar)), new ArrayList<>(Collections.singletonList(new MutableObject<>(aggExpr))));
fAgg = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.NON_EMPTY_STREAM, new ArrayList<>()); fAgg.setSourceLocation(sourceLoc); } else { // EVERY s.setSourceLocation(sourceLoc); fAgg = BuiltinFunctions.makeAggregateFunctionExpression(BuiltinFunctions.EMPTY_STREAM, new ArrayList<>()); fAgg.setSourceLocation(sourceLoc);
new AggregateFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.LISTIFY), false, Collections.singletonList(new MutableObject<>(pBranchVarRef))); listifyExpr.setSourceLocation(branchExpression.getSourceLocation()); AggregateOperator aggOp = new AggregateOperator(Collections.singletonList(branchVar), Collections.singletonList(new MutableObject<>(listifyExpr)));
BuiltinFunctions.makeSerializableAggregateFunctionExpression( expr.getFunctionIdentifier(), expr.getArguments()); serialAggExpr.setSourceLocation(expr.getSourceLocation()); if (mergeAggregationExpressionFactory.createMergeAggregation( originalVariables.get(i), serialAggExpr, context) == null) { BuiltinFunctions.makeSerializableAggregateFunctionExpression( expr.getFunctionIdentifier(), expr.getArguments()); serialAggExpr.setSourceLocation(expr.getSourceLocation()); aggOp.getExpressions().get(i).setValue(serialAggExpr);
listifyCall.setSourceLocation(sourceLoc); LogicalVariable windowVar = context.newVar(); AggregateOperator aggOp = new AggregateOperator(mkSingletonArrayList(windowVar),
AggregateFunctionCallExpression fListify = BuiltinFunctions.makeAggregateFunctionExpression( BuiltinFunctions.LISTIFY, mkSingletonArrayList(new MutableObject<>(varToListifyRef))); fListify.setSourceLocation(currentTopOp.getSourceLocation());