You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jonahgao (via GitHub)" <gi...@apache.org> on 2023/09/23 17:49:31 UTC

[GitHub] [arrow-datafusion] jonahgao commented on a diff in pull request #7627: fix: check for precision overflow when parsing float as decimal

jonahgao commented on code in PR #7627:
URL: https://github.com/apache/arrow-datafusion/pull/7627#discussion_r1335048520


##########
datafusion/sql/src/expr/value.rs:
##########
@@ -66,23 +67,19 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                 let p = str.len() - 1;
                 let s = str.len() - i - 1;
                 let str = str.replace('.', "");
-                let n = str.parse::<i128>().map_err(|_| {
-                    DataFusionError::from(ParserError(format!(
-                        "Cannot parse {str} as i128 when building decimal"
-                    )))
-                })?;
+                let n = parse_decimal_128_without_scale(&str)?;
                 Ok(Expr::Literal(ScalarValue::Decimal128(
                     Some(n),
                     p as u8,
                     s as i8,
                 )))
             } else {
-                let number = n.parse::<i128>().map_err(|_| {
-                    DataFusionError::from(ParserError(format!(
-                        "Cannot parse {n} as i128 when building decimal"
-                    )))
-                })?;
-                Ok(Expr::Literal(ScalarValue::Decimal128(Some(number), 38, 0)))
+                let number = parse_decimal_128_without_scale(str)?;
+                Ok(Expr::Literal(ScalarValue::Decimal128(
+                    Some(number),
+                    str.len() as u8,

Review Comment:
   Try to use the minimum precision instead of the maximum precision.



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