-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add compiler flag to have arithmetic expressions with float-types evaluate to float and not double #202
Comments
short a=1; |
Narrowing "int" to "short" wouldn't be allowed. I'd recommend plugin single row func. |
The code I posted is contrived to demonstrate the issue. Writing single row functions for each of the arithmetic expressions in a query would be more verbose than the existing cast calls. I understand that narrowing an int to a short isn't allowed. The issue is that |
Yeah well in the JVM world |
@bernhardttom I wasn't aware that was the JVM behavior. I've updated the issue to only mention float a = 123;
float b = 123;
System.out.println(((Object)(a + b)).getClass()); // java.lang.Float |
Looks like these should be returning esper/common/src/main/java/com/espertech/esper/common/internal/util/JavaClassHelper.java Lines 309 to 314 in ab90bc7
|
Due to backward compatibility the behavior stays as it is by default. However a compiler flag to change the default behavior can be added. Its possible the SQL standard prescribes it or is another reason this is the default behavior i.e. user request. I'll post when I find something. |
Seems like it's implementation dependant.
https://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt I tested in postgres and it evaluates to a double select 1::real + 1::integer -- "double precision" |
Seems like this isn't a bug. Also, I can rewrite my original query using a float literal. create schema Thing (value float);
create schema ThingPlusOne (value float);
insert into ThingPlusOne select value + 1f as value from Thing; |
For the sake of completeness, here are the truth tables showing the JVM and Esper arithmetic coercion rules JVM Arithmetic Coercion Rules
Esper Arithmetic Coercion Rules
|
I started implementing this and ran into this usage: Line 100 in 8dd0c24
It's being called here: Lines 58 to 63 in 8dd0c24
I need the |
Suggest to check for usages of validateWithoutContext (alt-F7 in Idea). Configuration probably needs to be passed in. |
When using a
float
value in an arithmetic expression, the expression incorrectly evaluates to adouble
instead offloat
. This leads to a lot of unnecessary casts all over the place.The text was updated successfully, but these errors were encountered: