Search in sources :

Example 6 with VariableExpr

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());
    }
}
Also used : LetClause(org.apache.asterix.lang.common.clause.LetClause) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) HashSet(java.util.HashSet)

Example 7 with VariableExpr

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;
}
Also used : VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) FreeVariableVisitor(org.apache.asterix.lang.sqlpp.visitor.FreeVariableVisitor) HashSet(java.util.HashSet)

Example 8 with VariableExpr

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());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Identifier(org.apache.asterix.lang.common.struct.Identifier) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) GroupbyClause(org.apache.asterix.lang.common.clause.GroupbyClause) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 9 with VariableExpr

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;
}
Also used : ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 10 with VariableExpr

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;
}
Also used : AbstractBinaryCorrelateClause(org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Aggregations

VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)59 Expression (org.apache.asterix.lang.common.base.Expression)35 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)29 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)20 ArrayList (java.util.ArrayList)19 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)18 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)17 Pair (org.apache.hyracks.algebricks.common.utils.Pair)16 VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)13 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)12 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)11 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)11 HashSet (java.util.HashSet)9 HashMap (java.util.HashMap)8 LetClause (org.apache.asterix.lang.common.clause.LetClause)8 Identifier (org.apache.asterix.lang.common.struct.Identifier)8 ForClause (org.apache.asterix.lang.aql.clause.ForClause)7 GroupbyClause (org.apache.asterix.lang.common.clause.GroupbyClause)7 FromTerm (org.apache.asterix.lang.sqlpp.clause.FromTerm)6 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)6