@Override public Void visitAssignOperator(AssignOperator op, IOptimizationContext context) throws AlgebricksException { visitAssignment(op, op.getExpressions(), context); return null; }
private void gatherFunctionCalls(AssignOperator assignOp, List<Mutable<ILogicalExpression>> funcExprs) { for (Mutable<ILogicalExpression> exprRef : assignOp.getExpressions()) { gatherFunctionCalls(exprRef, funcExprs); } }
private ILogicalExpression getFirstExpr(AssignOperator assign) { return assign.getExpressions().get(0).getValue(); }
private static ILogicalExpression getFirstExpr(AssignOperator assign) { return assign.getExpressions().get(0).getValue(); }
@Override public ILogicalOperator visitAssignOperator(AssignOperator op, Void arg) throws AlgebricksException { ArrayList<LogicalVariable> newList = new ArrayList<>(); ArrayList<Mutable<ILogicalExpression>> newExpressions = new ArrayList<>(); newList.addAll(op.getVariables()); deepCopyExpressionRefs(newExpressions, op.getExpressions()); return new AssignOperator(newList, newExpressions); }
private void extractInlinableVariablesFromAssign(AssignOperator assignOp, Set<LogicalVariable> includeVariables, Map<LogicalVariable, ILogicalExpression> outVarExprs) { List<LogicalVariable> vars = assignOp.getVariables(); List<Mutable<ILogicalExpression>> exprs = assignOp.getExpressions(); for (int i = 0, ln = vars.size(); i < ln; i++) { LogicalVariable var = vars.get(i); if (includeVariables.contains(var)) { ILogicalExpression expr = exprs.get(i).getValue(); if (expr.isFunctional()) { outVarExprs.put(var, expr); } } } } }
@Override public Void visitAssignOperator(AssignOperator op, Void arg) { for (Mutable<ILogicalExpression> exprRef : op.getExpressions()) { exprRef.getValue().getUsedVariables(usedVariables); } return null; }
@Override public String visitAssignOperator(AssignOperator op, Boolean showDetails) throws AlgebricksException { stringBuilder.setLength(0); stringBuilder.append("assign ").append(str(op.getVariables())).append(" <- "); printExprList(op.getExpressions()); appendSchema(op, showDetails); appendAnnotations(op, showDetails); appendPhysicalOperatorInfo(op, showDetails); return stringBuilder.toString(); }
private void removeUnecessaryAssign(AbstractLogicalOperator parentOp, AbstractLogicalOperator currentOp, AssignOperator assignOp, int index) { assignOp.getVariables().remove(index); assignOp.getExpressions().remove(index); if (assignOp.getVariables().size() == 0) { int opIndex = parentOp.getInputs().indexOf(new MutableObject<ILogicalOperator>(currentOp)); parentOp.getInputs().get(opIndex).setValue(assignOp.getInputs().get(0).getValue()); } } }
@Override public Void visitAssignOperator(AssignOperator op, Integer indent) throws AlgebricksException { addIndent(indent).append("\"operator\": \"assign\""); variablePrintHelper(op.getVariables(), indent); if (!op.getExpressions().isEmpty()) { addIndent(0).append(",\n"); pprintExprList(op.getExpressions(), indent); } return null; }
@Override public Boolean visitAssignOperator(AssignOperator op, ILogicalOperator arg) throws AlgebricksException { AbstractLogicalOperator aop = (AbstractLogicalOperator) arg; if (aop.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return Boolean.FALSE; } AssignOperator assignOpArg = (AssignOperator) copyAndSubstituteVar(op, arg); boolean isomorphic = VariableUtilities.varListEqualUnordered(getPairList(op.getVariables(), op.getExpressions()), getPairList(assignOpArg.getVariables(), assignOpArg.getExpressions())); return isomorphic; }
private boolean inlineInputAssignIntoAgg(AggregateOperator aggOp) throws AlgebricksException { AbstractLogicalOperator op2 = (AbstractLogicalOperator) aggOp.getInputs().get(0).getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return false; } AssignOperator assignOp = (AssignOperator) op2; VarExprSubstitution ves = new VarExprSubstitution(assignOp.getVariables(), assignOp.getExpressions()); inlineVariables(aggOp, ves); List<Mutable<ILogicalOperator>> op1InpList = aggOp.getInputs(); op1InpList.clear(); op1InpList.add(op2.getInputs().get(0)); return true; }
@Override public ILogicalOperator visitAssignOperator(AssignOperator op, Void arg) throws AlgebricksException { visitSingleInputOperator(op); List<Mutable<ILogicalExpression>> assignedExprRefs = op.getExpressions(); List<LogicalVariable> assignedVars = op.getVariables(); // Maps assigning variables if assignment expressions are // VariableReferenceExpressions. for (int index = 0; index < assignedVars.size(); ++index) { ILogicalExpression expr = assignedExprRefs.get(index).getValue(); if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) { VariableReferenceExpression varExpr = (VariableReferenceExpression) expr; LogicalVariable sourceVar = varExpr.getVariableReference(); updateInputToOutputVarMapping(sourceVar, assignedVars.get(index), false); } } return op; }
/** * 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; } }
private boolean inlineOuterInputAssignIntoAgg(AggregateOperator aggOp, AbstractOperatorWithNestedPlans opWithNestedPlans) throws AlgebricksException { AbstractLogicalOperator op2 = (AbstractLogicalOperator) opWithNestedPlans.getInputs().get(0).getValue(); if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return false; } AssignOperator assignOp = (AssignOperator) op2; VarExprSubstitution ves = new VarExprSubstitution(assignOp.getVariables(), assignOp.getExpressions()); return inlineVariables(aggOp, ves); }
private boolean testAndModifyRedundantOp(AssignOperator access, AbstractLogicalOperator op2) { if (op2.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return false; } AssignOperator a2 = (AssignOperator) op2; ILogicalExpression accessExpr0 = getFirstExpr(access); if (accessExpr0.equals(getFirstExpr(a2))) { VariableReferenceExpression varRef = new VariableReferenceExpression(a2.getVariables().get(0)); varRef.setSourceLocation(accessExpr0.getSourceLocation()); access.getExpressions().get(0).setValue(varRef); return true; } else { return false; } }
@Override public ILogicalOperator visitAssignOperator(AssignOperator op, ILogicalOperator arg) throws AlgebricksException { AssignOperator opCopy = new AssignOperator(deepCopyVariableList(op.getVariables()), exprDeepCopyVisitor.deepCopyExpressionReferenceList(op.getExpressions())); deepCopyInputsAnnotationsAndExecutionMode(op, arg, opCopy); return opCopy; }
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return false; } // Computes FDs and equivalence classes for the operator. PhysicalOptimizationsUtil.computeFDsAndEquivalenceClasses(op, context); AssignOperator assignOp = (AssignOperator) op; List<LogicalVariable> vars = assignOp.getVariables(); List<Mutable<ILogicalExpression>> exprRefs = assignOp.getExpressions(); return addEquivalenceClassesForRecordConstructor(vars, exprRefs, assignOp, context); }
@Override public Void visitAssignOperator(AssignOperator op, Pair<LogicalVariable, LogicalVariable> pair) throws AlgebricksException { substAssignVariables(op.getVariables(), op.getExpressions(), pair); // Substitute variables stored in ordering property if (op.getExplicitOrderingProperty() != null) { List<OrderColumn> orderColumns = op.getExplicitOrderingProperty().getOrderColumns(); for (int i = 0; i < orderColumns.size(); i++) { OrderColumn oc = orderColumns.get(i); if (oc.getColumn().equals(pair.first)) { orderColumns.set(i, new OrderColumn(pair.second, oc.getOrder())); } } } substVarTypes(op, pair); return null; }
@Override public Void visitAssignOperator(AssignOperator op, Integer indent) throws AlgebricksException { addIndent(indent).append("assign ").append(str(op.getVariables())).append(" <- "); pprintExprList(op.getExpressions(), indent); return null; }