Skip to content

Commit

Permalink
Issue duckdb#14366: SUMMARIZE Temporal Types
Browse files Browse the repository at this point in the history
Add AVG to the SUMMARIZE statistics for all temporal types.
  • Loading branch information
hawkfish committed Jan 27, 2025
1 parent 24b79f8 commit 56f5de5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/planner/binder/statement/bind_summarize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,14 @@ unique_ptr<BoundTableRef> Binder::BindSummarize(ShowRef &ref) {
max_children.push_back(SummarizeCreateAggregate("max", plan.names[i]));
unique_children.push_back(make_uniq<CastExpression>(
LogicalType::BIGINT, SummarizeCreateAggregate("approx_count_distinct", plan.names[i])));
if (plan.types[i].IsNumeric()) {
if (plan.types[i].IsNumeric() || plan.types[i].IsTemporal()) {
avg_children.push_back(SummarizeCreateAggregate("avg", plan.names[i]));
std_children.push_back(SummarizeCreateAggregate("stddev", plan.names[i]));
} else {
avg_children.push_back(make_uniq<ConstantExpression>(Value()));
}
if (plan.types[i].IsNumeric()) {
std_children.push_back(SummarizeCreateAggregate("stddev", plan.names[i]));
} else {
std_children.push_back(make_uniq<ConstantExpression>(Value()));
}
if (plan.types[i].IsNumeric() || plan.types[i].IsTemporal()) {
Expand Down
6 changes: 3 additions & 3 deletions test/sql/show_select/test_summarize.test
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ query IIIIIIIIIIII
summarize
from range('2024-01-01'::TIMESTAMP, '2024-04-10'::TIMESTAMP, INTERVAL 1 DAY);
----
range TIMESTAMP 2024-01-01 00:00:00 2024-04-09 00:00:00 99 NULL NULL 2024-01-25 12:00:00 2024-02-19 12:00:00 2024-03-15 12:00:00 100 0.00
range TIMESTAMP 2024-01-01 00:00:00 2024-04-09 00:00:00 99 2024-02-19 12:00:00 NULL 2024-01-25 12:00:00 2024-02-19 12:00:00 2024-03-15 12:00:00 100 0.00

query IIIIIIIIIIII
summarize
SELECT range::DATE AS range from range('2024-01-01'::DATE, '2024-04-10'::DATE, INTERVAL 1 DAY);
----
range DATE 2024-01-01 2024-04-09 98 NULL NULL 2024-01-26 2024-02-19 2024-03-16 100 0.00
range DATE 2024-01-01 2024-04-09 98 2024-02-19 12:00:00 NULL 2024-01-26 2024-02-19 2024-03-16 100 0.00

query IIIIIIIIIIII
summarize
SELECT range::TIME AS range from range('2024-01-01'::DATE, '2024-04-10'::DATE, INTERVAL 1 HOUR);
----
range TIME 00:00:00 23:00:00 28 NULL NULL 05:24:35.480769 11:28:55.400975 17:30:41.666667 2400 0.00
range TIME 00:00:00 23:00:00 28 11:30:00 NULL 05:24:35.480769 11:28:55.400975 17:30:41.666667 2400 0.00

statement ok
SUMMARIZE VALUES (1.0),(6754950520);
Expand Down

0 comments on commit 56f5de5

Please sign in to comment.