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

[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #6723: Return null for date_trunc(null) instead of panic

viirya commented on code in PR #6723:
URL: https://github.com/apache/arrow-datafusion/pull/6723#discussion_r1235808701


##########
datafusion/physical-expr/src/datetime_expressions.rs:
##########
@@ -283,6 +283,11 @@ pub fn date_trunc(args: &[ColumnarValue]) -> Result<ColumnarValue> {
     Ok(match array {
         ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(v, tz_opt)) => {
             let nano = (f)(*v)?;
+
+            if nano.is_none() {
+                return Ok(ColumnarValue::Scalar(ScalarValue::Null));

Review Comment:
   The issue is because you use `ScalarValue::Null` here.
   
   You can take a look of `enum ScalarValue`. `ScalarValue::Null` is for `DataType::Null`. For other types, they can take a `Some(value)` or a `None` which represents a null value for the type.
   
   For `TimestampNanosecond` type, you just need to put `ScalarValue::TimestampNanosecond` with `None` here.



-- 
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