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); }
gbc.setWithVarMap(new HashMap<Expression, VariableExpr>()); gbc.setGroupVar(groupVar); gbc.setGroupFieldList(groupFieldList); replaceCurrentScope(newScope); {if (true) return addSourceLocation(gbc, startToken);}
@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; }