Repository navigation
Parse scientific notation and mixed integer/decimal IN lists in row filters - #4371
rahulsmahadev wants to merge 1 commit into
Conversation
The row filter parser only accepted decimals with a fractional part and literal sets of a single numeric kind, so `x > 1e-3` and `x in (1, 2.5)` raised a ParseException. Co-authored-by: Isaac <no-reply@databricks.com>
|
@jackylee-ch could you take a look when you have a chance? This small change to the expression parser lets |
|
Thanks for picking this up! I think the scientific notation part should follow ANSI SQL. In ANSI, Parsing it as a Could we emit a The mixed integer/decimal |
Rationale for this change
The row filter parser rejects two kinds of valid numeric literals:
Decimal literals used pyparsing's
common.real(), which has no exponent, so1e-3parses as1and the rest is left over. A literal set had to be all decimals or all integers, so a list that mixes1and2.5did not parse either.This change uses
common.sci_real(), which accepts everythingcommon.real()does plus an exponent (1e-3,-1.5E3,2.5e1), and lets a literal set mix integers and decimals. Integers becomeLongLiterals and decimal or exponent forms becomeDecimalLiterals; binding uses the existing conversion rules (a decimal column needs a literal with its scale, and an integer column rejects fractional values). The decimal parse action already builds theDecimalfrom the matched text, so exponents are exact. A list that mixes numbers with strings still raises aParseException(test_in_different_types).Are these changes tested?
Yes.
test_scientific_notationandtest_in_mixed_numbersintests/expressions/test_parser.pycover exponents on either side of a comparison and inBETWEEN, and mixed integer/decimalINlists (in both orders) andNOT INlists. Both fail on main with theParseExceptions above and pass with this change.Are there any user-facing changes?
Bug fix: row filter strings accept scientific notation and
INlists that mix integers and decimals. Expressions that parsed before parse to the same result.This pull request and its description were written by Isaac.