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 2022/11/04 03:42:39 UTC

[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #4102: Add parser option for parsing SQL numeric literals as decimal

liukun4515 commented on code in PR #4102:
URL: https://github.com/apache/arrow-datafusion/pull/4102#discussion_r1013579030


##########
datafusion/sql/src/planner.rs:
##########
@@ -2907,28 +2973,26 @@ pub fn convert_data_type(sql_type: &SQLDataType) -> Result<DataType> {
     }
 }
 
-// Parse number in sql string, convert to Expr::Literal
-fn parse_sql_number(n: &str) -> Result<Expr> {
-    // parse first as i64
-    n.parse::<i64>()
-        .map(lit)
-        // if parsing as i64 fails try f64
-        .or_else(|_| n.parse::<f64>().map(lit))
-        .map_err(|_| {
-            DataFusionError::from(ParserError(format!(
-                "Cannot parse {} as i64 or f64",
-                n
-            )))
-        })
-}
-
 #[cfg(test)]
 mod tests {
     use super::*;
     use datafusion_common::assert_contains;
     use sqlparser::dialect::{Dialect, GenericDialect, HiveDialect, MySqlDialect};
     use std::any::Any;
 
+    #[test]
+    fn parse_decimals() {
+        let options = ParserOptions {
+            parse_float_as_decimal: true,
+        };
+        quick_test_with_options(
+            "SELECT 1, 1.0, 0.1, .1, 12.34",
+            "Projection: Int64(1), Decimal128(Some(10),2,1), Decimal128(Some(1),2,1), Decimal128(Some(1),1,1), Decimal128(Some(1234),4,2)\

Review Comment:
   agree



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