public static List<Mutable<ILogicalExpression>> cloneExpressions(List<Mutable<ILogicalExpression>> exprList) { if (exprList == null) { return null; } List<Mutable<ILogicalExpression>> clonedExprList = new ArrayList<>(exprList.size()); for (Mutable<ILogicalExpression> expr : exprList) { clonedExprList.add(new MutableObject<>(expr.getValue().cloneExpression())); } return clonedExprList; }
protected List<Mutable<ILogicalExpression>> cloneArguments() { List<Mutable<ILogicalExpression>> clonedArgs = new ArrayList<Mutable<ILogicalExpression>>(arguments.size()); for (Mutable<ILogicalExpression> e : arguments) { ILogicalExpression e2 = e.getValue().cloneExpression(); clonedArgs.add(new MutableObject<ILogicalExpression>(e2)); } return clonedArgs; }
private Mutable<ILogicalExpression> copyExpressionAndSubtituteVars(Mutable<ILogicalExpression> expr) { ILogicalExpression copy = expr.getValue().cloneExpression(); variableMapping.forEach(copy::substituteVar); return new MutableObject<>(copy); }
public static List<Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>>> cloneOrderExpressions( List<Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>>> orderExprList) { if (orderExprList == null) { return null; } List<Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>>> clonedExprList = new ArrayList<>(orderExprList.size()); for (Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> orderExpr : orderExprList) { clonedExprList.add( new Pair<>(orderExpr.first, new MutableObject<>(orderExpr.second.getValue().cloneExpression()))); } return clonedExprList; }
private Mutable<ILogicalExpression> deepCopyExpressionRef(Mutable<ILogicalExpression> oldExprRef) { ILogicalExpression oldExpr = oldExprRef.getValue(); if (oldExpr == null) { return new MutableObject<>(null); } return new MutableObject<>(oldExpr.cloneExpression()); }
exprRef.setValue(rhs.cloneExpression()); return true;
/** * Clones the given assign operator changing the returned variables to be new ones. * Also, leaves the inputs of the clone clear. */ private AssignOperator cloneAssignOperator(AssignOperator assignOp, IOptimizationContext context) { List<LogicalVariable> vars = new ArrayList<LogicalVariable>(); List<Mutable<ILogicalExpression>> exprs = new ArrayList<Mutable<ILogicalExpression>>(); int numVars = assignOp.getVariables().size(); for (int i = 0; i < numVars; i++) { vars.add(context.newVar()); exprs.add(new MutableObject<ILogicalExpression>( assignOp.getExpressions().get(i).getValue().cloneExpression())); } AssignOperator assignCloneOp = new AssignOperator(vars, exprs); assignCloneOp.setSourceLocation(assignOp.getSourceLocation()); assignCloneOp.setExecutionMode(assignOp.getExecutionMode()); return assignCloneOp; } }
List<Mutable<ILogicalExpression>> resultExprs = new ArrayList<>(valueExprs.size()); for (Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> p : valueExprs) { resultExprs.add(new MutableObject<>(p.second.getValue().cloneExpression()));
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; } } } }
private Pair<List<Mutable<ILogicalExpression>>, ILogicalOperator> translateWindowBoundaryExpr( Expression boundaryExpr, List<Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>>> valueExprs, Mutable<ILogicalOperator> tupSource, OperatorType boundaryOperator) throws CompilationException { SourceLocation sourceLoc = boundaryExpr.getSourceLocation(); if (valueExprs.size() != 1) { throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, sourceLoc, valueExprs.size()); } ILogicalExpression valueExpr = valueExprs.get(0).second.getValue(); AbstractFunctionCallExpression resultExpr = createFunctionCallExpressionForBuiltinOperator(boundaryOperator, sourceLoc); resultExpr.getArguments().add(new MutableObject<>(valueExpr.cloneExpression())); Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(boundaryExpr, tupSource); resultExpr.getArguments().add(new MutableObject<>(eo.first)); LogicalVariable resultVar = context.newVar(); AssignOperator assignOp = new AssignOperator(resultVar, new MutableObject<>(resultExpr)); assignOp.setSourceLocation(sourceLoc); assignOp.getInputs().add(eo.second); VariableReferenceExpression resultVarRefExpr = new VariableReferenceExpression(resultVar); resultVarRefExpr.setSourceLocation(sourceLoc); return new Pair<>(mkSingletonArrayList(new MutableObject<>(resultVarRefExpr)), assignOp); }
new ArrayList<>(orderExprList.size()); for (Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> p : orderExprList) { result.add(new Pair<>(p.first, new MutableObject<>(p.second.getValue().cloneExpression())));
private WindowOperator createHelperWindowOperator(List<Mutable<ILogicalExpression>> partExprList, List<Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>>> orderExprList, LogicalVariable rowNumVar, LogicalVariable denseRankVar, ListSet<LogicalVariable> usedVars, SourceLocation sourceLoc) throws CompilationException { WindowOperator winOp = new WindowOperator(partExprList, orderExprList); winOp.setSourceLocation(sourceLoc); for (LogicalVariable usedVar : usedVars) { FunctionIdentifier fid; if (usedVar.equals(rowNumVar)) { fid = BuiltinFunctions.ROW_NUMBER_IMPL; } else if (usedVar.equals(denseRankVar)) { fid = BuiltinFunctions.DENSE_RANK_IMPL; } else { throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, sourceLoc, usedVar.toString()); } AbstractFunctionCallExpression valueExpr = BuiltinFunctions.makeWindowFunctionExpression(fid, new ArrayList<>()); if (BuiltinFunctions.windowFunctionHasProperty(valueExpr.getFunctionIdentifier(), BuiltinFunctions.WindowFunctionProperty.INJECT_ORDER_ARGS)) { for (Pair<OrderOperator.IOrder, Mutable<ILogicalExpression>> p : orderExprList) { valueExpr.getArguments().add(new MutableObject<>(p.second.getValue().cloneExpression())); } } valueExpr.setSourceLocation(winOp.getSourceLocation()); winOp.getVariables().add(usedVar); winOp.getExpressions().add(new MutableObject<>(valueExpr)); } return winOp; } }
new MutableObject<ILogicalExpression>(unnestOpRef.getExpressionRef().getValue().cloneExpression())); LogicalVariable unnestVar2 = context.newVar(); UnnestOperator unnest2 = new UnnestOperator(unnestVar2, new MutableObject<ILogicalExpression>(unnestOpRef.getExpressionRef().getValue().cloneExpression()));
Mutable<ILogicalExpression> exprRef = assignOp.getExpressions().get(i); ILogicalExpression expr = exprRef.getValue(); originalAssignExprs.add(expr.cloneExpression());
newArgs.add(new MutableObject<>(er.getValue().cloneExpression()));
selectCondition.getUsedVariables(selectedVariables); MutableObject<ILogicalExpression> selectConditionRef = new MutableObject<>(selectCondition.cloneExpression());
private boolean assignCommonExpression(ExprEquivalenceClass exprEqClass, ILogicalExpression expr) throws AlgebricksException { SourceLocation sourceLoc = expr.getSourceLocation(); AbstractLogicalOperator firstOp = (AbstractLogicalOperator) exprEqClass.getFirstOperator(); Mutable<ILogicalExpression> firstExprRef = exprEqClass.getFirstExpression(); // We don't consider to eliminate common exprs in join operators by doing a cartesian production // and pulling the condition in to a select. This will negatively impact the performance. if (firstOp.getInputs().size() > 1) { // Bail for any non-join operator with multiple inputs. return false; } LogicalVariable newVar = context.newVar(); AssignOperator newAssign = new AssignOperator(newVar, new MutableObject<ILogicalExpression>(firstExprRef.getValue().cloneExpression())); newAssign.setSourceLocation(sourceLoc); // Place assign below firstOp. newAssign.getInputs().add(new MutableObject<ILogicalOperator>(firstOp.getInputs().get(0).getValue())); newAssign.setExecutionMode(firstOp.getExecutionMode()); firstOp.getInputs().get(0).setValue(newAssign); // Replace original expr with variable reference, and set var in expression equivalence class. VariableReferenceExpression newVarRef = new VariableReferenceExpression(newVar); newVarRef.setSourceLocation(sourceLoc); firstExprRef.setValue(newVarRef); exprEqClass.setVariable(newVar); context.computeAndSetTypeEnvironmentForOperator(newAssign); context.computeAndSetTypeEnvironmentForOperator(firstOp); return true; }
LogicalVariable newVar = context.newVar(); AssignOperator newAssign = new AssignOperator(newVar, new MutableObject<ILogicalExpression>(exprRef .getValue().cloneExpression())); newAssign.setExecutionMode(joinOp.getExecutionMode());
List<Mutable<ILogicalExpression>> addArgs = new ArrayList<>(); addArgs.add( new MutableObject<ILogicalExpression>(limitOp.getMaxObjects().getValue().cloneExpression())); addArgs.add(new MutableObject<ILogicalExpression>(limitOp.getOffset().getValue().cloneExpression())); ScalarFunctionCallExpression maxPlusOffset = new ScalarFunctionCallExpression(finfoAdd, addArgs); maxPlusOffset.setSourceLocation(sourceLoc);
LogicalVariable newVar = context.newVar(); AssignOperator newAssign = new AssignOperator(newVar, new MutableObject<ILogicalExpression>(exprRef.getValue().cloneExpression())); newAssign.setSourceLocation(exprRefSourceLoc); newAssign.setExecutionMode(joinOp.getExecutionMode());