Skip to content
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
76 changes: 76 additions & 0 deletions datafusion/core/tests/sql/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,7 @@ async fn test_extract_date_part() -> Result<()> {
"EXTRACT(microsecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
"12123456.78"
);
// Depends on https://github.com/apache/arrow-datafusion/issues/4528
// test_expression!(
// "EXTRACT(nanosecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
// "1212345678"
Expand All @@ -1319,6 +1320,81 @@ async fn test_extract_date_part() -> Result<()> {
Ok(())
}

#[tokio::test]
async fn test_extract_date_part_func() -> Result<()> {
test_expression!(
format!(
"(date_part('{0}', now()) = EXTRACT({0} FROM now()))",
"year"
),
"true"
);
test_expression!(
format!(
"(date_part('{0}', now()) = EXTRACT({0} FROM now()))",
"quarter"
),
"true"
);
test_expression!(
format!(
"(date_part('{0}', now()) = EXTRACT({0} FROM now()))",
"month"
),
"true"
);
test_expression!(
format!(
"(date_part('{0}', now()) = EXTRACT({0} FROM now()))",
"week"
),
"true"
);
test_expression!(
format!("(date_part('{0}', now()) = EXTRACT({0} FROM now()))", "day"),
"true"
);
test_expression!(
format!(
"(date_part('{0}', now()) = EXTRACT({0} FROM now()))",
"hour"
),
"true"
);
test_expression!(
format!(
"(date_part('{0}', now()) = EXTRACT({0} FROM now()))",
"minute"
),
"true"
);
test_expression!(
format!(
"(date_part('{0}', now()) = EXTRACT({0} FROM now()))",
"second"
),
"true"
);
test_expression!(
format!(
"(date_part('{0}', now()) = EXTRACT({0} FROM now()))",
"millisecond"
),
"true"
);
test_expression!(
format!(
"(date_part('{0}', now()) = EXTRACT({0} FROM now()))",
"microsecond"
),
"true"
);
// Depends on https://github.com/apache/arrow-datafusion/issues/4528
//test_expression!(format!("(date_part('{0}', now()) = EXTRACT({0} FROM now()))", "nanosecond"), "true");

Ok(())
}

#[tokio::test]
async fn test_in_list_scalar() -> Result<()> {
test_expression!("'a' IN ('a','b')", "true");
Expand Down
4 changes: 4 additions & 0 deletions datafusion/expr/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ pub fn signature(fun: &BuiltinScalarFunction) -> Signature {
DataType::Utf8,
DataType::Timestamp(TimeUnit::Nanosecond, None),
]),
TypeSignature::Exact(vec![
DataType::Utf8,
DataType::Timestamp(TimeUnit::Nanosecond, Some("+00:00".to_owned())),
]),
],
fun.volatility(),
),
Expand Down
2 changes: 1 addition & 1 deletion datafusion/physical-expr/src/datetime_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ macro_rules! extract_date_part {
Ok($FN(array)
.map(|v| cast(&(Arc::new(v) as ArrayRef), &DataType::Float64))?)
}
DataType::Timestamp(time_unit, None) => match time_unit {
DataType::Timestamp(time_unit, _) => match time_unit {
TimeUnit::Second => {
let array = as_timestamp_second_array($ARRAY)?;
Ok($FN(array)
Expand Down