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/21 17:09:36 UTC

[GitHub] [arrow-datafusion] alamb opened a new pull request, #6738: Minor: remove some uses of unwrap

alamb opened a new pull request, #6738:
URL: https://github.com/apache/arrow-datafusion/pull/6738

   # Which issue does this PR close?
   Minor follow on to https://github.com/apache/arrow-datafusion/pull/6723 
   
   # Rationale for this change
   
   While reviewing https://github.com/apache/arrow-datafusion/pull/6723 (thanks @BryanEmond !) I noticed it would be possible to do so with a little less code using `Option::map` so I coded it up
   
   # What changes are included in this PR?
   
   Refactor some code to avoid `unwrap`
   
   # Are these changes tested?
   Covered by existing tests added in https://github.com/apache/arrow-datafusion/pull/6723
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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 a diff in pull request #6738: Minor: remove some uses of unwrap

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6738:
URL: https://github.com/apache/arrow-datafusion/pull/6738#discussion_r1237330210


##########
datafusion/physical-expr/src/datetime_expressions.rs:
##########
@@ -284,44 +284,34 @@ pub fn date_trunc(args: &[ColumnarValue]) -> Result<ColumnarValue> {
         ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(v, tz_opt)) => {
             let nano = (f)(*v)?;
 
-            if nano.is_none() {
-                return Ok(ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(
-                    None,
-                    tz_opt.clone(),
-                )));
-            }
-
             match granularity.as_str() {
                 "minute" => {
                     // trunc to minute
                     let second = ScalarValue::TimestampNanosecond(
-                        Some(nano.unwrap() / 1_000_000_000 * 1_000_000_000),
+                        nano.map(|nano| nano / 1_000_000_000 * 1_000_000_000),

Review Comment:
   since `nano` is already an option, we can skip the check/unwrap using `Option::map`



-- 
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 merged pull request #6738: Minor: remove some uses of unwrap

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


-- 
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 pull request #6738: Minor: remove some uses of unwrap

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

   Thanks @viirya 


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