Search in sources :

Example 6 with FLWOGRExpression

use of org.apache.asterix.lang.aql.expression.FLWOGRExpression in project asterixdb by apache.

the class AQLCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FLWOGRExpression flwor, VariableSubstitutionEnvironment env) throws CompilationException {
    List<Clause> newClauses = new ArrayList<Clause>(flwor.getClauseList().size());
    VariableSubstitutionEnvironment currentEnv = env;
    for (Clause c : flwor.getClauseList()) {
        Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = c.accept(this, currentEnv);
        currentEnv = p1.second;
        newClauses.add((Clause) p1.first);
    }
    Pair<ILangExpression, VariableSubstitutionEnvironment> p2 = flwor.getReturnExpr().accept(this, currentEnv);
    Expression newReturnExpr = (Expression) p2.first;
    FLWOGRExpression newFlwor = new FLWOGRExpression(newClauses, newReturnExpr);
    return new Pair<ILangExpression, VariableSubstitutionEnvironment>(newFlwor, p2.second);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) ArrayList(java.util.ArrayList) FLWOGRExpression(org.apache.asterix.lang.aql.expression.FLWOGRExpression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) ForClause(org.apache.asterix.lang.aql.clause.ForClause) DistinctClause(org.apache.asterix.lang.aql.clause.DistinctClause) Clause(org.apache.asterix.lang.common.base.Clause) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 7 with FLWOGRExpression

use of org.apache.asterix.lang.aql.expression.FLWOGRExpression 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)

Aggregations

ForClause (org.apache.asterix.lang.aql.clause.ForClause)7 FLWOGRExpression (org.apache.asterix.lang.aql.expression.FLWOGRExpression)7 Clause (org.apache.asterix.lang.common.base.Clause)7 DistinctClause (org.apache.asterix.lang.aql.clause.DistinctClause)6 Expression (org.apache.asterix.lang.common.base.Expression)6 ArrayList (java.util.ArrayList)4 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)4 LetClause (org.apache.asterix.lang.common.clause.LetClause)3 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)2 GroupbyClause (org.apache.asterix.lang.common.clause.GroupbyClause)2 WhereClause (org.apache.asterix.lang.common.clause.WhereClause)2 List (java.util.List)1 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)1 CallExpr (org.apache.asterix.lang.common.expression.CallExpr)1 LiteralExpr (org.apache.asterix.lang.common.expression.LiteralExpr)1 StringLiteral (org.apache.asterix.lang.common.literal.StringLiteral)1 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)1 Query (org.apache.asterix.lang.common.statement.Query)1 Identifier (org.apache.asterix.lang.common.struct.Identifier)1 VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)1