Search in sources :

Example 11 with VarIdentifier

use of org.apache.asterix.lang.common.struct.VarIdentifier in project asterixdb by apache.

the class AqlQueryRewriter method wrapInLets.

private void wrapInLets() {
    // it into a let clause.
    if (topStatement == null) {
        return;
    }
    Expression body = topStatement.getBody();
    if (body.getKind() != Kind.FLWOGR_EXPRESSION) {
        VarIdentifier var = context.newVariable();
        VariableExpr v = new VariableExpr(var);
        LetClause c1 = new LetClause(v, body);
        ArrayList<Clause> clauseList = new ArrayList<>(1);
        clauseList.add(c1);
        FLWOGRExpression newBody = new FLWOGRExpression(clauseList, new VariableExpr(var));
        topStatement.setBody(newBody);
    }
}
Also used : LetClause(org.apache.asterix.lang.common.clause.LetClause) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) Expression(org.apache.asterix.lang.common.base.Expression) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) ArrayList(java.util.ArrayList) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) ForClause(org.apache.asterix.lang.aql.clause.ForClause) DistinctClause(org.apache.asterix.lang.aql.clause.DistinctClause) GroupbyClause(org.apache.asterix.lang.common.clause.GroupbyClause) LetClause(org.apache.asterix.lang.common.clause.LetClause) Clause(org.apache.asterix.lang.common.base.Clause)

Example 12 with VarIdentifier

use of org.apache.asterix.lang.common.struct.VarIdentifier in project asterixdb by apache.

the class AbstractSqlppExpressionScopingVisitor method visit.

@Override
public Expression visit(VariableExpr varExpr, ILangExpression arg) throws CompilationException {
    String varName = varExpr.getVar().getValue();
    if (scopeChecker.isInForbiddenScopes(varName)) {
        throw new CompilationException("Inside limit clauses, it is disallowed to reference a variable having the same name as any variable bound in the same scope as the limit clause.");
    }
    Identifier ident = scopeChecker.lookupSymbol(varName);
    if (ident != null) {
        // Exists such an identifier, then this is a variable reference instead of a variable
        // definition.
        varExpr.setIsNewVar(false);
        varExpr.setVar((VarIdentifier) ident);
    }
    return varExpr;
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) Identifier(org.apache.asterix.lang.common.struct.Identifier) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)

Example 13 with VarIdentifier

use of org.apache.asterix.lang.common.struct.VarIdentifier 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 14 with VarIdentifier

use of org.apache.asterix.lang.common.struct.VarIdentifier in project asterixdb by apache.

the class VariableCheckAndRewriteVisitor method rewriteNeeded.

// Whether a rewrite is needed for a variable reference expression.
private boolean rewriteNeeded(VariableExpr varExpr) throws CompilationException {
    String varName = varExpr.getVar().getValue();
    Identifier ident = scopeChecker.lookupSymbol(varName);
    if (ident != null) {
        // Exists such an identifier
        varExpr.setIsNewVar(false);
        varExpr.setVar((VarIdentifier) ident);
        return false;
    } else {
        // Meets a undefined variable
        return overwrite;
    }
}
Also used : VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) Identifier(org.apache.asterix.lang.common.struct.Identifier)

Example 15 with VarIdentifier

use of org.apache.asterix.lang.common.struct.VarIdentifier 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)

Aggregations

VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)15 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)10 Expression (org.apache.asterix.lang.common.base.Expression)6 ArrayList (java.util.ArrayList)5 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)4 FunctionDecl (org.apache.asterix.lang.common.statement.FunctionDecl)4 Identifier (org.apache.asterix.lang.common.struct.Identifier)4 HashMap (java.util.HashMap)3 LetClause (org.apache.asterix.lang.common.clause.LetClause)3 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)3 Pair (org.apache.hyracks.algebricks.common.utils.Pair)3 CompilationException (org.apache.asterix.common.exceptions.CompilationException)2 DistinctClause (org.apache.asterix.lang.aql.clause.DistinctClause)2 ForClause (org.apache.asterix.lang.aql.clause.ForClause)2 FLWOGRExpression (org.apache.asterix.lang.aql.expression.FLWOGRExpression)2 Clause (org.apache.asterix.lang.common.base.Clause)2 IParser (org.apache.asterix.lang.common.base.IParser)2 Statement (org.apache.asterix.lang.common.base.Statement)2 GroupbyClause (org.apache.asterix.lang.common.clause.GroupbyClause)2 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)2