Search in sources :

Example 1 with GbyVariableExpressionPair

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

the class SqlppAstPrintVisitor method visit.

@Override
public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
    if (gc.isGroupAll()) {
        out.println(skip(step) + "Group All");
        return null;
    }
    out.println(skip(step) + "Groupby");
    for (GbyVariableExpressionPair pair : gc.getGbyPairList()) {
        if (pair.getVar() != null) {
            pair.getVar().accept(this, step + 1);
            out.println(skip(step + 1) + ":=");
        }
        pair.getExpr().accept(this, step + 1);
    }
    if (gc.hasGroupVar()) {
        out.print(skip(step + 1) + "GROUP AS ");
        gc.getGroupVar().accept(this, 0);
        if (gc.hasGroupFieldList()) {
            out.println(skip(step + 1) + "(");
            for (Pair<Expression, Identifier> field : gc.getGroupFieldList()) {
                out.print(skip(step + 2) + field.second + ":=");
                field.first.accept(this, 0);
            }
            out.println(skip(step + 1) + ")");
        }
    }
    out.println();
    return null;
}
Also used : Identifier(org.apache.asterix.lang.common.struct.Identifier) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)

Example 2 with GbyVariableExpressionPair

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

the class DeepCopyVisitor method visit.

@Override
public GroupbyClause visit(GroupbyClause gc, Void arg) throws CompilationException {
    List<GbyVariableExpressionPair> gbyPairList = new ArrayList<>();
    List<GbyVariableExpressionPair> decorPairList = new ArrayList<>();
    Map<Expression, VariableExpr> withVarMap = new HashMap<>();
    VariableExpr groupVarExpr = null;
    List<Pair<Expression, Identifier>> groupFieldList = new ArrayList<>();
    for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) {
        VariableExpr var = gbyVarExpr.getVar();
        gbyPairList.add(new GbyVariableExpressionPair(var == null ? null : (VariableExpr) var.accept(this, arg), (Expression) gbyVarExpr.getExpr().accept(this, arg)));
    }
    for (GbyVariableExpressionPair gbyVarExpr : gc.getDecorPairList()) {
        VariableExpr var = gbyVarExpr.getVar();
        decorPairList.add(new GbyVariableExpressionPair(var == null ? null : (VariableExpr) var.accept(this, arg), (Expression) gbyVarExpr.getExpr().accept(this, arg)));
    }
    for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
        withVarMap.put((Expression) entry.getKey().accept(this, arg), (VariableExpr) entry.getValue().accept(this, arg));
    }
    if (gc.hasGroupVar()) {
        groupVarExpr = (VariableExpr) gc.getGroupVar().accept(this, arg);
    }
    for (Pair<Expression, Identifier> field : gc.getGroupFieldList()) {
        groupFieldList.add(new Pair<>((Expression) field.first.accept(this, arg), field.second));
    }
    return new GroupbyClause(gbyPairList, decorPairList, withVarMap, groupVarExpr, groupFieldList, gc.hasHashGroupByHint(), gc.isGroupAll());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Identifier(org.apache.asterix.lang.common.struct.Identifier) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) GroupbyClause(org.apache.asterix.lang.common.clause.GroupbyClause) 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) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 3 with GbyVariableExpressionPair

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

the class SqlppFormatPrintVisitor method printDelimitedGbyExpressions.

@Override
protected void printDelimitedGbyExpressions(List<GbyVariableExpressionPair> gbyList, int step) throws CompilationException {
    int gbySize = gbyList.size();
    int gbyIndex = 0;
    for (GbyVariableExpressionPair pair : gbyList) {
        pair.getExpr().accept(this, step);
        if (pair.getVar() != null) {
            out.print(" as ");
            pair.getVar().accept(this, step);
        }
        if (++gbyIndex < gbySize) {
            out.print(COMMA);
        }
    }
}
Also used : GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)

Example 4 with GbyVariableExpressionPair

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

the class VariableCloneAndSubstitutionUtil method substInVarExprPair.

public static List<GbyVariableExpressionPair> substInVarExprPair(LangRewritingContext context, List<GbyVariableExpressionPair> gbyVeList, VariableSubstitutionEnvironment newSubs, CloneAndSubstituteVariablesVisitor visitor) throws CompilationException {
    VariableSubstitutionEnvironment subs = newSubs;
    List<GbyVariableExpressionPair> veList = new LinkedList<>();
    for (GbyVariableExpressionPair vep : gbyVeList) {
        VariableExpr oldGbyVar = vep.getVar();
        VariableExpr newGbyVar = null;
        if (oldGbyVar != null) {
            newGbyVar = visitor.generateNewVariable(context, oldGbyVar);
            subs = eliminateSubstFromList(newGbyVar, subs);
        }
        Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = vep.getExpr().accept(visitor, subs);
        GbyVariableExpressionPair ve2 = new GbyVariableExpressionPair(newGbyVar, (Expression) p1.first);
        veList.add(ve2);
    }
    return veList;
}
Also used : VariableSubstitutionEnvironment(org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) LinkedList(java.util.LinkedList)

Example 5 with GbyVariableExpressionPair

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

the class FormatPrintVisitor method printDelimitedGbyExpressions.

protected void printDelimitedGbyExpressions(List<GbyVariableExpressionPair> gbyList, int step) throws CompilationException {
    int gbySize = gbyList.size();
    int gbyIndex = 0;
    for (GbyVariableExpressionPair pair : gbyList) {
        if (pair.getVar() != null) {
            pair.getVar().accept(this, step);
            out.print(assignSymbol);
        }
        pair.getExpr().accept(this, step);
        if (++gbyIndex < gbySize) {
            out.print(COMMA);
        }
    }
}
Also used : GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)

Aggregations

GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)16 Expression (org.apache.asterix.lang.common.base.Expression)9 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)9 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)8 ArrayList (java.util.ArrayList)7 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)6 Identifier (org.apache.asterix.lang.common.struct.Identifier)5 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)5 HashMap (java.util.HashMap)4 GroupbyClause (org.apache.asterix.lang.common.clause.GroupbyClause)4 QuantifiedPair (org.apache.asterix.lang.common.struct.QuantifiedPair)3 VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)3 Pair (org.apache.hyracks.algebricks.common.utils.Pair)3 LetClause (org.apache.asterix.lang.common.clause.LetClause)2 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)2 SelectClause (org.apache.asterix.lang.sqlpp.clause.SelectClause)2 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)2 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1