Search in sources :

Example 56 with VariableExpr

use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.

the class SqlppVariableUtil method getLiveVariables.

public static Set<VariableExpr> getLiveVariables(Scope scope, boolean includeWithVariables) {
    Set<VariableExpr> results = new HashSet<>();
    Set<VariableExpr> liveVars = scope.getLiveVariables();
    Iterator<VariableExpr> liveVarIter = liveVars.iterator();
    while (liveVarIter.hasNext()) {
        VariableExpr liveVar = liveVarIter.next();
        // ordered lists with UNION item type. Currently it is typed as [ANY].
        if (includeWithVariables || !liveVar.getVar().namedValueAccess()) {
            results.add(liveVar);
        }
    }
    return results;
}
Also used : VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) HashSet(java.util.HashSet)

Example 57 with VariableExpr

use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.

the class DeepCopyVisitor method visit.

@Override
public UnnestClause visit(UnnestClause unnestClause, Void arg) throws CompilationException {
    Expression rightExpression = (Expression) unnestClause.getRightExpression().accept(this, arg);
    VariableExpr rightVar = (VariableExpr) unnestClause.getRightVariable().accept(this, arg);
    VariableExpr rightPositionVar = unnestClause.getPositionalVariable() == null ? null : (VariableExpr) unnestClause.getPositionalVariable().accept(this, arg);
    return new UnnestClause(unnestClause.getJoinType(), rightExpression, rightVar, rightPositionVar);
}
Also used : 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) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) UnnestClause(org.apache.asterix.lang.sqlpp.clause.UnnestClause)

Example 58 with VariableExpr

use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.

the class FreeVariableVisitor method visit.

@Override
public Void visit(SelectExpression selectExpression, Collection<VariableExpr> freeVars) throws CompilationException {
    Collection<VariableExpr> letsFreeVars = new HashSet<>();
    Collection<VariableExpr> selectFreeVars = new HashSet<>();
    visitLetClauses(selectExpression.getLetList(), letsFreeVars);
    // visit order by
    if (selectExpression.hasOrderby()) {
        for (Expression orderExpr : selectExpression.getOrderbyClause().getOrderbyList()) {
            orderExpr.accept(this, selectFreeVars);
        }
    }
    // visit limit
    if (selectExpression.hasLimit()) {
        selectExpression.getLimitClause().accept(this, selectFreeVars);
    }
    // visit the main select
    selectExpression.getSelectSetOperation().accept(this, selectFreeVars);
    // Removed let binding variables.
    selectFreeVars.removeAll(SqlppVariableUtil.getBindingVariables(selectExpression.getLetList()));
    freeVars.addAll(letsFreeVars);
    freeVars.addAll(selectFreeVars);
    return null;
}
Also used : CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) 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) HashSet(java.util.HashSet)

Example 59 with VariableExpr

use of org.apache.asterix.lang.common.expression.VariableExpr in project asterixdb by apache.

the class FreeVariableVisitor method visit.

@Override
public Void visit(FromClause fromClause, Collection<VariableExpr> freeVars) throws CompilationException {
    Collection<VariableExpr> bindingVars = new HashSet<>();
    for (FromTerm fromTerm : fromClause.getFromTerms()) {
        Collection<VariableExpr> fromTermFreeVars = new HashSet<>();
        fromTerm.accept(this, fromTermFreeVars);
        // Since a right from term can refer to variables defined in a left from term,
        // we remove binding variables from the free variables.
        fromTermFreeVars.removeAll(bindingVars);
        // Adds binding variables.
        bindingVars.addAll(SqlppVariableUtil.getBindingVariables(fromTerm));
        // Adds into freeVars.
        freeVars.addAll(fromTermFreeVars);
    }
    return null;
}
Also used : VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) FromTerm(org.apache.asterix.lang.sqlpp.clause.FromTerm) HashSet(java.util.HashSet)

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