Search in sources :

Example 51 with VariableExpr

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

the class ExpressionToVariableUtil method getGeneratedVariable.

/**
     * Generates a variable according to an expression.
     *
     * @param expr
     *            the input expression.
     * @param raiseError,
     *            if it is not possible to generate a variable from the input expression,
     *            to raise the error if true, and to return a null if false.
     * @return the generated variable.
     * @throws ParseException
     */
public static VariableExpr getGeneratedVariable(Expression expr, boolean raiseError) throws ParseException {
    try {
        String varName = getGeneratedIdentifier(expr);
        VarIdentifier var = new VarIdentifier(varName);
        VariableExpr varExpr = new VariableExpr();
        varExpr.setVar(var);
        return varExpr;
    } catch (ParseException e) {
        if (raiseError) {
            throw e;
        }
        return null;
    }
}
Also used : VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) ParseException(org.apache.asterix.lang.sqlpp.parser.ParseException)

Example 52 with VariableExpr

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

the class DeepCopyVisitor method visit.

@Override
public QuantifiedExpression visit(QuantifiedExpression qe, Void arg) throws CompilationException {
    List<QuantifiedPair> quantifiedPairs = new ArrayList<>();
    for (QuantifiedPair pair : qe.getQuantifiedList()) {
        Expression expr = (Expression) pair.getExpr().accept(this, arg);
        VariableExpr var = (VariableExpr) pair.getVarExpr().accept(this, arg);
        quantifiedPairs.add(new QuantifiedPair(var, expr));
    }
    Expression condition = (Expression) qe.getSatisfiesExpr().accept(this, arg);
    return new QuantifiedExpression(qe.getQuantifier(), quantifiedPairs, condition);
}
Also used : QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) 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) ArrayList(java.util.ArrayList) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 53 with VariableExpr

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

the class DeepCopyVisitor method visit.

@Override
public FromTerm visit(FromTerm fromTerm, Void arg) throws CompilationException {
    // Visit the left expression of a from term.
    Expression fromExpr = (Expression) fromTerm.getLeftExpression().accept(this, arg);
    VariableExpr fromVar = (VariableExpr) fromTerm.getLeftVariable().accept(this, arg);
    VariableExpr positionVar = fromTerm.getPositionalVariable() == null ? null : (VariableExpr) fromTerm.getPositionalVariable().accept(this, arg);
    // Visits join/unnest/nest clauses.
    List<AbstractBinaryCorrelateClause> correlateClauses = new ArrayList<>();
    for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
        correlateClauses.add((AbstractBinaryCorrelateClause) correlateClause.accept(this, arg));
    }
    return new FromTerm(fromExpr, fromVar, positionVar, correlateClauses);
}
Also used : AbstractBinaryCorrelateClause(org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause) 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) ArrayList(java.util.ArrayList) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) FromTerm(org.apache.asterix.lang.sqlpp.clause.FromTerm)

Example 54 with VariableExpr

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

the class DeepCopyVisitor method visit.

@Override
public VariableExpr visit(VariableExpr varExpr, Void arg) throws CompilationException {
    VariableExpr clonedVar = new VariableExpr(new VarIdentifier(varExpr.getVar()));
    clonedVar.setIsNewVar(varExpr.getIsNewVar());
    return clonedVar;
}
Also used : VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr)

Example 55 with VariableExpr

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

the class SqlppVariableUtil method getBindingVariables.

public static Collection<VariableExpr> getBindingVariables(FromTerm fromTerm) {
    List<VariableExpr> bindingVars = new ArrayList<>();
    if (fromTerm == null) {
        return bindingVars;
    }
    bindingVars.add(fromTerm.getLeftVariable());
    if (fromTerm.hasPositionalVariable()) {
        bindingVars.add(fromTerm.getPositionalVariable());
    }
    for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
        bindingVars.add(correlateClause.getRightVariable());
        if (correlateClause.hasPositionalVariable()) {
            bindingVars.add(correlateClause.getPositionalVariable());
        }
    }
    return bindingVars;
}
Also used : AbstractBinaryCorrelateClause(org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause) ArrayList(java.util.ArrayList) 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