-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Polymorphic binary arithmetic scalar functions #14089
Polymorphic binary arithmetic scalar functions #14089
Conversation
I've removed the polymorphic division function implementation because that breaks backward compatibility for the v1 query engine. |
bfc0da0
to
ff6a73b
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #14089 +/- ##
============================================
+ Coverage 61.75% 64.11% +2.36%
- Complexity 207 1538 +1331
============================================
Files 2436 2600 +164
Lines 133233 143505 +10272
Branches 20636 21982 +1346
============================================
+ Hits 82274 92014 +9740
+ Misses 44911 44722 -189
- Partials 6048 6769 +721
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
ff6a73b
to
42091c8
Compare
...pache/pinot/common/function/scalar/arithmetic/PolymorphicBinaryArithmeticScalarFunction.java
Outdated
Show resolved
Hide resolved
42091c8
to
223bb2e
Compare
Per the PG behavior: https://www.postgresql.org/docs/current/functions-math.html |
Ideally yes, but that would break backward compatibility too (just like the division case). In PG,
Do you mean a specific query option for arithmetic related operations or just a generic option under which we'd bucket all such compatibility breaking but SQL compliant changes in the future? Also, the v2 behavior should already be SQL compliant because Calcite will make sure that the return type for the division operator is appropriate (and Pinot makes sure to cast internal values based on the expected return type of an operator). |
Also, if we do end up introducing such a query option in the future, we should probably make sure that the arithmetic transform functions are updated to respect the query option too. For instance, there is an AdditionTransformFunction which also always returns |
I was thinking adding a general query option to turn v1 engine into standard sql compatible mode, so that v2 engine can enable it and get standard sql behavior. Even if we cast after getting the result, it might already lose precision and give inaccurate result. Currently, when adding 2 ints, will v2 engine return int? For division, PG always round towards 0, which is not followed if we cast the result after execution. |
Basically we want a general way so that we can add standard SQL support without breaking existing v1 queries |
Yes, this is a valid point. Also, an expression like
Yes, it does, which seems somewhat problematic because something like
I wasn't able to find any common standard SQL definition for such arithmetic operations. For instance, in MySQL |
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.
We can discuss query options in a different thread. That is orthogonal to this PR
} | ||
|
||
@Override | ||
@Nullable |
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.
(minor) Remove @Nullable
. Same for other places
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.
Actually maybe we should register them with the standard Calcite operator SqlStdOperatorTable.MINUS
?
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.
Ah yeah, I had pushed this change to fix some test failures with direct usages of ADD
, and IIRC operator alias based registering wasn't working for me locally earlier but I checked again and things look good (might've messed something up earlier). I've pushed a commit to use aliases for the standard operators and removed these overrides.
...on/src/main/java/org/apache/pinot/common/function/scalar/arithmetic/MinusScalarFunction.java
Outdated
Show resolved
Hide resolved
...pache/pinot/common/function/scalar/arithmetic/PolymorphicBinaryArithmeticScalarFunction.java
Outdated
Show resolved
Hide resolved
…umMap instead of HashMap; cleanup functionInfoForTypes method in PolymorphicBinaryArithmeticScalarFunction
bc3f33c
to
fbd44ce
Compare
SELECT * FROM mytable WHERE ts BETWEEN now() - 1000 AND now()
fails on the v1 single-stage query engine without these changes. The reason is that during query compilation, the CompileTimeFunctionsInvoker query rewriter will replacenow() - 1000
with the equivalent double value since that's the only available implementation of the minus function -pinot/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
Lines 38 to 41 in 852e4f3
LONG
, we run into an issue since the string could be the scientific representation of the double value: