alamb commented on code in PR #8700:
URL: https://github.com/apache/arrow-rs/pull/8700#discussion_r2695158502


##########
arrow-cast/src/parse.rs:
##########
@@ -2752,6 +2740,35 @@ mod tests {
             let result = parse_decimal::<Decimal256Type>(s, 76, scale);
             assert_eq!(i, result.unwrap());
         }
+
+        let zero_scale_tests = [
+            ("0.123", 0, 3),
+            ("1.0", 1, 3),
+            ("1.2", 1, 3),
+            ("1.00", 1, 3),
+            ("1.23", 1, 3),
+            ("1.000", 1, 3),
+            ("1.123", 1, 3),
+            ("123.0", 123, 3),
+            ("123.4", 123, 3),
+            ("123.00", 123, 3),
+            ("123.45", 123, 3),
+            ("123.000000000000000000004", 123, 3),
+            ("0.123e2", 12, 3),
+            ("0.123e4", 1230, 10),
+            ("1.23e4", 12300, 10),
+            ("12.3e4", 123000, 10),
+            ("123e4", 1230000, 10),
+            (
+                "20000000000000000000000000000000000002.0",
+                20000000000000000000000000000000000002,
+                38,
+            ),
+        ];
+        for (s, i, precision) in zero_scale_tests {
+            let result_128 = parse_decimal::<Decimal128Type>(s, precision, 
0).unwrap();
+            assert_eq!(i, result_128);
+        }

Review Comment:
   > So if the matches! approach from above is fine with you, and if you agree 
we should make these unsupported, then I can just append these patterns there. 
Otherwise, let me know which ones would you think it'd make sense to parse.
   
   I think that sounds good to me. I tested some other systems  and they also 
can't parse these examples
   
   ```sql
   D select '1e'::decimal;
   Conversion Error:
   Could not convert string "1e" to DECIMAL(18,3)
   
   LINE 1: select '1e'::decimal;
   ```
   
   spark also doesn't parse them
   
   ```sql
   spark-sql (default)> SELECT cast ('1' as DECIMAL(5,3));
   1.000
   Time taken: 0.048 seconds, Fetched 1 row(s)
   spark-sql (default)> SELECT cast ('1e' as DECIMAL(5,3));
   NULL
   Time taken: 0.052 seconds, Fetched 1 row(s)
   spark-sql (default)> SELECT cast ('e' as DECIMAL(5,3));
   NULL
   Time taken: 0.034 seconds, Fetched 1 row(s)
   spark-sql (default)> SELECT cast ('1e+' as DECIMAL(5,3));
   NULL
   Time taken: 0.033 seconds, Fetched 1 row(s)
   spark-sql (default)> SELECT cast ('1e' as DECIMAL(5,0));
   NULL
   Time taken: 0.038 seconds, Fetched 1 row(s)
   ```



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