use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(NestClause nestClause, ILangExpression arg) throws CompilationException {
// NOTE: the two branches of a NEST cannot be correlated, instead of
// checking the correlation here, we defer the check to the query
// optimizer.
nestClause.setRightExpression(visit(nestClause.getRightExpression(), nestClause));
// Registers the data item variable.
VariableExpr rightVar = nestClause.getRightVariable();
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), rightVar.getVar());
if (nestClause.hasPositionalVariable()) {
// Registers the positional variable.
VariableExpr posVar = nestClause.getPositionalVariable();
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), posVar.getVar());
}
// The condition expression can refer to the just registered variables
// for the right branch.
nestClause.setConditionExpression(visit(nestClause.getConditionExpression(), nestClause));
return null;
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(JoinClause joinClause, ILangExpression arg) throws CompilationException {
Scope leftScope = scopeChecker.removeCurrentScope();
scopeChecker.createNewScope();
// NOTE: the two join branches cannot be correlated, instead of checking
// the correlation here,
// we defer the check to the query optimizer.
joinClause.setRightExpression(visit(joinClause.getRightExpression(), joinClause));
// Registers the data item variable.
VariableExpr rightVar = joinClause.getRightVariable();
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), rightVar.getVar());
if (joinClause.hasPositionalVariable()) {
// Registers the positional variable.
VariableExpr posVar = joinClause.getPositionalVariable();
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), posVar.getVar());
}
Scope rightScope = scopeChecker.removeCurrentScope();
mergeScopes(leftScope, rightScope);
scopeChecker.pushExistingScope(leftScope);
// The condition expression can refer to the just registered variables
// for the right branch.
joinClause.setConditionExpression(visit(joinClause.getConditionExpression(), joinClause));
return null;
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(UnnestClause unnestClause, ILangExpression arg) throws CompilationException {
unnestClause.setRightExpression(visit(unnestClause.getRightExpression(), unnestClause));
// register the data item variable
VariableExpr rightVar = unnestClause.getRightVariable();
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), rightVar.getVar());
if (unnestClause.hasPositionalVariable()) {
// register the positional variable
VariableExpr posVar = unnestClause.getPositionalVariable();
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), posVar.getVar());
}
return null;
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class SqlppSubstituteExpressionVisitor method preVisit.
// Note: we intentionally override preVisit instead of postVisit because we wants larger expressions
// get substituted first if some of their child expressions are present as keys in the exprMap.
// An example is:
// asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/group-by/gby-expr-3/gby-expr-3.3.query.sqlpp
@Override
protected Expression preVisit(Expression expr) throws CompilationException {
Expression mappedExpr = exprMap.get(expr);
if (mappedExpr == null) {
return expr;
}
Collection<VariableExpr> freeVars = SqlppVariableUtil.getFreeVariables(expr);
for (VariableExpr freeVar : freeVars) {
Scope currentScope = scopeChecker.getCurrentScope();
if (currentScope.findSymbol(freeVar.getVar().getValue()) != null) {
// that is being visited, we shouldn't perform the substitution.
return expr;
}
}
// Makes a deep copy before returning to avoid shared references.
return (Expression) SqlppRewriteUtil.deepCopy(mappedExpr);
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class VariableCloneAndSubstitutionUtil method substInVarExprPair.
public static List<GbyVariableExpressionPair> substInVarExprPair(LangRewritingContext context, List<GbyVariableExpressionPair> gbyVeList, VariableSubstitutionEnvironment newSubs, CloneAndSubstituteVariablesVisitor visitor) throws CompilationException {
VariableSubstitutionEnvironment subs = newSubs;
List<GbyVariableExpressionPair> veList = new LinkedList<>();
for (GbyVariableExpressionPair vep : gbyVeList) {
VariableExpr oldGbyVar = vep.getVar();
VariableExpr newGbyVar = null;
if (oldGbyVar != null) {
newGbyVar = visitor.generateNewVariable(context, oldGbyVar);
subs = eliminateSubstFromList(newGbyVar, subs);
}
Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = vep.getExpr().accept(visitor, subs);
GbyVariableExpressionPair ve2 = new GbyVariableExpressionPair(newGbyVar, (Expression) p1.first);
veList.add(ve2);
}
return veList;
}
Aggregations