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;
}
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());
}
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);
}
}
}
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;
}
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);
}
}
}
Aggregations