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 second and minute in expr. #1901

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions datafusion-physical-expr/src/datetime_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ pub fn date_part(args: &[ColumnarValue]) -> Result<ColumnarValue> {
let arr = match date_part.to_lowercase().as_str() {
"hour" => extract_date_part!(array, temporal::hour),
"year" => extract_date_part!(array, temporal::year),
"minute" => extract_date_part!(array, temporal::minute),
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.

Do we need to support month and other fields?
As described in the doc https://www.postgresql.org/docs/9.1/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT, There are many fields needed to support.
I think we can support the kernel following this https://github.com/apache/arrow-rs/pull/1376/files in the arrow-rs before next release of arrow-rs.
We can implement the fields which are most used first.

Copy link
Member Author

@Ted-Jiang Ted-Jiang Mar 3, 2022

Choose a reason for hiding this comment

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

Thanks, i will a 'mount 'API in arrow-rs arrow-pr

Copy link
Contributor

@alamb alamb Mar 3, 2022

Choose a reason for hiding this comment

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

PR is apache/arrow-rs#1388 for anyone who cares

"second" => extract_date_part!(array, temporal::second),
_ => Err(DataFusionError::Execution(format!(
"Date part '{}' not supported",
date_part
Expand Down
16 changes: 16 additions & 0 deletions datafusion/tests/sql/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,22 @@ async fn test_extract_date_part() -> Result<()> {
"EXTRACT(year FROM to_timestamp('2020-09-08T12:00:00+00:00'))",
"2020"
);
test_expression!(
"EXTRACT(minute FROM to_timestamp('2020-09-08T12:12:00+00:00'))",
"12"
);
test_expression!(
"date_part('minute', to_timestamp('2020-09-08T12:12:00+00:00'))",
"12"
);
test_expression!(
"EXTRACT(second FROM to_timestamp('2020-09-08T12:00:12+00:00'))",
"12"
);
test_expression!(
"date_part('second', to_timestamp('2020-09-08T12:00:12+00:00'))",
"12"
);
Ok(())
}

Expand Down