You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/11/17 12:15:29 UTC

[GitHub] [arrow-rs] alamb commented on a change in pull request #952: add more error test case and change the code style

alamb commented on a change in pull request #952:
URL: https://github.com/apache/arrow-rs/pull/952#discussion_r751183059



##########
File path: arrow/src/csv/reader.rs
##########
@@ -1614,7 +1605,7 @@ mod tests {
             let result = parse_decimal_with_parameter(s, 20, 3);
             assert_eq!(i, result.unwrap())
         }
-        let can_not_parse_tests = ["123,123", "."];
+        let can_not_parse_tests = ["123,123", ".", "123.123.123"];

Review comment:
       ๐Ÿ‘ 

##########
File path: arrow/src/csv/reader.rs
##########
@@ -801,31 +800,23 @@ fn parse_decimal_with_parameter(s: &str, precision: usize, scale: usize) -> Resu
             }
         };
 
+        // each byte is digitใ€'-' or '.'
         let bytes = s.as_bytes();
         let mut negative = false;
         let mut result: i128 = 0;
 
-        while offset > 0 {
-            match bytes[offset - 1] {
-                b'-' => {
-                    negative = true;
-                }
-                b'.' => {
-                    // do nothing
-                }
-                b'0'..=b'9' => {
-                    result += i128::from(bytes[offset - 1] - b'0') * base;
-                    base *= 10;
-                }
-                _ => {
-                    return Err(ArrowError::ParseError(format!(
-                        "can't match byte {}",
-                        bytes[offset - 1]
-                    )));
-                }
+        bytes[0..offset].iter().rev().for_each(|&byte| match byte {

Review comment:
       ๐Ÿ‘  looking much nicer!




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