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 extract week in temporal.rs #1376

Merged
merged 3 commits into from
Mar 2, 2022
Merged

Conversation

Ted-Jiang
Copy link
Member

Which issue does this PR close?

Closes #1375.

Add a method Extracts the week of a given temporal array as an array of integers.
For apache/datafusion#1896
will implement
week :week number starting from 1 in the year.

@github-actions github-actions bot added the arrow Changes to the arrow crate label Mar 1, 2022
@Ted-Jiang Ted-Jiang force-pushed the ISSUE_1375 branch 2 times, most recently from 39b53e3 to 34df948 Compare March 1, 2022 08:18
@Ted-Jiang
Copy link
Member Author

@alamb @Dandandan @liukun4515 PTAL

@liukun4515
Copy link
Contributor

@alamb @Dandandan @liukun4515 PTAL

Thanks. @Ted-Jiang

let mut b = Int32Builder::new(array.len());

match array.data_type() {
&DataType::Date32 | &DataType::Date64 | &DataType::Timestamp(_, None) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to consider the timezone when support the Timestamp type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it is important (eventually) to handle the timezone

This function seems to follow the model of existing functions such as second which also don't handle timezone

I suggest we merge this PR in as is (without timezone support) and file a ticket for proper handling of timezone support for all the extract functions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks,I will create an issue follow up the timezone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timezone issue: #1380

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add the enhancement pull request to resolve the time zone issue. @alamb

assert_eq!(9, b.value(0));
assert!(!b.is_valid(1));
assert_eq!(1, b.value(2));
assert_eq!(52, b.value(3));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how a date of 2022.01.01 would have a week of 52. I wonder if the comments on what date 1640998800000 corresponds to is incorrect?

Copy link
Member Author

@Ted-Jiang Ted-Jiang Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for forgetting provide enough info.
PG has the same behavior.


postgres=# select extract('week' from date '2022-01-01');
 date_part
-----------
        52
(1 row)

It may cause by 2019/12/31 is Tuesday, i use chronno to calculate the week it followed ISO standard.

Copy link
Contributor

@liukun4515 liukun4515 Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how a date of 2022.01.01 would have a week of 52. I wonder if the comments on what date 1640998800000 corresponds to is incorrect?

@alamb
the week of 2022.01.01 belongs to the last year.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the clarification. Sorry for my confusion

arrow/src/compute/kernels/temporal.rs Show resolved Hide resolved
let mut b = Int32Builder::new(array.len());

match array.data_type() {
&DataType::Date32 | &DataType::Date64 | &DataType::Timestamp(_, None) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it is important (eventually) to handle the timezone

This function seems to follow the model of existing functions such as second which also don't handle timezone

I suggest we merge this PR in as is (without timezone support) and file a ticket for proper handling of timezone support for all the extract functions

Copy link
Contributor

@liukun4515 liukun4515 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alamb
Copy link
Contributor

alamb commented Mar 2, 2022

Thank you @Ted-Jiang and @liukun4515

@alamb alamb changed the title Add extract week in temporal.rs Support extract week in temporal.rs Mar 2, 2022
@alamb alamb merged commit ce27bed into apache:master Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add week temporal kernel
3 participants