@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);
}