List<SingleElementSymbol> groupingExpressions,
LinkedHashSet<AggregateSymbol> aggregates,
LinkedList<PlanNode> unionChildren, SymbolMap parentMap, CommandContext context, QueryMetadataInterface metadata, CapabilitiesFinder capFinder) throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
// remove the group node
groupNode.getParent().replaceChild(groupNode, groupNode.getFirstChild());
GroupSymbol group = sourceNode.getGroups().iterator().next().clone();
boolean first = true;
List<SingleElementSymbol> symbols = null;
for (PlanNode planNode : unionChildren) {
PlanNode groupClone = NodeFactory.getNewNode(NodeConstants.Types.GROUP);
groupClone.setProperty(Info.GROUP_COLS, LanguageObject.Util.deepClone(groupingExpressions, SingleElementSymbol.class));
groupClone.addGroups(groupNode.getGroups());
PlanNode view = RuleDecomposeJoin.createSource(group, planNode, parentMap);
view.addAsParent(groupClone);
PlanNode projectPlanNode = NodeFactory.getNewNode(NodeConstants.Types.PROJECT);
Select allSymbols = new Select(groupingExpressions);
allSymbols.addSymbols(aggregates);
if (first) {
first = false;
QueryRewriter.makeSelectUnique(allSymbols, false);
symbols = allSymbols.getSymbols();
}
projectPlanNode.setProperty(NodeConstants.Info.PROJECT_COLS, allSymbols.getSymbols());
projectPlanNode.addGroups(view.getGroups());
groupClone.addAsParent(projectPlanNode);
if (planNode.getType() == NodeConstants.Types.ACCESS) {
//TODO: temporarily remove the access node so that the inline view could be removed if possible
while (RuleRaiseAccess.raiseAccessNode(planNode, planNode, metadata, capFinder, true, null) != null) {
//continue to raise
}
}
}
GroupSymbol modifiedGroup = group.clone();
SymbolMap symbolMap = createSymbolMap(modifiedGroup, symbols, sourceNode, metadata);
sourceNode.setProperty(Info.SYMBOL_MAP, symbolMap);
FrameUtil.convertFrame(sourceNode, group, Collections.singleton(modifiedGroup), symbolMap.inserseMapping(), metadata);
}