This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new b24720449 minor: make parsing slightly more efficient + functional 
(#3432)
b24720449 is described below

commit b24720449ba447ed32d621c48eaf2e8e447eccc4
Author: Andrew Lamb <[email protected]>
AuthorDate: Sat Sep 10 10:00:05 2022 -0400

    minor: make parsing slightly more efficient + functional (#3432)
---
 datafusion/sql/src/planner.rs | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index 46dfd0901..7a1b8b6ae 100644
--- a/datafusion/sql/src/planner.rs
+++ b/datafusion/sql/src/planner.rs
@@ -2705,14 +2705,17 @@ 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> {
-    match (n.parse::<i64>(), n.parse::<f64>()) {
-        (Ok(n), _) => Ok(lit(n)),
-        (Err(_), Ok(n)) => Ok(lit(n)),
-        (Err(_), Err(_)) => Err(DataFusionError::from(ParserError(format!(
-            "Cannot parse {} as i64 or f64",
-            n
-        )))),
-    }
+    // 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)]

Reply via email to