Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AggregationNode.hasSingleGlobalAggregation #14559

Merged
merged 1 commit into from
Oct 12, 2022
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;
sopel39 marked this conversation as resolved.
Show resolved Hide resolved
}

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