Skip to content

Commit

Permalink
Add AggregationNode.hasSingleGlobalAggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-stec authored and sopel39 committed Oct 12, 2022
1 parent 9134586 commit a844763
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
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;
}

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

0 comments on commit a844763

Please sign in to comment.