Skip to content

Commit

Permalink
support extract second and minute in expr. (#1901)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ted-Jiang authored Mar 3, 2022
1 parent 6f3ca5b commit bc42ead
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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),
"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

0 comments on commit bc42ead

Please sign in to comment.