andygrove commented on code in PR #3397:
URL: https://github.com/apache/arrow-datafusion/pull/3397#discussion_r965991019
##########
datafusion/sql/src/planner.rs:
##########
@@ -2678,9 +2683,10 @@ 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>() {
- Ok(n) => Ok(lit(n)),
- Err(_) => Ok(lit(n.parse::<f64>().unwrap())),
+ 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)))),
}
Review Comment:
It may be simpler to do this in two steps?
```suggestion
match n.parse::<i64>() {
Ok(n) => Ok(lit(n)),
_ => match n.parse::<f64>() {
Ok(n) => Ok(lit(n)),
_ => Err(DataFusionError::from(ParserError(format!("Cannot parse
{} as i64 or f64", n)))),
}
}
```
--
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]