Search in sources :

Example 1 with ILangExpression

use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.

the class AQLFormatPrintUtil method toString.

public static String toString(List<ILangExpression> exprs) throws CompilationException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PrintWriter output = new PrintWriter(bos);
    AQLFormatPrintVisitor visitor = new AQLFormatPrintVisitor(output);
    for (ILangExpression expr : exprs) {
        expr.accept(visitor, 0);
    }
    output.close();
    return bos.toString();
}
Also used : ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AQLFormatPrintVisitor(org.apache.asterix.lang.aql.visitor.AQLFormatPrintVisitor) PrintWriter(java.io.PrintWriter)

Example 2 with ILangExpression

use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.

the class AqlBuiltinFunctionRewriteVisitor method visit.

@Override
public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
    FunctionSignature functionSignature = callExpr.getFunctionSignature();
    callExpr.setFunctionSignature(CommonFunctionMapUtil.normalizeBuiltinFunctionSignature(functionSignature));
    List<Expression> newExprList = new ArrayList<>();
    for (Expression expr : callExpr.getExprList()) {
        newExprList.add(expr.accept(this, arg));
    }
    callExpr.setExprList(newExprList);
    return callExpr;
}
Also used : Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) ArrayList(java.util.ArrayList) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature)

Example 3 with ILangExpression

use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.

the class SqlppCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(NestClause nestClause, VariableSubstitutionEnvironment env) throws CompilationException {
    VariableExpr rightVar = nestClause.getRightVariable();
    VariableExpr newRightVar = generateNewVariable(context, rightVar);
    VariableExpr newRightPosVar = nestClause.hasPositionalVariable() ? generateNewVariable(context, nestClause.getPositionalVariable()) : null;
    // Visits the right expression.
    Expression rightExpr = (Expression) nestClause.getRightExpression().accept(this, env).first;
    // Visits the condition.
    VariableSubstitutionEnvironment currentEnv = new VariableSubstitutionEnvironment(env);
    currentEnv.removeSubstitution(newRightVar);
    if (newRightPosVar != null) {
        currentEnv.removeSubstitution(newRightPosVar);
    }
    // The condition can refer to the newRightVar and newRightPosVar.
    Expression conditionExpr = (Expression) nestClause.getConditionExpression().accept(this, currentEnv).first;
    NestClause newJoinClause = new NestClause(nestClause.getJoinType(), rightExpr, newRightVar, newRightPosVar, conditionExpr);
    return new Pair<>(newJoinClause, currentEnv);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) NestClause(org.apache.asterix.lang.sqlpp.clause.NestClause) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 4 with ILangExpression

use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.

the class SqlppCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FromClause fromClause, VariableSubstitutionEnvironment env) throws CompilationException {
    VariableSubstitutionEnvironment currentEnv = new VariableSubstitutionEnvironment(env);
    List<FromTerm> newFromTerms = new ArrayList<>();
    for (FromTerm fromTerm : fromClause.getFromTerms()) {
        Pair<ILangExpression, VariableSubstitutionEnvironment> p = fromTerm.accept(this, currentEnv);
        newFromTerms.add((FromTerm) p.first);
        // A right from term could be correlated from a left from term,
        // therefore we propagate the substitution environment.
        currentEnv = p.second;
    }
    return new Pair<>(new FromClause(newFromTerms), currentEnv);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) FromClause(org.apache.asterix.lang.sqlpp.clause.FromClause) ArrayList(java.util.ArrayList) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) FromTerm(org.apache.asterix.lang.sqlpp.clause.FromTerm) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Example 5 with ILangExpression

use of org.apache.asterix.lang.common.base.ILangExpression in project asterixdb by apache.

the class SqlppCloneAndSubstituteVariablesVisitor method visit.

@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FromTerm fromTerm, VariableSubstitutionEnvironment env) throws CompilationException {
    VariableExpr leftVar = fromTerm.getLeftVariable();
    VariableExpr newLeftVar = generateNewVariable(context, leftVar);
    VariableExpr newLeftPosVar = fromTerm.hasPositionalVariable() ? generateNewVariable(context, fromTerm.getPositionalVariable()) : null;
    Expression newLeftExpr = (Expression) visitUnnesBindingExpression(fromTerm.getLeftExpression(), env).first;
    List<AbstractBinaryCorrelateClause> newCorrelateClauses = new ArrayList<>();
    VariableSubstitutionEnvironment currentEnv = new VariableSubstitutionEnvironment(env);
    currentEnv.removeSubstitution(newLeftVar);
    if (newLeftPosVar != null) {
        currentEnv.removeSubstitution(newLeftPosVar);
    }
    for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
        if (correlateClause.getClauseType() == ClauseType.UNNEST_CLAUSE) {
            // The right-hand-side of unnest could be correlated with the left side,
            // therefore we propagate the substitution environment of the left-side.
            Pair<ILangExpression, VariableSubstitutionEnvironment> p = correlateClause.accept(this, currentEnv);
            currentEnv = p.second;
            newCorrelateClauses.add((AbstractBinaryCorrelateClause) p.first);
        } else {
            // The right-hand-side of join and nest could not be correlated with the left side,
            // therefore we propagate the original substitution environment.
            newCorrelateClauses.add((AbstractBinaryCorrelateClause) correlateClause.accept(this, env).first);
            // Join binding variables should be removed for further traversal.
            currentEnv.removeSubstitution(correlateClause.getRightVariable());
            if (correlateClause.hasPositionalVariable()) {
                currentEnv.removeSubstitution(correlateClause.getPositionalVariable());
            }
        }
    }
    return new Pair<>(new FromTerm(newLeftExpr, newLeftVar, newLeftPosVar, newCorrelateClauses), currentEnv);
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) AbstractBinaryCorrelateClause(org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) ArrayList(java.util.ArrayList) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) FromTerm(org.apache.asterix.lang.sqlpp.clause.FromTerm) Pair(org.apache.hyracks.algebricks.common.utils.Pair)

Aggregations

ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)56 Expression (org.apache.asterix.lang.common.base.Expression)34 Pair (org.apache.hyracks.algebricks.common.utils.Pair)34 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)28 ArrayList (java.util.ArrayList)23 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)23 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)18 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)18 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)16 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)15 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)9 LetClause (org.apache.asterix.lang.common.clause.LetClause)8 HashMap (java.util.HashMap)5 VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)5 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)4 CallExpr (org.apache.asterix.lang.common.expression.CallExpr)4 FromClause (org.apache.asterix.lang.sqlpp.clause.FromClause)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintWriter (java.io.PrintWriter)3 FLWOGRExpression (org.apache.asterix.lang.aql.expression.FLWOGRExpression)3