Skip to content

Commit ceab1e1

Browse files
authored
feat: add isodow (ISO day-of-week) support to date_part (Monday = 0) (#17112)
* Add support for 'isodow' in date_part function and corresponding SQL tests * Update documentation for date_part function to clarify 'dow' and add 'isodow' support
1 parent c5cb6f4 commit ceab1e1

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

datafusion/functions/src/datetime/date_part.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ use datafusion_macros::user_doc;
6868
- millisecond
6969
- microsecond
7070
- nanosecond
71-
- dow (day of the week)
71+
- dow (day of the week where Sunday is 0)
7272
- doy (day of the year)
7373
- epoch (seconds since Unix epoch)
74+
- isodow (day of the week where Monday is 0)
7475
"#
7576
),
7677
argument(
@@ -217,6 +218,7 @@ impl ScalarUDFImpl for DatePartFunc {
217218
"qtr" | "quarter" => date_part(array.as_ref(), DatePart::Quarter)?,
218219
"doy" => date_part(array.as_ref(), DatePart::DayOfYear)?,
219220
"dow" => date_part(array.as_ref(), DatePart::DayOfWeekSunday0)?,
221+
"isodow" => date_part(array.as_ref(), DatePart::DayOfWeekMonday0)?,
220222
"epoch" => epoch(array.as_ref())?,
221223
_ => return exec_err!("Date part '{part}' not supported"),
222224
}

datafusion/sqllogictest/test_files/expr/date_part.slt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,3 +1070,23 @@ true
10701070

10711071
query error DataFusion error: This feature is not implemented: Date part Nanosecond not supported
10721072
SELECT (date_part('nanosecond', now()) = EXTRACT(nanosecond FROM now()))
1073+
1074+
query I
1075+
SELECT date_part('ISODOW', CAST('2000-01-01' AS DATE))
1076+
----
1077+
5
1078+
1079+
query I
1080+
SELECT EXTRACT(isodow FROM to_timestamp('2020-09-08T12:00:00+00:00'))
1081+
----
1082+
1
1083+
1084+
query I
1085+
SELECT EXTRACT("isodow" FROM to_timestamp('2020-09-08T12:00:00+00:00'))
1086+
----
1087+
1
1088+
1089+
query I
1090+
SELECT EXTRACT('isodow' FROM to_timestamp('2020-09-08T12:00:00+00:00'))
1091+
----
1092+
1

docs/source/user-guide/sql/scalar_functions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2114,9 +2114,10 @@ date_part(part, expression)
21142114
- millisecond
21152115
- microsecond
21162116
- nanosecond
2117-
- dow (day of the week)
2117+
- dow (day of the week where Sunday is 0)
21182118
- doy (day of the year)
21192119
- epoch (seconds since Unix epoch)
2120+
- isodow (day of the week where Monday is 0)
21202121

21212122
- **expression**: Time expression to operate on. Can be a constant, column, or function.
21222123

0 commit comments

Comments
 (0)