apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
5.9k stars 1.11k forks source link

feat: make `parse_float_as_decimal` work on scientific notaion #8486

Open Weijun-H opened 9 months ago

Weijun-H commented 9 months ago

Is your feature request related to a problem or challenge?

Datafusion can't parse float as decimal if it is scientific notation.

DataFusion CLI v33.0.0
❯ set datafusion.sql_parser.parse_float_as_decimal=true;
0 rows in set. Query took 0.014 seconds.

❯ select 10e10;
SQL error: ParserError("Cannot parse 10e10 as i128 when building decimal: invalid digit found in string")
❯ select -10e10;
SQL error: ParserError("Cannot parse 10e10 as i128 when building decimal: invalid digit found in string")

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

No response

Weijun-H commented 9 months ago

I will take this ticket

alamb commented 9 months ago

Maybe @andygrove has some additional context / correct expected behavior -- he seems to have introduced this feature in https://github.com/apache/arrow-datafusion/pull/4102

Weijun-H commented 9 months ago
set datafusion.sql_parser.parse_float_as_decimal=true;

Yes, it supports this feature only when set datafusion.sql_parser.parse_float_as_decimal=false;

alamb commented 9 months ago

For the record, here is what happens by default (set datafusion.sql_parser.parse_float_as_decimal=false;)

❯ select 10e10;
+-----------------------+
| Float64(100000000000) |
+-----------------------+
| 1.0e11                |
+-----------------------+
1 row in set. Query took 0.024 seconds.
andygrove commented 8 months ago

I made a comment in https://github.com/apache/arrow-datafusion/pull/4102 that We cannot enable by default until decimal support is farther along. Unfortunately, I do not remember the specifics. Now that decimal support is farther along, maybe we can revisit this and try enabling by default (and eventually deprecate the option).