private Map<Expression, Identifier> getGroupFieldVariables(GroupbyClause groupbyClause) { return groupbyClause.hasGroupFieldList() ? SqlppVariableUtil.createFieldVariableMap(groupbyClause.getGroupFieldList()) : Collections.emptyMap(); }
@Override public Void visit(GroupbyClause gc, Void arg) throws CompilationException { for (GbyVariableExpressionPair p : gc.getGbyPairList()) { p.getExpr().accept(this, arg); } if (gc.hasDecorList()) { for (GbyVariableExpressionPair p : gc.getDecorPairList()) { p.getExpr().accept(this, arg); } } if (gc.hasGroupFieldList()) { for (Pair<Expression, Identifier> p : gc.getGroupFieldList()) { p.first.accept(this, arg); } } if (gc.hasWithMap()) { for (Map.Entry<Expression, VariableExpr> me : gc.getWithVarMap().entrySet()) { me.getKey().accept(this, arg); } } return null; }
@Override public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(GroupbyClause gc, VariableSubstitutionEnvironment env) throws CompilationException { VariableSubstitutionEnvironment newSubs = env; List<GbyVariableExpressionPair> newGbyList = VariableCloneAndSubstitutionUtil.substInVarExprPair(context, gc.getGbyPairList(), newSubs, this); List<GbyVariableExpressionPair> newDecorList = gc.hasDecorList() ? VariableCloneAndSubstitutionUtil.substInVarExprPair(context, gc.getDecorPairList(), newSubs, this) : new ArrayList<>(); VariableExpr newGroupVar = null; if (gc.hasGroupVar()) { newGroupVar = generateNewVariable(context, gc.getGroupVar()); } Map<Expression, VariableExpr> newWithMap = new HashMap<>(); if (gc.hasWithMap()) { for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) { Expression newKeyVar = (Expression) entry.getKey().accept(this, env).first; VariableExpr newValueVar = generateNewVariable(context, entry.getValue()); newWithMap.put(newKeyVar, newValueVar); } } List<Pair<Expression, Identifier>> newGroupFieldList = gc.hasGroupFieldList() ? VariableCloneAndSubstitutionUtil.substInFieldList(gc.getGroupFieldList(), env, this) : null; GroupbyClause newGroup = new GroupbyClause(newGbyList, newDecorList, newWithMap, newGroupVar, newGroupFieldList, gc.hasHashGroupByHint(), gc.isGroupAll()); newGroup.setSourceLocation(gc.getSourceLocation()); return new Pair<>(newGroup, newSubs); }
@Override public Void visit(GroupbyClause gc, Void arg) throws CompilationException { for (GbyVariableExpressionPair p : gc.getGbyPairList()) { p.getExpr().accept(this, arg); } if (gc.hasDecorList()) { for (GbyVariableExpressionPair p : gc.getDecorPairList()) { p.getExpr().accept(this, arg); } } if (gc.hasGroupFieldList()) { for (Pair<Expression, Identifier> p : gc.getGroupFieldList()) { p.first.accept(this, arg); } } if (gc.hasWithMap()) { for (Map.Entry<Expression, VariableExpr> me : gc.getWithVarMap().entrySet()) { me.getKey().accept(this, arg); } } return null; }
private void rewriteSelectWithGroupBy(SelectBlock selectBlock, ILangExpression arg) throws CompilationException { GroupbyClause gbyClause = selectBlock.getGroupbyClause(); // Sets the group variable. if (!gbyClause.hasGroupVar()) { VariableExpr groupVar = new VariableExpr(context.newVariable()); groupVar.setSourceLocation(gbyClause.getSourceLocation()); gbyClause.setGroupVar(groupVar); } // Sets the field list for the group variable. List<Pair<Expression, Identifier>> groupFieldList; if (gbyClause.hasGroupFieldList()) { groupFieldList = new ArrayList<>(); for (Pair<Expression, Identifier> groupField : gbyClause.getGroupFieldList()) { Expression newFieldExpr = groupField.first.accept(this, arg); groupFieldList.add(new Pair<>(newFieldExpr, groupField.second)); } } else { groupFieldList = createGroupFieldList(selectBlock); } gbyClause.setGroupFieldList(groupFieldList); }
out.print(skip(step + 1) + "GROUP AS "); gc.getGroupVar().accept(this, 0); if (gc.hasGroupFieldList()) { printFieldList(step + 1, gc.getGroupFieldList());
@Override public Void visit(GroupbyClause gc, Collection<VariableExpr> freeVars) throws CompilationException { // Puts all group-by variables into the symbol set of the new scope. for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) { gbyVarExpr.getExpr().accept(this, freeVars); } if (gc.hasDecorList()) { for (GbyVariableExpressionPair decorVarExpr : gc.getDecorPairList()) { decorVarExpr.getExpr().accept(this, freeVars); } } if (gc.hasGroupFieldList()) { for (Pair<Expression, Identifier> groupField : gc.getGroupFieldList()) { groupField.first.accept(this, freeVars); } } if (gc.hasWithMap()) { for (Expression expr : gc.getWithVarMap().keySet()) { expr.accept(this, freeVars); } } return null; }
@Override public Boolean visit(GroupbyClause gc, ILangExpression arg) throws CompilationException { for (GbyVariableExpressionPair key : gc.getGbyPairList()) { if (visit(key.getExpr(), arg)) { return true; } } if (gc.hasDecorList()) { for (GbyVariableExpressionPair key : gc.getDecorPairList()) { if (visit(key.getExpr(), arg)) { return true; } } } if (gc.hasGroupFieldList() && visitFieldList(gc.getGroupFieldList(), arg)) { return true; } if (gc.hasWithMap() && visitExprList(gc.getWithVarMap().keySet(), arg)) { return true; } return false; }
if (gc.hasGroupFieldList()) { for (Pair<Expression, Identifier> gbyField : gc.getGroupFieldList()) { gbyField.first = visit(gbyField.first, arg);
@Override public Boolean visit(GroupbyClause gc, List<FunctionDecl> arg) throws CompilationException { Pair<Boolean, List<GbyVariableExpressionPair>> p1 = inlineUdfsInGbyPairList(gc.getGbyPairList(), arg); gc.setGbyPairList(p1.second); boolean changed = p1.first; if (gc.hasDecorList()) { Pair<Boolean, List<GbyVariableExpressionPair>> p2 = inlineUdfsInGbyPairList(gc.getDecorPairList(), arg); gc.setDecorPairList(p2.second); changed |= p2.first; } if (gc.hasGroupFieldList()) { Pair<Boolean, List<Pair<Expression, Identifier>>> p3 = inlineUdfsInFieldList(gc.getGroupFieldList(), arg); gc.setGroupFieldList(p3.second); changed |= p3.first; } if (gc.hasWithMap()) { Pair<Boolean, Map<Expression, VariableExpr>> p4 = inlineUdfsInVarMap(gc.getWithVarMap(), arg); gc.setWithVarMap(p4.second); changed |= p4.first; } return changed; }