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 @@ -185,6 +185,28 @@ public void testPartialAggStatistics()
}
}

@Test
public void testPartialAggStatisticsGroupByPartKey()
{
try {
// CBO Statistics
getQueryRunner().execute("CREATE TABLE test_orders WITH (partitioned_by = ARRAY['ds']) AS " +
"SELECT orderkey, orderpriority, comment, custkey, '2020-09-01' as ds FROM orders where orderkey < 2000 ");

// collect HBO Statistics
String queryGBPartitionKey = "SELECT ds FROM test_orders group by ds";

Plan plan = plan(queryGBPartitionKey, createSession("always"));

assertTrue(PlanNodeSearcher.searchFrom(plan.getRoot())
.where(node -> node instanceof AggregationNode && ((AggregationNode) node).getStep() == AggregationNode.Step.PARTIAL).findFirst().isPresent());
executeAndTrackHistory(queryGBPartitionKey, createSession("always"));
}
finally {
getQueryRunner().execute("DROP TABLE IF EXISTS test_orders");
}
}

@Override
protected void assertPlan(@Language("SQL") String query, PlanMatchPattern pattern)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ private PartialAggregationStatistics constructAggregationNodeStatistics(PlanNode
PlanNodeStats childNodeStats = planNodeStatsMap.get(childNode.getId());
if (childNodeStats != null) {
double partialAggregationInputBytes = adjustedOutputBytes(childNode, childNodeStats);
return new PartialAggregationStatistics(Estimate.of(partialAggregationInputBytes),
Estimate.of(outputBytes),
return new PartialAggregationStatistics(
Copy link
Contributor

@pranjalssh pranjalssh Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a method Estimate.estimateFromDouble which does this. Current naming is terrible as we have methods like Estimate.of as well. We can change these names to be more explicit of what they do and use right methods.

Double.isNaN(partialAggregationInputBytes) ? Estimate.unknown() : Estimate.of(partialAggregationInputBytes),
Double.isNaN(outputBytes) ? Estimate.unknown() : Estimate.of(outputBytes),
Estimate.of(childNodeStats.getPlanNodeOutputPositions()),
Estimate.of(outputPositions));
}
Expand Down