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

[GitHub] [arrow-rs] suxiaogang223 opened a new pull request, #3734: replace for loop by try_for_each

suxiaogang223 opened a new pull request, #3734:
URL: https://github.com/apache/arrow-rs/pull/3734

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   # Rationale for this change
    In the previously submitted merge request, to return `Error` in the closure of the `for_each`, change the code from iter to for loop:
   ```rust
       for byte in bytes[0..offset].iter().rev() {
               match byte {
                   b'-' => {
                       negative = true;
                   }
                   b'0'..=b'9' => {
                       let add =
                           T::Native::usize_as((byte - b'0') as usize).mul_checked(base)?;
                       result = result.add_checked(add)?;
                       base = base.mul_checked(T::Native::usize_as(10))?;
                   }
                   // because of the PARSE_DECIMAL_RE, bytes just contains digit、'-' and '.'.
                   _ => {}
               }
           }
   ```
   I later found out that it was possible to return error using `try_for_each`, like this:
   ```rust
      bytes[0..offset]
               .iter()
               .rev()
               .try_for_each::<_, Result<(), ArrowError>>(|&byte| match byte {
                   b'-' => {
                       negative = true;
                       Ok(())
                   }
                   b'0'..=b'9' => {
                       let add =
                           T::Native::usize_as((byte - b'0') as usize).mul_checked(base)?;
                       result = result.add_checked(add)?;
                       base = base.mul_checked(T::Native::usize_as(10))?;
                       Ok(())
                   }
                   // because of the PARSE_DECIMAL_RE, bytes just contains digit、'-' and '.'.
                   _ => Ok(()),
               })?;
   ```
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   replace for loop by try_for_each
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   no
   
   <!--
   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 `breaking 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-rs] viirya commented on a diff in pull request #3734: replace for loop by try_for_each

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #3734:
URL: https://github.com/apache/arrow-rs/pull/3734#discussion_r1112224836


##########
arrow-csv/src/reader/mod.rs:
##########
@@ -866,21 +866,24 @@ fn parse_decimal_with_parameter<T: DecimalType>(
         let mut negative = false;
         let mut result = T::Native::usize_as(0);
 
-        for byte in bytes[0..offset].iter().rev() {
-            match byte {
-                b'-' => {
-                    negative = true;
-                }
-                b'0'..=b'9' => {
-                    let add =
-                        T::Native::usize_as((byte - b'0') as usize).mul_checked(base)?;
-                    result = result.add_checked(add)?;
-                    base = base.mul_checked(T::Native::usize_as(10))?;
+        bytes[0..offset]
+            .iter()
+            .rev()
+            .try_for_each::<_, Result<(), ArrowError>>(|&byte| {
+                match byte {
+                    b'-' => {
+                        negative = true;
+                    }
+                    b'0'..=b'9' => {
+                        let add = T::Native::usize_as((byte - b'0') as usize)
+                            .mul_checked(base)?;
+                        result = result.add_checked(add)?;
+                        base = base.mul_checked(T::Native::usize_as(10))?;
+                    }
+                    _ => (),
                 }
-                // because of the PARSE_DECIMAL_RE, bytes just contains digit、'-' and '.'.

Review Comment:
   No need to keep the comment?



-- 
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-rs] tustvold commented on a diff in pull request #3734: replace for loop by try_for_each

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #3734:
URL: https://github.com/apache/arrow-rs/pull/3734#discussion_r1112006379


##########
arrow-csv/src/reader/mod.rs:
##########
@@ -866,21 +866,24 @@ fn parse_decimal_with_parameter<T: DecimalType>(
         let mut negative = false;
         let mut result = T::Native::usize_as(0);
 
-        for byte in bytes[0..offset].iter().rev() {
-            match byte {
+        bytes[0..offset]
+            .iter()
+            .rev()
+            .try_for_each::<_, Result<(), ArrowError>>(|&byte| match byte {
                 b'-' => {
                     negative = true;
+                    Ok(())

Review Comment:
   It might be cleaner to lift the `Ok(())` out of the match, but don't feel strongly



-- 
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-rs] ursabot commented on pull request #3734: replace for loop by try_for_each

Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #3734:
URL: https://github.com/apache/arrow-rs/pull/3734#issuecomment-1438021994

   Benchmark runs are scheduled for baseline = 72ad8a728e43d15409f93331da7fc793220252ad and contender = 25da74c35861fe0c5922c0e0792eacbe1bd48e25. 25da74c35861fe0c5922c0e0792eacbe1bd48e25 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/5e991f5585724109a287e64df9312675...083f75019fdf450f8b385ea995dea964/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/6b7749642bdd466c9be1dd960fdcdb8f...6876a077c4b8447a99315ae67a996ce3/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/b8c95e35290d48698420f255ac23ef54...f0c5939a585f4a3dabe403459db11f3f/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/08be09daa4714b50a5d9582d8d4d14f8...f741b8718f54415296b30f650658e892/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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-rs] tustvold merged pull request #3734: replace for loop by try_for_each

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


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