-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add commonly used math, string and date scalar functions in Pinot #8304
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
5c56be1 to
41c2050
Compare
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/TrigonometricFunctions.java
Outdated
Show resolved
Hide resolved
Jackie-Jiang
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.
Thanks for adding these missing functions. Can you please add unit test to ensure the desired behavior?
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/TrigonometricFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/TrigonometricFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/DateTimeFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #8304 +/- ##
============================================
+ Coverage 70.76% 70.96% +0.20%
- Complexity 4278 4283 +5
============================================
Files 1655 1661 +6
Lines 86665 87046 +381
Branches 13067 13134 +67
============================================
+ Hits 61327 61772 +445
+ Misses 21095 21012 -83
- Partials 4243 4262 +19
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
@KKcorps There are 6 hidden conversations (github automatically collapsed them) unaddressed, please take a look. |
...rc/main/java/org/apache/pinot/core/operator/transform/function/LiteralTransformFunction.java
Outdated
Show resolved
Hide resolved
|
@Jackie-Jiang @richardstartin I have added the unit-tests as well. |
.../src/main/java/org/apache/pinot/core/operator/transform/function/PowerTransformFunction.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/apache/pinot/core/operator/transform/function/PowerTransformFunction.java
Outdated
Show resolved
Hide resolved
...in/java/org/apache/pinot/core/operator/transform/function/RoundDecimalTransformFunction.java
Outdated
Show resolved
Hide resolved
...java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunction.java
Outdated
Show resolved
Hide resolved
...java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunction.java
Outdated
Show resolved
Hide resolved
...java/org/apache/pinot/core/operator/transform/function/TruncateDecimalTransformFunction.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.
🥇
...java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunction.java
Outdated
Show resolved
Hide resolved
f38c59d to
e98c403
Compare
.../java/org/apache/pinot/core/operator/transform/function/TrigonometricTransformFunctions.java
Outdated
Show resolved
Hide resolved
richardstartin
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.
This looks good to me, and I appreciate that this has extended a long way beyond its original scope so thanks for being so patient and for your determination. Can we just get rid of the stray semicolons in the trig functions before merging please.
0829dcb to
0a63209
Compare
Jackie-Jiang
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.
Mostly good
pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/apache/pinot/core/operator/transform/function/PowerTransformFunction.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.
We may avoid the boxing/unboxing using primitive double and use NaN to represent not set, same for other functions
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.
Made the change for this class. Is it fine if I use Integer.MIN_VALUE for other classes or leaved the boxed implementation as it is for now? I would prefer the latter.
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.
Using boxed value is fine if we unbox the value before getting into the loop (not sure if JVM will do the optimization, cc @richardstartin)
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 would just use a flag rather than sentinel values. I don't know what the best thing to do is, but it probably isn't very important anyway. If this ever shows up as a bottleneck we can fix it.
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 like the idea of using a boolean flag, so that it is guaranteed to have the desired behavior without potentially paying the cost of unboxing the values
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.
Yeah, boolean flags are better. using them.
...java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunction.java
Outdated
Show resolved
Hide resolved
...rc/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
Outdated
Show resolved
Hide resolved
2830ca3 to
e81d81c
Compare
Jackie-Jiang
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.
LGTM otherwise
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.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.
(minor) Rename the second parameter to scale for readability
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.
Can we use Math.round() for this function as BigDecimal calculation is much more costly? If not, please add some comments explaining the reason. Same for the one with scale
...in/java/org/apache/pinot/core/operator/transform/function/RoundDecimalTransformFunction.java
Outdated
Show resolved
Hide resolved
| _rightTransformFunction), | ||
| "Argument must be single-valued with type INT or LONG for transform function: %s", getName()); | ||
| } else { | ||
| _rightTransformFunction = null; |
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.
Can simplify the handling by setting _scale = 0 and _fixedScale = 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.
The reason for doing it this way is to use optimal Math.round and Math.floor for this case instead of relying on BigDecimal represenation.
There are some functions which are missing from Pinot currently which are part of standard SQL. We can still do some of these operations (except for trignometric ones) by writing composite SQL expressions using existing functions. This however leads to complex queries and it is better we support these functions directly in Pinot.
For better performance, Transform function classes have also been added for the new Math functions. The classes have the same function name as scalar and will be given first preference when function is used.
This also helps in providing better support for third party tools such as Tableau.