use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class VariableCloneAndSubstitutionUtil method visitAndCloneExprList.
public static List<Expression> visitAndCloneExprList(List<Expression> oldExprList, VariableSubstitutionEnvironment arg, CloneAndSubstituteVariablesVisitor visitor) throws CompilationException {
List<Expression> exprs = new ArrayList<>(oldExprList.size());
for (Expression e : oldExprList) {
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = e.accept(visitor, arg);
exprs.add((Expression) p1.first);
}
return exprs;
}
use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class AQLCloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FLWOGRExpression flwor, VariableSubstitutionEnvironment env) throws CompilationException {
List<Clause> newClauses = new ArrayList<Clause>(flwor.getClauseList().size());
VariableSubstitutionEnvironment currentEnv = env;
for (Clause c : flwor.getClauseList()) {
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = c.accept(this, currentEnv);
currentEnv = p1.second;
newClauses.add((Clause) p1.first);
}
Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = flwor.getReturnExpr().accept(this, currentEnv);
Expression newReturnExpr = (Expression) p2.first;
FLWOGRExpression newFlwor = new FLWOGRExpression(newClauses, newReturnExpr);
return new Pair<ILangExpression, VariableSubstitutionEnvironment>(newFlwor, p2.second);
}
use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class SqlppCloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(IndependentSubquery independentSubquery, VariableSubstitutionEnvironment env) throws CompilationException {
Pair<ILangExpression, VariableSubstitutionEnvironment> p = independentSubquery.getExpr().accept(this, env);
IndependentSubquery newSubquery = new IndependentSubquery((Expression) p.first);
return new Pair<>(newSubquery, p.second);
}
use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class SqlppCloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectBlock selectBlock, VariableSubstitutionEnvironment env) throws CompilationException {
Pair<ILangExpression, VariableSubstitutionEnvironment> newFrom = null;
Pair<ILangExpression, VariableSubstitutionEnvironment> newLet;
Pair<ILangExpression, VariableSubstitutionEnvironment> newWhere = null;
Pair<ILangExpression, VariableSubstitutionEnvironment> newGroupby = null;
Pair<ILangExpression, VariableSubstitutionEnvironment> newHaving = null;
Pair<ILangExpression, VariableSubstitutionEnvironment> newSelect;
List<LetClause> newLetClauses = new ArrayList<>();
List<LetClause> newLetClausesAfterGby = new ArrayList<>();
VariableSubstitutionEnvironment currentEnv = new VariableSubstitutionEnvironment(env);
if (selectBlock.hasFromClause()) {
newFrom = selectBlock.getFromClause().accept(this, currentEnv);
currentEnv = newFrom.second;
}
if (selectBlock.hasLetClauses()) {
for (LetClause letClause : selectBlock.getLetList()) {
newLet = letClause.accept(this, currentEnv);
currentEnv = newLet.second;
newLetClauses.add(letClause);
}
}
if (selectBlock.hasWhereClause()) {
newWhere = selectBlock.getWhereClause().accept(this, currentEnv);
currentEnv = newWhere.second;
}
if (selectBlock.hasGroupbyClause()) {
newGroupby = selectBlock.getGroupbyClause().accept(this, currentEnv);
currentEnv = newGroupby.second;
if (selectBlock.hasLetClausesAfterGroupby()) {
for (LetClause letClauseAfterGby : selectBlock.getLetListAfterGroupby()) {
newLet = letClauseAfterGby.accept(this, currentEnv);
currentEnv = newLet.second;
newLetClausesAfterGby.add(letClauseAfterGby);
}
}
}
if (selectBlock.hasHavingClause()) {
newHaving = selectBlock.getHavingClause().accept(this, currentEnv);
currentEnv = newHaving.second;
}
newSelect = selectBlock.getSelectClause().accept(this, currentEnv);
currentEnv = newSelect.second;
FromClause fromClause = newFrom == null ? null : (FromClause) newFrom.first;
WhereClause whereClause = newWhere == null ? null : (WhereClause) newWhere.first;
GroupbyClause groupbyClause = newGroupby == null ? null : (GroupbyClause) newGroupby.first;
HavingClause havingClause = newHaving == null ? null : (HavingClause) newHaving.first;
return new Pair<>(new SelectBlock((SelectClause) newSelect.first, fromClause, newLetClauses, whereClause, groupbyClause, newLetClausesAfterGby, havingClause), currentEnv);
}
use of org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment in project asterixdb by apache.
the class SqlppCloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(SelectExpression selectExpression, VariableSubstitutionEnvironment env) throws CompilationException {
boolean subquery = selectExpression.isSubquery();
List<LetClause> newLetList = new ArrayList<>();
SelectSetOperation newSelectSetOperation;
OrderbyClause newOrderbyClause = null;
LimitClause newLimitClause = null;
VariableSubstitutionEnvironment currentEnv = env;
Pair<ILangExpression, VariableSubstitutionEnvironment> p;
if (selectExpression.hasLetClauses()) {
for (LetClause letClause : selectExpression.getLetList()) {
p = letClause.accept(this, currentEnv);
newLetList.add(letClause);
currentEnv = p.second;
}
}
p = selectExpression.getSelectSetOperation().accept(this, env);
newSelectSetOperation = (SelectSetOperation) p.first;
currentEnv = p.second;
if (selectExpression.hasOrderby()) {
p = selectExpression.getOrderbyClause().accept(this, currentEnv);
newOrderbyClause = (OrderbyClause) p.first;
currentEnv = p.second;
}
if (selectExpression.hasLimit()) {
p = selectExpression.getLimitClause().accept(this, currentEnv);
newLimitClause = (LimitClause) p.first;
currentEnv = p.second;
}
return new Pair<>(new SelectExpression(newLetList, newSelectSetOperation, newOrderbyClause, newLimitClause, subquery), currentEnv);
}
Aggregations