You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2023/06/16 15:32:35 UTC

[GitHub] [arrow-datafusion] alamb opened a new issue, #6701: `date_trunc(null)` results in a panic

alamb opened a new issue, #6701:
URL: https://github.com/apache/arrow-datafusion/issues/6701

   ### Describe the bug
   
   Calling the `date_trunc(null)` function results in a panic
   
   ### To Reproduce
   
   ```
   DataFusion CLI v26.0.0
   ❯ select date_trunc('2021-02-01T12:01:02', 'hour');
   Optimizer rule 'simplify_expressions' failed
   caused by
   Arrow error: Parser error: Error parsing timestamp from 'hour': timestamp must contain at least 10 characters
   ❯ select date_trunc('hour', '2021-02-01T12:01:02');
   +------------------------------------------------------+
   | date_trunc(Utf8("hour"),Utf8("2021-02-01T12:01:02")) |
   +------------------------------------------------------+
   | 2021-02-01T12:00:00                                  |
   +------------------------------------------------------+
   1 row in set. Query took 0.074 seconds.
   ❯ select date_trunc('hour', null);
   thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /Users/alamb/Software/arrow-datafusion/datafusion/physical-expr/src/datetime_expressions.rs:314:35
   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
   ```
   
   ### Expected behavior
   
   `null` should be returned
   
   
   
   ### Additional context
   
   Found while reviewing https://github.com/apache/arrow-datafusion/pull/6654 from @Weijun-H 
   
   The issue is the use of `unwrap()` in the `date_trunc` implementation
   
   I think this is a good first issue for someone as it involves removing `unwrap()` and writing some tests using .slt


-- 
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@arrow.apache.org.apache.org

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


[GitHub] [arrow-datafusion] viirya closed issue #6701: `date_trunc(null)` results in a panic

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya closed issue #6701: `date_trunc(null)` results in a panic
URL: https://github.com/apache/arrow-datafusion/issues/6701


-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] BryanEmond commented on issue #6701: `date_trunc(null)` results in a panic

Posted by "BryanEmond (via GitHub)" <gi...@apache.org>.
BryanEmond commented on issue #6701:
URL: https://github.com/apache/arrow-datafusion/issues/6701#issuecomment-1595186014

   I've tried to remove the unwrap() like specify in the issue, but nano is an option<i64>, so removing the unwrap just creates errors. So is it better to catch the error and return null or replacing unwrap() by unwrap_or_default() which return "1970-01-01T00:00:00"?


-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] BryanEmond commented on issue #6701: `date_trunc(null)` results in a panic

Posted by "BryanEmond (via GitHub)" <gi...@apache.org>.
BryanEmond commented on issue #6701:
URL: https://github.com/apache/arrow-datafusion/issues/6701#issuecomment-1595158226

   I'll look at it.
   


-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on issue #6701: `date_trunc(null)` results in a panic

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #6701:
URL: https://github.com/apache/arrow-datafusion/issues/6701#issuecomment-1596100597

   > I've tried to remove the unwrap() like specify in the issue, but nano is an Option, so removing the unwrap just creates errors. So is it better to catch the error and return null or replacing unwrap() by unwrap_or_default() which return "1970-01-01T00:00:00"?
   
   I think what is needed is to ignore nulls (so that null comes out)
   
   something like `nano.map(|nano| truncate(nano))`
   
   So rather than `unwrap` use `map` to only do the calculation of `nano` is non null
   
   If you make a PR with some example code I can probably offer some more specific advice


-- 
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@arrow.apache.org

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