Apache DataFusion SQL Query Engine
Minor: Add SQL example for `date_bin` (#13390)
Andrew Lamb042843ad249f
diff --git a/datafusion/functions/src/datetime/date_bin.rs b/datafusion/functions/src/datetime/date_bin.rsindex 065201e1ca..82481f9fff 100644--- a/datafusion/functions/src/datetime/date_bin.rs+++ b/datafusion/functions/src/datetime/date_bin.rs@@ -181,6 +181,30 @@ Calculates time intervals and returns the start of the interval nearest to the sFor example, if you "bin" or "window" data into 15 minute intervals, an input timestamp of `2023-01-01T18:18:18Z` will be updated to the start time of the 15 minute bin it is in: `2023-01-01T18:15:00Z`."#).with_syntax_example("date_bin(interval, expression, origin-timestamp)")+ .with_sql_example(r#"```sql+-- Bin the timestamp into 1 day intervals+> SELECT date_bin(interval '1 day', time) as bin+FROM VALUES ('2023-01-01T18:18:18Z'), ('2023-01-03T19:00:03Z') t(time);++---------------------++| bin |++---------------------++| 2023-01-01T00:00:00 |+| 2023-01-03T00:00:00 |++---------------------++2 row(s) fetched.++-- Bin the timestamp into 1 day intervals starting at 3AM on 2023-01-01+> SELECT date_bin(interval '1 day', time, '2023-01-01T03:00:00') as bin+FROM VALUES ('2023-01-01T18:18:18Z'), ('2023-01-03T19:00:03Z') t(time);++---------------------++| bin |++---------------------++| 2023-01-01T03:00:00 |+| 2023-01-03T03:00:00 |++---------------------++2 row(s) fetched.+```+"#).with_argument("interval", "Bin interval.").with_argument("expression", "Time expression to operate on. Can be a constant, column, or function.").with_argument("origin-timestamp", "Optional. Starting point used to determine bin boundaries. If not specified defaults 1970-01-01T00:00:00Z (the UNIX epoch in UTC).diff --git a/docs/source/user-guide/sql/scalar_functions.md b/docs/source/user-guide/sql/scalar_functions.mdindex e9cd2bba7d..74e7285b76 100644--- a/docs/source/user-guide/sql/scalar_functions.md+++ b/docs/source/user-guide/sql/scalar_functions.md@@ -1954,6 +1954,32 @@ The following intervals are supported:- years- century+#### Example++```sql+-- Bin the timestamp into 1 day intervals+> SELECT date_bin(interval '1 day', time) as bin+FROM VALUES ('2023-01-01T18:18:18Z'), ('2023-01-03T19:00:03Z') t(time);++---------------------++| bin |++---------------------++| 2023-01-01T00:00:00 |+| 2023-01-03T00:00:00 |++---------------------++2 row(s) fetched.++-- Bin the timestamp into 1 day intervals starting at 3AM on 2023-01-01+> SELECT date_bin(interval '1 day', time, '2023-01-01T03:00:00') as bin+FROM VALUES ('2023-01-01T18:18:18Z'), ('2023-01-03T19:00:03Z') t(time);++---------------------++| bin |++---------------------++| 2023-01-01T03:00:00 |+| 2023-01-03T03:00:00 |++---------------------++2 row(s) fetched.+```+### `date_format`_Alias of [to_char](#to_char)._