jonahgao opened a new pull request, #7648: URL: https://github.com/apache/arrow-datafusion/pull/7648
## Which issue does this PR close? N/A ## Rationale for this change The option `datafusion.sql_parser.parse_float_as_decimal` does not work on negative numbers. ``` DataFusion CLI v31.0.0 0 rows in set. Query took 0.001 seconds. ❯ set datafusion.sql_parser.parse_float_as_decimal=true; 0 rows in set. Query took 0.001 seconds. ❯ select 1.1, -1.1; +--------------------------+---------------+ | Decimal128(Some(11),2,1) | Float64(-1.1) | +--------------------------+---------------+ | 1.1 | -1.1 | +--------------------------+---------------+ 1 row in set. Query took 0.006 seconds. ``` The number `-1.1` is parsed as a Float64 type, but it is expected to be of Decimal type. This is because the expr `SQLExpr::Value(Value::Number(n, _))` only contains unsigned numbers. https://github.com/sqlparser-rs/sqlparser-rs/blob/7723ea56c5119c7d1a15233c18eb2aaf48b60dc0/src/tokenizer.rs#L53-L54 Negative numbers are parsed as `UnaryOperator::Minus`, but handling `UnaryOperator::Minus` is not compatible with the option `datafusion.sql_parser.parse_float_as_decimal` . https://github.com/apache/arrow-datafusion/blob/19174e76656adec353f85ff468654ba210dc9cda/datafusion/sql/src/expr/unary_op.rs#L38-L51 ## What changes are included in this PR? - Make parse_float_as_decimal work on negative numbers - Parsing `i64::MIN` as an Int64 type, previously it was a Float64. ``` ❯ select -9223372036854775808; +-------------------------------+ | Float64(-9223372036854776000) | +-------------------------------+ | -9.223372036854776e18 | +-------------------------------+ ``` - Support parsing `0.` as Decimal, previously raise an error. ``` ❯ select 0.; SQL error: ParserError("Cannot parse as i128 when building decimal: cannot parse integer from empty string") ``` ## Are these changes tested? Yes ## Are there any user-facing changes? No -- 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]
