You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Sean-Kenneth-Doherty (via GitHub)" <gi...@apache.org> on 2026/05/17 10:36:21 UTC

[PR] Guard date_trunc lower-bound truncation [datafusion]

Sean-Kenneth-Doherty opened a new pull request, #22303:
URL: https://github.com/apache/datafusion/pull/22303

   ## Which issue does this PR close?
   
   - Closes #22214.
   
   ## Rationale for this change
   
   Truncating a near-lower-bound nanosecond timestamp to a coarser calendar unit can produce a timestamp outside Arrow's nanosecond range.  already used fallible timestamp conversion, but it unwrapped the final conversion back to nanoseconds and could panic.
   
   ## What changes are included in this PR?
   
   - Convert the final out-of-range truncation case into a DataFusion execution error.
   - Add a small string helper for user-facing granularity names in the error.
   - Add a unit regression and a sqllogictest regression for lower-bound nanosecond truncation.
   
   ## Are these changes tested?
   
   Yes:
   
   - 
   - 
   - 
   running 1 test
   test datetime::date_trunc::tests::date_trunc_out_of_range_lower_bound_returns_error ... ok
   
   test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 282 filtered out; finished in 0.12s
   - 
   - 
   
   ## Are there any user-facing changes?
   
   Instead of panicking, out-of-range  results now return an error.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Guard date_trunc lower-bound truncation [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #22303:
URL: https://github.com/apache/datafusion/pull/22303#issuecomment-4558958388

   Looks good -- thank you @Sean-Kenneth-Doherty 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Guard date_trunc lower-bound truncation [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #22303:
URL: https://github.com/apache/datafusion/pull/22303#issuecomment-4547278765

   @Sean-Kenneth-Doherty  can you address @Jefffrey 's comments so we can merge this PR in?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Guard date_trunc lower-bound truncation [datafusion]

Posted by "Sean-Kenneth-Doherty (via GitHub)" <gi...@apache.org>.
Sean-Kenneth-Doherty commented on PR #22303:
URL: https://github.com/apache/datafusion/pull/22303#issuecomment-4470442924

   Local validation for the current head (`40335934b`):
   
   - `cargo fmt --check --all`
   - `git diff --check origin/main...HEAD && git diff --check`
   - `cargo test -p datafusion-functions date_trunc_out_of_range_lower_bound_returns_error` (1 passed)
   - Ran the locally built `sqllogictests` driver from `datafusion/sqllogictest` with the `date_trunc_boundaries` filter; it completed `1/1` files.
   
   Hosted checks currently only show the labeler, so this covers the focused unit and SQL regression paths for the lower-bound `date_trunc` case.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Guard date_trunc lower-bound truncation [datafusion]

Posted by "Sean-Kenneth-Doherty (via GitHub)" <gi...@apache.org>.
Sean-Kenneth-Doherty commented on PR #22303:
URL: https://github.com/apache/datafusion/pull/22303#issuecomment-4558931521

   Addressed @Jefffrey’s review comments in `7440978d2`:
   
   - replaced the one-off `DateTruncGranularity::as_str()` helper with a `Display` implementation
   - moved the lower-bound `date_trunc` SQL regression into `datafusion/sqllogictest/test_files/datetime/timestamps.slt`
   - removed the standalone `date_trunc_boundaries.slt` file
   
   Validation:
   
   - `cargo fmt --all --check`
   - `git diff --check`
   - `CARGO_BUILD_JOBS=2 cargo test -p datafusion-functions --lib date_trunc_out_of_range_lower_bound_returns_error`
   - `CARGO_BUILD_JOBS=2 cargo test -p datafusion-sqllogictest --test sqllogictests -- datetime/timestamps.slt` (`1/1 files completed`)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Guard date_trunc lower-bound truncation [datafusion]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #22303:
URL: https://github.com/apache/datafusion/pull/22303#discussion_r3295933577


##########
datafusion/functions/src/datetime/date_trunc.rs:
##########
@@ -133,6 +133,21 @@ impl DateTruncGranularity {
                 | Self::Microsecond
         )
     }
+
+    fn as_str(self) -> &'static str {

Review Comment:
   Maybe better to do this as a `Display` impl?



##########
datafusion/sqllogictest/test_files/date_trunc_boundaries.slt:
##########
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Regression test for https://github.com/apache/datafusion/issues/22214
+query error .*out of range after truncating to year
+SELECT date_trunc(

Review Comment:
   Could we put this in `timestamps.slt` instead of creating a single file for this test case?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Guard date_trunc lower-bound truncation [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #22303:
URL: https://github.com/apache/datafusion/pull/22303


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org