neilconway commented on code in PR #10668:
URL: https://github.com/apache/arrow-rs/pull/10668#discussion_r3798407683


##########
arrow-cast/src/cast/decimal.rs:
##########
@@ -539,100 +549,160 @@ where
     T::Native: DecimalCast + ArrowNativeTypeOp,
 {
     let value_str = value_str.trim();
-    let parts: Vec<&str> = value_str.split('.').collect();
-    if parts.len() > 2 {
-        return Err(ArrowError::InvalidArgumentError(format!(
-            "Invalid decimal format: {value_str:?}"
-        )));
-    }
+    let bytes = value_str.as_bytes();
 
-    let (negative, first_part) = if parts[0].is_empty() {
-        (false, parts[0])
-    } else {
-        match parts[0].as_bytes()[0] {
-            b'-' => (true, &parts[0][1..]),
-            b'+' => (false, &parts[0][1..]),
-            _ => (false, parts[0]),
+    let mut index = 0;
+    let negative = match bytes.first() {
+        Some(b'-') => {
+            index += 1;
+            true
+        }
+        Some(b'+') => {
+            index += 1;
+            false
         }
+        _ => false,
     };
 
-    let integers = first_part;
-    let decimals = if parts.len() == 2 { parts[1] } else { "" };
+    let mut value = T::Native::ZERO;
+    let mut chunk = 0_u64;
+    let mut chunk_len = 0_usize;
+    let mut saw_digit = false;
+    let mut saw_point = false;
+    let mut fractionals = 0_usize;
+    let mut first_discarded_digit = None;
+
+    while let Some(&b) = bytes.get(index) {
+        match b {
+            b'0'..=b'9' => {
+                saw_digit = true;
+                let digit = b - b'0';
+                if saw_point {
+                    if fractionals == scale {
+                        first_discarded_digit.get_or_insert(digit);
+                        index += 1;
+                        continue;

Review Comment:
   Yeah that occurred to me -- it seemed a bit marginal because strings with 
long strings of digits beyond the target scale seems like a bit of a corner 
case. But it's probably worth investigating; I'll take a look as a follow-on PR 
if that's okay.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to