Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ private static boolean isGlobalAggregation(PlanNode node)
}

AggregationNode aggregationNode = (AggregationNode) node;
return aggregationNode.hasEmptyGroupingSet() &&
aggregationNode.getGroupingSetCount() == 1 &&
return aggregationNode.hasSingleGlobalAggregation() &&
aggregationNode.getStep() == SINGLE;
Comment thread
sopel39 marked this conversation as resolved.
Outdated
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ private static boolean isGlobalAggregation(PlanNode node)
}

AggregationNode aggregationNode = (AggregationNode) node;
return aggregationNode.hasEmptyGroupingSet() &&
aggregationNode.getGroupingSetCount() == 1 &&
return aggregationNode.hasSingleGlobalAggregation() &&
aggregationNode.getStep() == SINGLE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public class RemoveEmptyGlobalAggregation
.matching(node ->
// no aggregate functions
node.getAggregations().isEmpty() &&
// global aggregation
node.hasEmptyGroupingSet() && node.getGroupingSetCount() == 1);
node.hasSingleGlobalAggregation());

@Override
public Pattern<AggregationNode> getPattern()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Range<Long> visitEnforceSingleRow(EnforceSingleRowNode node, Void context
@Override
public Range<Long> visitAggregation(AggregationNode node, Void context)
{
if (node.hasEmptyGroupingSet() && node.getGroupingSetCount() == 1) {
if (node.hasSingleGlobalAggregation()) {
// only single default aggregation which will produce exactly single row
return Range.singleton(1L);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ public GroupingSetDescriptor getGroupingSets()
return groupingSets;
}

/**
* @return true if the aggregation collapses all rows into a single global group (e.g., as a result of a GROUP BY () query).
* Otherwise, false.
*/
public boolean hasSingleGlobalAggregation()
{
return hasEmptyGroupingSet() && getGroupingSetCount() == 1;
}

/**
* @return whether this node should produce default output in case of no input pages.
* For example for query:
Expand Down