Uh oh!
There was an error while loading. Please reload this page.
[PHOENIX-1814] Exponential notation parsing and tests - #67
Conversation
There was a problem hiding this comment.
Instead of creating a DECIMAL (which maps to PDecimal that uses a BigDecimal), create a rule for DOUBLE which matches the e notation and returns a PDouble instead (which uses a Java double). You could potentially conditionally return a PFloat versus a PDouble depending on the precision used, but not sure we really need to do that. This is the way I've seen other databases make it possible to define a literal that's a double instead of a DECIMAL or NUMERIC.
There was a problem hiding this comment.
While investigating ParseNodeFactory, it looks like all numbers are parsed as real numbers (big decimal), or whole numbers (slightly more logic to try to fit them into ints, Longs, or BigDecimals). Just to clarify, you want me to create a new method in ParseNodeFactory to try to parse doubles, then update the Antlr tree to use that new method?
There was a problem hiding this comment.
I don't think any new methods in ParseNodeFactory will be necessary, as you can use the factory.literal(Object o) method and if the Object is an instanceof Double, it'll do the right thing. You will need the grammar change, but just create a new top level rule for it instead of adding it to DECIMAL. When it matches, you can do something like this:
$ret = factory.literal(Double.valueOf(token.getText()));
There was a problem hiding this comment.
I think it looks good. Not sure if there's an official syntax for parsing an E notation for SQL-92. This requires that the E notation be there, which is what we want. These are all valid then:
.1 e 100
.01 e + 100
1. e -100
1.23 e 200
There was a problem hiding this comment.
All of those will work, and we capture 'e' and 'E' as well. The only one that wont work is "+1.5e-7" (listed in the description of https://issues.apache.org/jira/browse/PHOENIX-1814 as an example value). I tested inserting regular numbers (non-exponential notation) with a '+' before them and the value doesn't parse at all.
There was a problem hiding this comment.
FWIW this is the notation Python uses to parse numbers in exponential notation.
There was a problem hiding this comment.
@JamesRTaylor here is a test that verifies that the internal representation of an exponential number is infact a Double.
stoty
commented
Aug 1, 2023
This has already been merged. |
No description provided.