You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use chrono::{DateTime,Datelike,Duration,Months,TimeDelta,Utc};
42
-
use datafusion_expr::scalar_doc_sections::DOC_SECTION_DATETIME;
43
43
44
+
#[user_doc(
45
+
doc_section(label = "Time and Date Functions"),
46
+
description = r#"
47
+
Calculates time intervals and returns the start of the interval nearest to the specified timestamp. Use `date_bin` to downsample time series data by grouping rows into time-based "bins" or "windows" and applying an aggregate or selector function to each window.
48
+
49
+
For 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`.
description = "Time expression to operate on. Can be a constant, column, or function."
79
+
),
80
+
argument(
81
+
name = "origin-timestamp",
82
+
description = r#"Optional. Starting point used to determine bin boundaries. If not specified defaults 1970-01-01T00:00:00Z (the UNIX epoch in UTC). The following intervals are supported:
83
+
84
+
- nanoseconds
85
+
- microseconds
86
+
- milliseconds
87
+
- seconds
88
+
- minutes
89
+
- hours
90
+
- days
91
+
- weeks
92
+
- months
93
+
- years
94
+
- century
95
+
"#
96
+
)
97
+
)]
44
98
#[derive(Debug)]
45
99
pubstructDateBinFunc{
46
100
signature:Signature,
@@ -169,68 +223,10 @@ impl ScalarUDFImpl for DateBinFunc {
Calculates time intervals and returns the start of the interval nearest to the specified timestamp. Use `date_bin` to downsample time series data by grouping rows into time-based "bins" or "windows" and applying an aggregate or selector function to each window.
184
-
185
-
For 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`.
FROM VALUES ('2023-01-01T18:18:18Z'), ('2023-01-03T19:00:03Z') t(time);
192
-
+---------------------+
193
-
| bin |
194
-
+---------------------+
195
-
| 2023-01-01T00:00:00 |
196
-
| 2023-01-03T00:00:00 |
197
-
+---------------------+
198
-
2 row(s) fetched.
199
-
200
-
-- Bin the timestamp into 1 day intervals starting at 3AM on 2023-01-01
201
-
> SELECT date_bin(interval '1 day', time, '2023-01-01T03:00:00') as bin
202
-
FROM VALUES ('2023-01-01T18:18:18Z'), ('2023-01-03T19:00:03Z') t(time);
203
-
+---------------------+
204
-
| bin |
205
-
+---------------------+
206
-
| 2023-01-01T03:00:00 |
207
-
| 2023-01-03T03:00:00 |
208
-
+---------------------+
209
-
2 row(s) fetched.
210
-
```
211
-
"#)
212
-
.with_argument("interval","Bin interval.")
213
-
.with_argument("expression","Time expression to operate on. Can be a constant, column, or function.")
214
-
.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).
0 commit comments