Skip to content

Commit

Permalink
Internal duckdb#2176: Temporal Standard Deviations
Browse files Browse the repository at this point in the history
Add STDDEV_XXX for temporal types to SUMMARIZE
  • Loading branch information
Richard Wesley committed May 31, 2024
1 parent 4a8d9b0 commit 1191129
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/planner/binder/statement/bind_summarize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,15 @@ 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()) {
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()) {
avg_children.push_back(SummarizeCreateAggregate("avg", plan.names[i]));
std_children.push_back(SummarizeCreateAggregate("stddev", plan.names[i]));
q25_children.push_back(SummarizeCreateAggregate("approx_quantile", plan.names[i], Value::FLOAT(0.25)));
q50_children.push_back(SummarizeCreateAggregate("approx_quantile", plan.names[i], Value::FLOAT(0.50)));
q75_children.push_back(SummarizeCreateAggregate("approx_quantile", plan.names[i], Value::FLOAT(0.75)));
} else {
avg_children.push_back(make_uniq<ConstantExpression>(Value()));
std_children.push_back(make_uniq<ConstantExpression>(Value()));
q25_children.push_back(make_uniq<ConstantExpression>(Value()));
q50_children.push_back(make_uniq<ConstantExpression>(Value()));
q75_children.push_back(make_uniq<ConstantExpression>(Value()));
Expand Down
8 changes: 4 additions & 4 deletions test/sql/show_select/test_summarize.test
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ 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 101 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
range TIMESTAMP 2024-01-01 00:00:00 2024-04-09 00:00:00 101 2024-02-19 12:00:00 696:16:32.906716 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 t::TIMESTAMPTZ AS range
from range('2024-01-01'::TIMESTAMP, '2024-04-10'::TIMESTAMP, INTERVAL 1 DAY) tbl(t);
----
range TIMESTAMP WITH TIME ZONE 2024-01-01 00:00:00+00 2024-04-09 00:00:00+00 101 2024-02-19 12:00:00+00 NULL 2024-01-25 12:00:00+00 2024-02-19 12:00:00+00 2024-03-15 12:00:00+00 100 0.00
range TIMESTAMP WITH TIME ZONE 2024-01-01 00:00:00+00 2024-04-09 00:00:00+00 101 2024-02-19 12:00:00+00 696:16:32.906716 2024-01-25 12:00:00+00 2024-02-19 12:00:00+00 2024-03-15 12:00: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 101 2024-02-19 12:00:00 NULL 2024-01-26 2024-02-19 2024-03-16 100 0.00
range DATE 2024-01-01 2024-04-09 101 2024-02-19 12:00:00 696:16:32.906716 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 24 11:30:00 NULL 05:24:35.480769 11:28:55.400975 17:30:41.666667 2400 0.00
range TIME 00:00:00 23:00:00 24 11:30:00 06:55:25.064851 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 1191129

Please sign in to comment.