public static List<VariableExpr> getLetBindingVariables(List<? extends AbstractClause> clauses) { List<VariableExpr> bindingVars = new ArrayList<>(); if (clauses == null || clauses.isEmpty()) { return bindingVars; } for (AbstractClause clause : clauses) { if (clause.getClauseType() == Clause.ClauseType.LET_CLAUSE) { LetClause letClause = (LetClause) clause; bindingVars.add(letClause.getVarExpr()); } } return bindingVars; }
private void getLetBindings(List<AbstractClause> clauses, List<FieldBinding> outFieldBindings, Set<String> outFieldNames) throws CompilationException { for (AbstractClause clause : clauses) { if (clause.getClauseType() == ClauseType.LET_CLAUSE) { LetClause letClause = (LetClause) clause; outFieldBindings.add(getFieldBinding(letClause.getVarExpr(), outFieldNames)); } } }
@Override public boolean equals(Object object) { if (this == object) { return true; } if (!(object instanceof LetClause)) { return false; } LetClause target = (LetClause) object; return bindExpr.equals(target.getBindingExpr()) && varExpr.equals(target.getVarExpr()); }
private void visitLetWhereClauses(List<? extends AbstractClause> clauseList, Collection<VariableExpr> freeVars) throws CompilationException { if (clauseList == null || clauseList.isEmpty()) { return; } Collection<VariableExpr> bindingVars = new HashSet<>(); for (AbstractClause clause : clauseList) { Collection<VariableExpr> clauseFreeVars = new HashSet<>(); clause.accept(this, clauseFreeVars); // Removes previous binding variables. clauseFreeVars.removeAll(bindingVars); freeVars.addAll(clauseFreeVars); // Adds let binding variables into the binding variable collection. if (clause.getClauseType() == ClauseType.LET_CLAUSE) { bindingVars.add(((LetClause) clause).getVarExpr()); } } }
@Override public Void visit(LetClause lc, Integer step) throws CompilationException { out.print(skip(step) + "with "); lc.getVarExpr().accept(this, step + 2); out.print(" as "); Expression bindingExpr = lc.getBindingExpr(); bindingExpr.accept(this, step + 2); out.println(); return null; }
@Override public Void visit(LetClause lc, Integer step) throws CompilationException { out.print(skip(step) + "with "); Expression bindingExpr = lc.getBindingExpr(); bindingExpr.accept(this, step + 2); out.print(" as "); lc.getVarExpr().accept(this, step + 2); out.println(); return null; }
@Override public Void visit(LetClause lc, Integer step) throws CompilationException { out.print(skip(step) + "let "); lc.getVarExpr().accept(this, 0); out.print(assignSymbol); lc.getBindingExpr().accept(this, step + 1); out.println(); return null; }
private void visitLetClause(LetClause lc, Integer step, boolean startLet, boolean hasConsequentLet) throws CompilationException { if (startLet) { out.print(skip(step) + "with "); } else { out.print(skip(step + 3)); } lc.getVarExpr().accept(this, step + 3); out.print(" as "); lc.getBindingExpr().accept(this, step + 3); if (hasConsequentLet) { out.print(COMMA); } out.println(); }
private Map<VariableExpr, Expression> extractLetBindingVariables(List<Clause> clauses, GroupbyClause cuttingGbyClause) throws CompilationException { Map<VariableExpr, Expression> varExprMap = new HashMap<VariableExpr, Expression>(); int gbyIndex = clauses.indexOf(cuttingGbyClause); for (int i = gbyIndex + 1; i < clauses.size(); i++) { Clause cl = clauses.get(i); if (cl.getClauseType() == ClauseType.LET_CLAUSE) { LetClause letClause = (LetClause) cl; // inline let variables one by one iteratively. letClause.setBindingExpr((Expression) AQLVariableSubstitutionUtil .substituteVariable(letClause.getBindingExpr(), varExprMap)); varExprMap.put(letClause.getVarExpr(), letClause.getBindingExpr()); } } return varExprMap; }
private Map<Expression, Expression> extractLetBindingVariableExpressionMappings(List<LetClause> letClauses) throws CompilationException { Map<Expression, Expression> varExprMap = new HashMap<>(); for (LetClause lc : letClauses) { // inline let variables one by one iteratively. lc.setBindingExpr(SqlppRewriteUtil.substituteExpression(lc.getBindingExpr(), varExprMap, context)); varExprMap.put(lc.getVarExpr(), lc.getBindingExpr()); } return varExprMap; } }
@Override public Void visit(LetClause lc, Integer step) throws CompilationException { out.print(skip(step) + "Let "); lc.getVarExpr().accept(this, 0); out.println(skip(step + 1) + ":="); lc.getBindingExpr().accept(this, step + 1); return null; }
@Override public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(LetClause lc, VariableSubstitutionEnvironment env) throws CompilationException { Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = lc.getBindingExpr().accept(this, env); VariableExpr varExpr = lc.getVarExpr(); VariableExpr newVe = generateNewVariable(context, varExpr); LetClause newLet = new LetClause(newVe, (Expression) p1.first); newLet.setSourceLocation(lc.getSourceLocation()); return new Pair<>(newLet, VariableCloneAndSubstitutionUtil.eliminateSubstFromList(lc.getVarExpr(), env)); }
private Map<VariableExpr, Expression> extractDefinedCollectionVariables(List<Clause> clauses, GroupbyClause cuttingGbyClause, String generatedAlias) { Map<VariableExpr, Expression> varExprMap = new HashMap<VariableExpr, Expression>(); List<VariableExpr> varToSubstitute = collectProducedVariablesFromGroupby(cuttingGbyClause); int gbyIndex = clauses.indexOf(cuttingGbyClause); for (int i = gbyIndex + 1; i < clauses.size(); i++) { Clause cl = clauses.get(i); if (cl.getClauseType() == ClauseType.LET_CLAUSE) { varToSubstitute.add(((LetClause) cl).getVarExpr()); } } for (VariableExpr var : varToSubstitute) { varExprMap.put(var, new FieldAccessor(new VariableExpr(new VarIdentifier(generatedAlias)), new VarIdentifier(var.getVar().getValue().substring(1)))); } return varExprMap; }
varExprMap.put(letClause.getVarExpr(), bindingExpr);
@Override public LetClause visit(LetClause letClause, Void arg) throws CompilationException { LetClause copy = new LetClause((VariableExpr) letClause.getVarExpr().accept(this, arg), (Expression) letClause.getBindingExpr().accept(this, arg)); copy.setSourceLocation(letClause.getSourceLocation()); return copy; }
@Override public Expression visit(LetClause letClause, ILangExpression arg) throws CompilationException { scopeChecker.extendCurrentScope(); letClause.setBindingExpr(visit(letClause.getBindingExpr(), letClause)); VariableExpr varExpr = letClause.getVarExpr(); addNewVarSymbolToScope(scopeChecker.getCurrentScope(), varExpr.getVar(), varExpr.getSourceLocation()); return null; }
@Override public Pair<ILogicalOperator, LogicalVariable> visit(LetClause lc, Mutable<ILogicalOperator> tupSource) throws CompilationException { LogicalVariable v; AssignOperator returnedOp; Expression bindingExpr = lc.getBindingExpr(); SourceLocation sourceLoc = bindingExpr.getSourceLocation(); if (bindingExpr.getKind() == Kind.VARIABLE_EXPRESSION) { VariableExpr bindingVarExpr = (VariableExpr) bindingExpr; ILogicalExpression prevVarRef = translateVariableRef(bindingVarExpr); v = context.newVarFromExpression(lc.getVarExpr()); returnedOp = new AssignOperator(v, new MutableObject<>(prevVarRef)); returnedOp.getInputs().add(tupSource); returnedOp.setSourceLocation(sourceLoc); } else { v = context.newVarFromExpression(lc.getVarExpr()); Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(bindingExpr, tupSource); returnedOp = new AssignOperator(v, new MutableObject<>(eo.first)); returnedOp.getInputs().add(eo.second); returnedOp.setSourceLocation(sourceLoc); } return new Pair<>(returnedOp, v); }
freeVariablesInClause.removeAll(visibleVarsInCurrentScope); freeVariablesInGbyLets.addAll(freeVariablesInClause); visibleVarsInCurrentScope.add(letClause.getVarExpr()); break; case HAVING_CLAUSE: