Add commonly used math, string and date scalar functions in Pinot #8304
Add commonly used math, string and date scalar functions in Pinot #8304KKcorps merged 49 commits intoapache:masterfrom
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.
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
...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.
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
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.
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.
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.
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.
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.
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.
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
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.
(minor) Rename the second parameter to scale for readability
There was a problem hiding this comment.
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.
Can simplify the handling by setting _scale = 0 and _fixedScale = true
There was a problem hiding this comment.
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.