-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[SQL Compatible] Fix literal type handling #11763
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
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #11763 +/- ##
============================================
+ Coverage 63.08% 63.24% +0.15%
Complexity 1140 1140
============================================
Files 2343 2343
Lines 126320 126335 +15
Branches 19423 19436 +13
============================================
+ Hits 79694 79900 +206
+ Misses 40953 40765 -188
+ Partials 5673 5670 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
pinot-spi/src/main/java/org/apache/pinot/spi/utils/BooleanUtils.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of changing it we should add one more for -1 to make sure the results is actually considered as true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is for backward compatible where we used to allow 0 and 1. We never allow -1, so that shouldn't be needed. More tests are covered in LiteralContextText
pinot-common/src/main/java/org/apache/pinot/common/request/context/LiteralContext.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/request/context/LiteralContext.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this relevant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly relevant, but find this not able to return the error during debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (sqlNumericLiteral.isExact()) {
if (sqlNumericLiteral.isInteger()) {
// long/int
} else {
// float/double
}
} else {
// TODO support exact decimal
// decimal
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect. FLOAT/DOUBLE is not exact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ST_POINT is ANY on 3rd argument, should it be boolean or integer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be boolean. We allow int for backward compatibility only because this function was introduced before BOOLEAN is supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont really think . can be added in function name percentile99.5(col) is not valid. (https://www.postgresql.org/docs/current/xfunc-sql.html)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for percentile(col, 99.5) which is allowed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this even needed? we should handle it in RequestUtils
- AFAIK the arrFloat[rowIdx] will point to the double signature,
- once uncomment the TODO it will use the float signature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed. We cannot directly cast float to double because that will create wrong value (e.g 0.05f -> 0.05000000074505806), then cause wrong result. Added more notes
031b253 to
afd4c0e
Compare
xiangfu0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also put the incompatible items into PR descriptions.
| testTransformFunction(transformFunction, expectedBigDecimalValues); | ||
|
|
||
| expression = RequestContextUtils.getExpression( | ||
| String.format("add(add(12,%s),%s,add(add(%s,%s),'12110.34556677889901122335678',%s),%s)", STRING_SV_COLUMN, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean we won't auto infer big decimal/ts values and enforce the cast always?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. In standard SQL, literal cannot be auto inferred based on its value.
|
This is great, thanks so much for fixing this! |
Currently when literal is single quoted (e.g. 'abc', '123', '1.23'), the type is auto-derived based on the literal itself. Also, it can only derive to big-decimal, timestamp or string but not other numeric types.
In Standard SQL (we reference PostgreSQL convention as standard), single quoted literal has unknown type and the type should be resolved based on the context around the literal (read more here).
This PR:
CASEto follow the PostgreSQL convention (read more here), and fix a bug of reading float value as double typeIncompatible
Following standard SQL, single quoted literal won't have its type auto-derived. In order to create big-decimal literal, user should use
cast('12345.6789' AS DECIMAL)explicitly