@Override public Pair<ILogicalOperator, LogicalVariable> visit(VariableExpr v, Mutable<ILogicalOperator> tupSource) throws CompilationException { // Should we ever get to this method? ILogicalExpression oldVRef = translateVariableRef(v); LogicalVariable var = context.newVar(); AssignOperator a = new AssignOperator(var, new MutableObject<>(oldVRef)); a.getInputs().add(tupSource); a.setSourceLocation(v.getSourceLocation()); return new Pair<>(a, var); }
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); } } } } }
/** * 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; } }
@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 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()); } } }
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; }
for (int i = 0; i < assigns.size(); i++) { AssignOperator assign = assigns.get(i); for (int j = 0; j < assign.getVariables().size(); j++) { if (var != assign.getVariables().get(j)) { continue; if (assign.getExpressions().get(j).getValue() .getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) { continue; simFuncExprRef = assign.getExpressions().get(j); new AssignOperator(newVar, new MutableObject<ILogicalExpression>(simCheckFuncExpr)); newAssign.setSourceLocation(sourceLoc); newAssign.getInputs() .add(new MutableObject<ILogicalOperator>(matchingAssign.getInputs().get(0).getValue())); matchingAssign.getInputs().get(0).setValue(newAssign);
throws AlgebricksException { AssignOperator assign = (AssignOperator) op; List<LogicalVariable> variables = assign.getVariables(); List<Mutable<ILogicalExpression>> expressions = assign.getExpressions(); int[] outColumns = new int[variables.size()]; for (int i = 0; i < outColumns.length; i++) { runtime.setSourceLocation(assign.getSourceLocation()); ILogicalOperator src = assign.getInputs().get(0).getValue(); builder.contributeGraphEdge(src, 0, assign, 0);
AssignOperator newAssign = new AssignOperator(assignVars, assignExprs); newAssign.getInputs().add(new MutableObject<ILogicalOperator>(joinInputOp)); newAssign.setExecutionMode(joinOp.getExecutionMode()); joinOp.getInputs().get(inputIndex).setValue(newAssign); context.computeAndSetTypeEnvironmentForOperator(newAssign);
private static void byNameToByHandle(AssignOperator fieldAccessOp, IOptimizationContext context) { Mutable<ILogicalOperator> opUnder = fieldAccessOp.getInputs().get(0); AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) fieldAccessOp.getExpressions().get(0).getValue(); ILogicalExpression a1 = fce.getArguments().get(0).getValue(); SourceLocation sourceLoc = fieldAccessOp.getSourceLocation(); ArrayList<Mutable<ILogicalExpression>> exprArray = new ArrayList<Mutable<ILogicalExpression>>(1); exprArray.add(new MutableObject<ILogicalExpression>(a1)); AssignOperator assignVar = new AssignOperator(varArray, exprArray); assignVar.setSourceLocation(sourceLoc); x = new VariableReferenceExpression(var1); x.setSourceLocation(sourceLoc); assignVar.getInputs().add(opUnder); opUnder = new MutableObject<ILogicalOperator>(assignVar); new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.TYPE_OF)); typeOf.getArguments().add(new MutableObject<ILogicalExpression>(x)); AssignOperator typAssign = new AssignOperator(t, new MutableObject<ILogicalExpression>(typeOf)); typAssign.setSourceLocation(sourceLoc); typAssign.getInputs().add(opUnder); AssignOperator handleAssign = new AssignOperator(w, new MutableObject<ILogicalExpression>(getHandle)); handleAssign.setSourceLocation(sourceLoc); handleAssign.getInputs().add(new MutableObject<ILogicalOperator>(typAssign)); wRef.setSourceLocation(sourceLoc); getData.getArguments().add(new MutableObject<ILogicalExpression>(wRef)); fieldAccessOp.getExpressions().get(0).setValue(getData); List<Mutable<ILogicalOperator>> faInputs = fieldAccessOp.getInputs();
private LogicalVariable createAssignment(ILogicalExpression expr, TranslationContext tCtx) { if (expr.getExpressionTag() == LogicalExpressionTag.VARIABLE) { return ((VariableReferenceExpression) expr).getVariableReference(); } LogicalVariable result = newLogicalVariable(); AssignOperator aOp = new AssignOperator(result, mutable(expr)); aOp.getInputs().add(mutable(tCtx.op)); tCtx.op = aOp; return result; }
private AssignOperator createAssignOperator(List<IOptimizableFuncExpr> optFuncExprs, List<LogicalVariable> minFilterVars, List<LogicalVariable> maxFilterVars, IOptimizationContext context, SourceLocation sourceLoc) { List<LogicalVariable> assignKeyVarList = new ArrayList<>(); List<Mutable<ILogicalExpression>> assignKeyExprList = new ArrayList<>(); for (IOptimizableFuncExpr optFuncExpr : optFuncExprs) { ComparisonKind ck = AlgebricksBuiltinFunctions.getComparisonType(optFuncExpr.getFuncExpr().getFunctionIdentifier()); ILogicalExpression searchKeyExpr = optFuncExpr.getConstantExpr(0); LogicalVariable var = context.newVar(); assignKeyExprList.add(new MutableObject<>(searchKeyExpr)); assignKeyVarList.add(var); if (ck == ComparisonKind.GE || ck == ComparisonKind.GT) { minFilterVars.add(var); } else if (ck == ComparisonKind.LE || ck == ComparisonKind.LT) { maxFilterVars.add(var); } else if (ck == ComparisonKind.EQ) { minFilterVars.add(var); maxFilterVars.add(var); } } AssignOperator assignOp = new AssignOperator(assignKeyVarList, assignKeyExprList); assignOp.setSourceLocation(sourceLoc); return assignOp; }
@Override public Void visitAssignOperator(AssignOperator op, IOptimizationContext context) throws AlgebricksException { visitAssignment(op, op.getExpressions(), context); return null; }
for (LogicalVariable var : assignOp.getVariables()) { VariableReferenceExpression varRef = new VariableReferenceExpression(var); varRef.setSourceLocation(assignOp.getSourceLocation()); additionalFilteringExpressions.add(new MutableObject<ILogicalExpression>(varRef)); assignOp.getInputs().add(new MutableObject<>(dataSourceScanOp.getInputs().get(0).getValue())); dataSourceScanOp.getInputs().get(0).setValue(assignOp); for (LogicalVariable var : assignOp.getVariables()) { VariableReferenceExpression varRef = new VariableReferenceExpression(var); varRef.setSourceLocation(assignOp.getSourceLocation()); additionalFilteringExpressions.add(new MutableObject<ILogicalExpression>(varRef)); assignOp.getInputs().add(new MutableObject<>(unnestMapOp.getInputs().get(0).getValue())); unnestMapOp.getInputs().get(0).setValue(assignOp);
@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 Long visitAssignOperator(AssignOperator op, Void arg) throws AlgebricksException { return op.getInputs().get(0).getValue().accept(this, arg); }
AssignOperator assign = (AssignOperator) op2; DataSourceScanOperator opNew = new DataSourceScanOperator(assign.getVariables(), ds); opNew.getInputs().addAll(assign.getInputs()); opRef2.setValue(opNew); return true;
Mutable<ILogicalOperator> topChild = topOp.getInputs().get(0); List<Mutable<ILogicalOperator>> a2InptList = a2.getInputs(); a2InptList.clear(); a2InptList.add(topChild); throw new CompilationException(ErrorCode.COMPILATION_ERROR, a2.getSourceLocation(), "Field access " + getFirstExpr(a2) + " does not correspond to any input");
private AssignOperator getAssignOperator(LogicalVariable unnestVariable, LogicalVariable outputVariable, IFunctionInfo inputFunction) { List<Mutable<ILogicalExpression>> nodeArgs = new ArrayList<Mutable<ILogicalExpression>>(); nodeArgs.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(unnestVariable))); ScalarFunctionCallExpression unctionExpression = new ScalarFunctionCallExpression(inputFunction, nodeArgs); Mutable<ILogicalExpression> nodeTreeIdExpression = new MutableObject<ILogicalExpression>(unctionExpression); return new AssignOperator(outputVariable, nodeTreeIdExpression); }
@Override public Void visitAssignOperator(AssignOperator op, Void arg) throws AlgebricksException { producedVariables.addAll(op.getVariables()); return null; }