use of org.apache.asterix.lang.common.context.Scope in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(FromClause fromClause, ILangExpression arg) throws CompilationException {
Scope scopeForFromClause = scopeChecker.extendCurrentScope();
for (FromTerm fromTerm : fromClause.getFromTerms()) {
fromTerm.accept(this, fromClause);
// Merges the variables defined in the current from term into the scope of the current from clause.
Scope scopeForFromTerm = scopeChecker.removeCurrentScope();
mergeScopes(scopeForFromClause, scopeForFromTerm);
}
return null;
}
use of org.apache.asterix.lang.common.context.Scope in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(SelectSetOperation selectSetOperation, ILangExpression arg) throws CompilationException {
Scope scopeBeforeCurrentBranch = scopeChecker.getCurrentScope();
scopeChecker.createNewScope();
selectSetOperation.getLeftInput().accept(this, arg);
if (selectSetOperation.hasRightInputs()) {
for (SetOperationRight right : selectSetOperation.getRightInputs()) {
// Exit scopes that were entered within a previous select expression
while (scopeChecker.getCurrentScope() != scopeBeforeCurrentBranch) {
scopeChecker.removeCurrentScope();
}
scopeChecker.createNewScope();
right.getSetOperationRightInput().accept(this, arg);
}
// Exit scopes that were entered within the last branch of the set operation.
while (scopeChecker.getCurrentScope() != scopeBeforeCurrentBranch) {
scopeChecker.removeCurrentScope();
}
}
return null;
}
use of org.apache.asterix.lang.common.context.Scope 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.context.Scope 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.context.Scope in project asterixdb by apache.
the class ScopeChecker method extendCurrentScopeNoPush.
public final Scope extendCurrentScopeNoPush(boolean maskParentScope) {
Scope scope = scopeStack.peek();
scope = new Scope(this, scope, maskParentScope);
return scope;
}
Aggregations