Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support extracting week and week's year from date or timestamp #14524

Open
findepi opened this issue Feb 6, 2025 · 3 comments
Open

Support extracting week and week's year from date or timestamp #14524

findepi opened this issue Feb 6, 2025 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@findepi
Copy link
Member

findepi commented Feb 6, 2025

Add support for extract(week_iso from date_time) and date_part('week_iso', date_time).
Add support for extract(year_of_week_iso from date_time) and date_part('year_of_week_iso', date_time).

References

PostgreSQL

https://www.postgresql.org/docs/17/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT

  • week (ISO week)
  • isoyear (year of week)

Trino

https://github.com/trinodb/trino/blob/8e88778a03f137a0c0924875f8d4560138d23d10/core/trino-parser/src/main/java/io/trino/sql/tree/Extract.java#L36

https://github.com/trinodb/trino/blob/8e88778a03f137a0c0924875f8d4560138d23d10/core/trino-parser/src/main/java/io/trino/sql/tree/Extract.java#L43

Snowflake

https://docs.snowflake.com/en/sql-reference/functions-date-time#supported-date-and-time-parts

  • week
  • weekiso | week_iso
  • yearofweek
  • yearofweekiso

Notes

Snowflake has two variants of these functions / date-time fields. The ISO variant is means always the same thing. The non-ISO is session-dependent.
In our implementation we should support the ISO semantics. We could use ISO terminology (_iso names), or support them as aliases.

@findepi findepi added the enhancement New feature or request label Feb 6, 2025
@kosiew
Copy link
Contributor

kosiew commented Feb 7, 2025

take

@Omega359
Copy link
Contributor

Omega359 commented Feb 7, 2025

Looks like the code in date_part (which extract maps to) uses IntervalUnit for the matching of the parts. 'Week' is already supported and maps to iso week of the year (0-53) though it doesn't have the week-iso alias. That would be a change in arrow-arith.

I think supporting isoyear/yearofweek/etc would be more work as there is no support for that anywhere in arror-arith that I can find.

@kosiew
Copy link
Contributor

kosiew commented Feb 11, 2025

@Omega359 ,
Thanks for the pointer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants