use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class FreeVariableVisitor method visitLetClauses.
private void visitLetClauses(List<LetClause> letClauses, Collection<VariableExpr> freeVars) throws CompilationException {
if (letClauses == null || letClauses.isEmpty()) {
return;
}
Collection<VariableExpr> bindingVars = new HashSet<>();
for (LetClause letClause : letClauses) {
Collection<VariableExpr> letFreeVars = new HashSet<>();
letClause.accept(this, letFreeVars);
// Removes previous binding variables.
letFreeVars.removeAll(bindingVars);
freeVars.addAll(letFreeVars);
// Adds let binding variables into the binding variable collection.
bindingVars.add(letClause.getVarExpr());
}
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class SqlppVariableUtil method getFreeVariables.
public static Collection<VariableExpr> getFreeVariables(ILangExpression langExpr) throws CompilationException {
Collection<VariableExpr> freeVars = new HashSet<>();
FreeVariableVisitor visitor = new FreeVariableVisitor();
langExpr.accept(visitor, freeVars);
return freeVars;
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class DeepCopyVisitor method visit.
@Override
public GroupbyClause visit(GroupbyClause gc, Void arg) throws CompilationException {
List<GbyVariableExpressionPair> gbyPairList = new ArrayList<>();
List<GbyVariableExpressionPair> decorPairList = new ArrayList<>();
Map<Expression, VariableExpr> withVarMap = new HashMap<>();
VariableExpr groupVarExpr = null;
List<Pair<Expression, Identifier>> groupFieldList = new ArrayList<>();
for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) {
VariableExpr var = gbyVarExpr.getVar();
gbyPairList.add(new GbyVariableExpressionPair(var == null ? null : (VariableExpr) var.accept(this, arg), (Expression) gbyVarExpr.getExpr().accept(this, arg)));
}
for (GbyVariableExpressionPair gbyVarExpr : gc.getDecorPairList()) {
VariableExpr var = gbyVarExpr.getVar();
decorPairList.add(new GbyVariableExpressionPair(var == null ? null : (VariableExpr) var.accept(this, arg), (Expression) gbyVarExpr.getExpr().accept(this, arg)));
}
for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
withVarMap.put((Expression) entry.getKey().accept(this, arg), (VariableExpr) entry.getValue().accept(this, arg));
}
if (gc.hasGroupVar()) {
groupVarExpr = (VariableExpr) gc.getGroupVar().accept(this, arg);
}
for (Pair<Expression, Identifier> field : gc.getGroupFieldList()) {
groupFieldList.add(new Pair<>((Expression) field.first.accept(this, arg), field.second));
}
return new GroupbyClause(gbyPairList, decorPairList, withVarMap, groupVarExpr, groupFieldList, gc.hasHashGroupByHint(), gc.isGroupAll());
}
use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(InsertStatement insertStatement, ILangExpression arg) throws CompilationException {
scopeChecker.createNewScope();
// Visits the body query.
insertStatement.getQuery().accept(this, insertStatement);
// Registers the (inserted) data item variable.
VariableExpr bindingVar = insertStatement.getVar();
if (bindingVar != null) {
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), bindingVar.getVar());
}
// Visits the expression for the returning expression.
Expression returningExpr = insertStatement.getReturnExpression();
if (returningExpr != null) {
insertStatement.setReturnExpression(visit(returningExpr, insertStatement));
}
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(FromTerm fromTerm, ILangExpression arg) throws CompilationException {
scopeChecker.createNewScope();
// Visit the left expression of a from term.
fromTerm.setLeftExpression(visit(fromTerm.getLeftExpression(), fromTerm));
// Registers the data item variable.
VariableExpr leftVar = fromTerm.getLeftVariable();
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), leftVar.getVar());
// Registers the positional variable
if (fromTerm.hasPositionalVariable()) {
VariableExpr posVar = fromTerm.getPositionalVariable();
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), posVar.getVar());
}
// Visits join/unnest/nest clauses.
for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
correlateClause.accept(this, fromTerm);
}
return null;
}
Aggregations