Skip to content

Commit

Permalink
Minor: make unsupported nanosecond part a real (not internal) error (
Browse files Browse the repository at this point in the history
…apache#13733)

* Minor: make unsupported `nanosecond` part a real (not internal) error

* fmt

* Improve wording to refer to date part
  • Loading branch information
alamb authored Dec 12, 2024
1 parent 1c73a23 commit 98c483e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
9 changes: 6 additions & 3 deletions datafusion/functions/src/datetime/date_part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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::{
Expand Down Expand Up @@ -290,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<ArrayRef> {
// 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 internal_err!("unit {unit:?} not supported");
return not_impl_err!("Date part {unit:?} not supported");
}

let conversion_factor = match unit {
Expand Down
20 changes: 10 additions & 10 deletions datafusion/sqllogictest/test_files/expr/date_part.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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: Date part Nanosecond not supported
SELECT EXTRACT(nanosecond FROM timestamp '2020-09-08T12:00:12.12345678+00:00')

query I
Expand All @@ -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: Date part Nanosecond not supported
SELECT EXTRACT("nanosecond" FROM timestamp '2020-09-08T12:00:12.12345678+00:00')

query I
Expand All @@ -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: Date part Nanosecond not supported
SELECT EXTRACT('nanosecond' FROM timestamp '2020-09-08T12:00:12.12345678+00:00')


Expand All @@ -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: Date part Nanosecond not supported
SELECT date_part('nanosecond', timestamp '2020-09-08T12:00:12.12345678+00:00')


Expand All @@ -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: Date part Nanosecond not supported
SELECT date_part('nanosecond', '2020-09-08T12:00:12.12345678+00:00')

# test_date_part_time
Expand Down Expand Up @@ -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: Date part Nanosecond not supported
SELECT extract(nanosecond from arrow_cast('23:32:50'::time, 'Time32(Second)'))

query R
Expand Down Expand Up @@ -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: Date part Nanosecond not supported
SELECT extract(nanosecond from arrow_cast('23:32:50.123'::time, 'Time32(Millisecond)'))

query R
Expand Down Expand Up @@ -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: Date part Nanosecond not supported
SELECT extract(nanosecond from arrow_cast('23:32:50.123456'::time, 'Time64(Microsecond)'))

query R
Expand Down Expand Up @@ -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: Date part Nanosecond not supported
SELECT date_part('nanosecond', arrow_cast('23:32:50.123456789'::time, 'Time64(Nanosecond)'))

query R
Expand Down Expand Up @@ -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: Date part Nanosecond not supported
SELECT (date_part('nanosecond', now()) = EXTRACT(nanosecond FROM now()))

0 comments on commit 98c483e

Please sign in to comment.