From 39b1670bff6a056ec3d3e7e8778fae4811acd097 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Wed, 11 Dec 2024 09:56:25 -0500 Subject: [PATCH 1/3] Minor: make unsupported `nanosecond` part a real (not internal) error --- .../functions/src/datetime/date_part.rs | 4 ++-- .../test_files/expr/date_part.slt | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/datafusion/functions/src/datetime/date_part.rs b/datafusion/functions/src/datetime/date_part.rs index b8c58a11d999..8cbede5ef331 100644 --- a/datafusion/functions/src/datetime/date_part.rs +++ b/datafusion/functions/src/datetime/date_part.rs @@ -35,7 +35,7 @@ use datafusion_common::cast::{ as_timestamp_microsecond_array, as_timestamp_millisecond_array, as_timestamp_nanosecond_array, as_timestamp_second_array, }; -use datafusion_common::{exec_err, internal_err, ExprSchema, Result, ScalarValue}; +use datafusion_common::{exec_err, internal_err, not_impl_err, ExprSchema, Result, ScalarValue}; use datafusion_expr::scalar_doc_sections::DOC_SECTION_DATETIME; use datafusion_expr::TypeSignature::Exact; use datafusion_expr::{ @@ -292,7 +292,7 @@ fn get_date_part_doc() -> &'static Documentation { fn seconds_as_i32(array: &dyn Array, unit: TimeUnit) -> Result { // Nanosecond is neither supported in Postgres nor DuckDB, to avoid to deal with overflow and precision issue we don't support nanosecond if unit == Nanosecond { - return internal_err!("unit {unit:?} not supported"); + return not_impl_err!("unit {unit:?} not supported"); } let conversion_factor = match unit { diff --git a/datafusion/sqllogictest/test_files/expr/date_part.slt b/datafusion/sqllogictest/test_files/expr/date_part.slt index cec80a165f30..3919da1d24e0 100644 --- a/datafusion/sqllogictest/test_files/expr/date_part.slt +++ b/datafusion/sqllogictest/test_files/expr/date_part.slt @@ -225,7 +225,7 @@ SELECT EXTRACT(microsecond FROM timestamp '2020-09-08T12:00:12.12345678+00:00') ---- 12123456 -query error DataFusion error: Internal error: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: unit Nanosecond not supported SELECT EXTRACT(nanosecond FROM timestamp '2020-09-08T12:00:12.12345678+00:00') query I @@ -243,7 +243,7 @@ SELECT EXTRACT("microsecond" FROM timestamp '2020-09-08T12:00:12.12345678+00:00' ---- 12123456 -query error DataFusion error: Internal error: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: unit Nanosecond not supported SELECT EXTRACT("nanosecond" FROM timestamp '2020-09-08T12:00:12.12345678+00:00') query I @@ -261,7 +261,7 @@ SELECT EXTRACT('microsecond' FROM timestamp '2020-09-08T12:00:12.12345678+00:00' ---- 12123456 -query error DataFusion error: Internal error: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: unit Nanosecond not supported SELECT EXTRACT('nanosecond' FROM timestamp '2020-09-08T12:00:12.12345678+00:00') @@ -281,7 +281,7 @@ SELECT date_part('microsecond', timestamp '2020-09-08T12:00:12.12345678+00:00') ---- 12123456 -query error DataFusion error: Internal error: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: unit Nanosecond not supported SELECT date_part('nanosecond', timestamp '2020-09-08T12:00:12.12345678+00:00') @@ -300,7 +300,7 @@ SELECT date_part('microsecond', '2020-09-08T12:00:12.12345678+00:00') ---- 12123456 -query error DataFusion error: Internal error: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: unit Nanosecond not supported SELECT date_part('nanosecond', '2020-09-08T12:00:12.12345678+00:00') # test_date_part_time @@ -356,7 +356,7 @@ SELECT extract(microsecond from arrow_cast('23:32:50'::time, 'Time32(Second)')) ---- 50000000 -query error DataFusion error: Internal error: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: unit Nanosecond not supported SELECT extract(nanosecond from arrow_cast('23:32:50'::time, 'Time32(Second)')) query R @@ -420,7 +420,7 @@ SELECT extract(microsecond from arrow_cast('23:32:50.123'::time, 'Time32(Millise ---- 50123000 -query error DataFusion error: Internal error: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: unit Nanosecond not supported SELECT extract(nanosecond from arrow_cast('23:32:50.123'::time, 'Time32(Millisecond)')) query R @@ -484,7 +484,7 @@ SELECT extract(microsecond from arrow_cast('23:32:50.123456'::time, 'Time64(Micr ---- 50123456 -query error DataFusion error: Internal error: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: unit Nanosecond not supported SELECT extract(nanosecond from arrow_cast('23:32:50.123456'::time, 'Time64(Microsecond)')) query R @@ -564,7 +564,7 @@ SELECT extract(us from arrow_cast('23:32:50.123456789'::time, 'Time64(Nanosecond ---- 50123456 -query error DataFusion error: Internal error: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: unit Nanosecond not supported SELECT date_part('nanosecond', arrow_cast('23:32:50.123456789'::time, 'Time64(Nanosecond)')) query R @@ -874,5 +874,5 @@ SELECT (date_part('microsecond', now()) = EXTRACT(microsecond FROM now())) ---- true -query error DataFusion error: Internal error: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: unit Nanosecond not supported SELECT (date_part('nanosecond', now()) = EXTRACT(nanosecond FROM now())) From 1d101acfe5ba6a30d0f4f4e31b887ac6e393033d Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Wed, 11 Dec 2024 09:58:10 -0500 Subject: [PATCH 2/3] fmt --- datafusion/functions/src/datetime/date_part.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/datafusion/functions/src/datetime/date_part.rs b/datafusion/functions/src/datetime/date_part.rs index 8cbede5ef331..6143955252fd 100644 --- a/datafusion/functions/src/datetime/date_part.rs +++ b/datafusion/functions/src/datetime/date_part.rs @@ -35,7 +35,9 @@ use datafusion_common::cast::{ as_timestamp_microsecond_array, as_timestamp_millisecond_array, as_timestamp_nanosecond_array, as_timestamp_second_array, }; -use datafusion_common::{exec_err, internal_err, not_impl_err, ExprSchema, Result, ScalarValue}; +use datafusion_common::{ + exec_err, internal_err, not_impl_err, ExprSchema, Result, ScalarValue, +}; use datafusion_expr::scalar_doc_sections::DOC_SECTION_DATETIME; use datafusion_expr::TypeSignature::Exact; use datafusion_expr::{ From 95d0dd5de63f3a1144d0092def2540bc8c0c3b8d Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Thu, 12 Dec 2024 08:59:32 -0500 Subject: [PATCH 3/3] Improve wording to refer to date part --- .../functions/src/datetime/date_part.rs | 5 +++-- .../test_files/expr/date_part.slt | 20 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/datafusion/functions/src/datetime/date_part.rs b/datafusion/functions/src/datetime/date_part.rs index 6143955252fd..6d6adf2a344d 100644 --- a/datafusion/functions/src/datetime/date_part.rs +++ b/datafusion/functions/src/datetime/date_part.rs @@ -292,9 +292,10 @@ fn get_date_part_doc() -> &'static Documentation { /// result to a total number of seconds, milliseconds, microseconds or /// nanoseconds fn seconds_as_i32(array: &dyn Array, unit: TimeUnit) -> Result { - // Nanosecond is neither supported in Postgres nor DuckDB, to avoid to deal with overflow and precision issue we don't support nanosecond + // Nanosecond is neither supported in Postgres nor DuckDB, to avoid dealing + // with overflow and precision issue we don't support nanosecond if unit == Nanosecond { - return not_impl_err!("unit {unit:?} not supported"); + return not_impl_err!("Date part {unit:?} not supported"); } let conversion_factor = match unit { diff --git a/datafusion/sqllogictest/test_files/expr/date_part.slt b/datafusion/sqllogictest/test_files/expr/date_part.slt index 3919da1d24e0..1d79ac3959e5 100644 --- a/datafusion/sqllogictest/test_files/expr/date_part.slt +++ b/datafusion/sqllogictest/test_files/expr/date_part.slt @@ -225,7 +225,7 @@ SELECT EXTRACT(microsecond FROM timestamp '2020-09-08T12:00:12.12345678+00:00') ---- 12123456 -query error DataFusion error: This feature is not implemented: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: Date part Nanosecond not supported SELECT EXTRACT(nanosecond FROM timestamp '2020-09-08T12:00:12.12345678+00:00') query I @@ -243,7 +243,7 @@ SELECT EXTRACT("microsecond" FROM timestamp '2020-09-08T12:00:12.12345678+00:00' ---- 12123456 -query error DataFusion error: This feature is not implemented: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: Date part Nanosecond not supported SELECT EXTRACT("nanosecond" FROM timestamp '2020-09-08T12:00:12.12345678+00:00') query I @@ -261,7 +261,7 @@ SELECT EXTRACT('microsecond' FROM timestamp '2020-09-08T12:00:12.12345678+00:00' ---- 12123456 -query error DataFusion error: This feature is not implemented: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: Date part Nanosecond not supported SELECT EXTRACT('nanosecond' FROM timestamp '2020-09-08T12:00:12.12345678+00:00') @@ -281,7 +281,7 @@ SELECT date_part('microsecond', timestamp '2020-09-08T12:00:12.12345678+00:00') ---- 12123456 -query error DataFusion error: This feature is not implemented: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: Date part Nanosecond not supported SELECT date_part('nanosecond', timestamp '2020-09-08T12:00:12.12345678+00:00') @@ -300,7 +300,7 @@ SELECT date_part('microsecond', '2020-09-08T12:00:12.12345678+00:00') ---- 12123456 -query error DataFusion error: This feature is not implemented: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: Date part Nanosecond not supported SELECT date_part('nanosecond', '2020-09-08T12:00:12.12345678+00:00') # test_date_part_time @@ -356,7 +356,7 @@ SELECT extract(microsecond from arrow_cast('23:32:50'::time, 'Time32(Second)')) ---- 50000000 -query error DataFusion error: This feature is not implemented: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: Date part Nanosecond not supported SELECT extract(nanosecond from arrow_cast('23:32:50'::time, 'Time32(Second)')) query R @@ -420,7 +420,7 @@ SELECT extract(microsecond from arrow_cast('23:32:50.123'::time, 'Time32(Millise ---- 50123000 -query error DataFusion error: This feature is not implemented: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: Date part Nanosecond not supported SELECT extract(nanosecond from arrow_cast('23:32:50.123'::time, 'Time32(Millisecond)')) query R @@ -484,7 +484,7 @@ SELECT extract(microsecond from arrow_cast('23:32:50.123456'::time, 'Time64(Micr ---- 50123456 -query error DataFusion error: This feature is not implemented: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: Date part Nanosecond not supported SELECT extract(nanosecond from arrow_cast('23:32:50.123456'::time, 'Time64(Microsecond)')) query R @@ -564,7 +564,7 @@ SELECT extract(us from arrow_cast('23:32:50.123456789'::time, 'Time64(Nanosecond ---- 50123456 -query error DataFusion error: This feature is not implemented: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: Date part Nanosecond not supported SELECT date_part('nanosecond', arrow_cast('23:32:50.123456789'::time, 'Time64(Nanosecond)')) query R @@ -874,5 +874,5 @@ SELECT (date_part('microsecond', now()) = EXTRACT(microsecond FROM now())) ---- true -query error DataFusion error: This feature is not implemented: unit Nanosecond not supported +query error DataFusion error: This feature is not implemented: Date part Nanosecond not supported SELECT (date_part('nanosecond', now()) = EXTRACT(nanosecond FROM now()))