@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; }
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 Expression visit(LetClause letClause, ILangExpression arg) throws CompilationException { letClause.setBindingExpr(visit(letClause.getBindingExpr(), letClause)); return null; }
@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()); }
final public Clause LetClause() throws ParseException, ParseException { LetClause lc = new LetClause(); VariableExpr varExp; Expression beExp; extendCurrentScope(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LET: jj_consume_token(LET); break; case WITH: jj_consume_token(WITH); break; default: jj_la1[103] = jj_gen; jj_consume_token(-1); throw new ParseException(); } varExp = Variable(); jj_consume_token(ASSIGN); beExp = Expression(); getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); lc.setVarExpr(varExp); lc.setBindingExpr(beExp); {if (true) return lc;} throw new Error("Missing return statement in function"); }
final public LetClause LetElement() throws ParseException, ParseException { VariableExpr varExp; Expression beExp; extendCurrentScope(); varExp = Variable(); jj_consume_token(EQ); beExp = Expression(); LetClause lc = new LetClause(varExp, beExp); lc.setSourceLocation(varExp.getSourceLocation()); {if (true) return lc;} throw new Error("Missing return statement in function"); }
@Override public Void visit(LetClause lc, Void arg) throws CompilationException { lc.getBindingExpr().accept(this, arg); return null; }
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 introduceLetClauses(List<Pair<Expression, VarIdentifier>> fromBindingList, List<AbstractClause> toLetWhereList) { for (Pair<Expression, VarIdentifier> p : fromBindingList) { Expression bindExpr = p.first; VarIdentifier var = p.second; VariableExpr varExpr = new VariableExpr(var); varExpr.setSourceLocation(bindExpr.getSourceLocation()); toLetWhereList.add(new LetClause(varExpr, bindExpr)); context.addExcludedForFieldAccessVar(var); } fromBindingList.clear(); }
@Override public Void visit(SelectExpression selectStatement, Integer step) throws CompilationException { if (selectStatement.isSubquery()) { out.print("("); } int selectStep = selectStatement.isSubquery() ? step + 2 : step; if (selectStatement.hasLetClauses()) { for (LetClause letClause : selectStatement.getLetList()) { letClause.accept(this, selectStep); } } selectStatement.getSelectSetOperation().accept(this, selectStep); if (selectStatement.hasOrderby()) { selectStatement.getOrderbyClause().accept(this, selectStep); } if (selectStatement.hasLimit()) { selectStatement.getLimitClause().accept(this, selectStep); } if (selectStatement.isSubquery()) { out.print(skip(step) + " )"); } 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; }
final public Clause LetClause() throws ParseException, ParseException { LetClause lc = new LetClause(); VariableExpr varExp; Expression beExp; extendCurrentScope(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LET: jj_consume_token(LET); break; case WITH: jj_consume_token(WITH); break; default: jj_la1[33] = jj_gen; jj_consume_token(-1); throw new ParseException(); } varExp = Variable(); jj_consume_token(ASSIGN); beExp = Expression(); getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); lc.setVarExpr(varExp); lc.setBindingExpr(beExp); {if (true) return lc;} throw new Error("Missing return statement in function"); }
@Override public Boolean visit(LetClause lc, List<FunctionDecl> arg) throws CompilationException { Pair<Boolean, Expression> p = inlineUdfsInExpr(lc.getBindingExpr(), arg); lc.setBindingExpr(p.second); return p.first; }
final public LetClause WithElement() throws ParseException, ParseException { VariableExpr varExp; Expression beExp; extendCurrentScope(); varExp = Variable(); jj_consume_token(AS); beExp = Expression(); LetClause lc = new LetClause(varExp, beExp); lc.setSourceLocation(varExp.getSourceLocation()); {if (true) return lc;} throw new Error("Missing return statement in function"); }
@Override public Void visit(LetClause lc, Void arg) throws CompilationException { lc.getBindingExpr().accept(this, arg); return null; }
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)); } } }
private void wrapInLets() { // If the top expression of the main statement is not a FLWOR, it wraps // it into a let clause. if (topStatement == null) { return; } Expression body = topStatement.getBody(); if (body.getKind() != Kind.FLWOGR_EXPRESSION) { VarIdentifier var = context.newVariable(); VariableExpr v = new VariableExpr(var); LetClause c1 = new LetClause(v, body); ArrayList<Clause> clauseList = new ArrayList<>(1); clauseList.add(c1); FLWOGRExpression newBody = new FLWOGRExpression(clauseList, new VariableExpr(var)); topStatement.setBody(newBody); } }
@Override public SelectExpression visit(SelectExpression selectExpression, Void arg) throws CompilationException { List<LetClause> lets = new ArrayList<>(); SelectSetOperation select; OrderbyClause orderby = null; LimitClause limit = null; // visit let list if (selectExpression.hasLetClauses()) { for (LetClause letClause : selectExpression.getLetList()) { lets.add((LetClause) letClause.accept(this, arg)); } } // visit the main select. select = (SelectSetOperation) selectExpression.getSelectSetOperation().accept(this, arg); // visit order by if (selectExpression.hasOrderby()) { orderby = (OrderbyClause) selectExpression.getOrderbyClause().accept(this, arg); } // visit limit if (selectExpression.hasLimit()) { limit = (LimitClause) selectExpression.getLimitClause().accept(this, arg); } SelectExpression copy = new SelectExpression(lets, select, orderby, limit, selectExpression.isSubquery()); copy.addHints(selectExpression.getHints()); return copy; }
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; }
@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)); }