-
Notifications
You must be signed in to change notification settings - Fork 1.4k
add scalar function for cast so it can be calculated at compile time #8535
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 scalar function for cast so it can be calculated at compile time #8535
Conversation
3d8700a to
49c49a2
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.
Great to see we can leverage the PinotDataType to make it so simple
...ommon/src/main/java/org/apache/pinot/common/function/scalar/DataTypeConversionFunctions.java
Outdated
Show resolved
Hide resolved
...ommon/src/main/java/org/apache/pinot/common/function/scalar/DataTypeConversionFunctions.java
Outdated
Show resolved
Hide resolved
49c49a2 to
322d7d2
Compare
...ommon/src/main/java/org/apache/pinot/common/function/scalar/DataTypeConversionFunctions.java
Outdated
Show resolved
Hide resolved
322d7d2 to
6c09550
Compare
Codecov Report
@@ Coverage Diff @@
## master #8535 +/- ##
============================================
- Coverage 70.65% 64.03% -6.63%
- Complexity 4286 4292 +6
============================================
Files 1674 1636 -38
Lines 87743 86054 -1689
Branches 13279 13115 -164
============================================
- Hits 61999 55102 -6897
- Misses 21439 26956 +5517
+ Partials 4305 3996 -309
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
6c09550 to
8162a15
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.
Currently CastTransformFunction doesn't support multi-valued column casting. We should keep the scalar function and transform function consistent (either both support MV or both not support MV). IMO multi-value handling is a little bit tricky because of the array type (primitive vs boxed), and we should add some queries test to ensure it works end-to-end and covers ingestion, compilation, aggregation and post-aggregation. I'd suggest first adding the basic support for SV, and then having a separate PR to add the MV support
...ommon/src/main/java/org/apache/pinot/common/function/scalar/DataTypeConversionFunctions.java
Outdated
Show resolved
Hide resolved
...ommon/src/main/java/org/apache/pinot/common/function/scalar/DataTypeConversionFunctions.java
Outdated
Show resolved
Hide resolved
...ommon/src/main/java/org/apache/pinot/common/function/scalar/DataTypeConversionFunctions.java
Outdated
Show resolved
Hide resolved
...n/src/test/java/org/apache/pinot/common/function/scalar/DataTypeConversionFunctionsTest.java
Outdated
Show resolved
Hide resolved
|
Some thoughts:
|
I agree that dropping MV support would simplify this a lot. |
I agree, this is essentially what adding this scalar function allows an existing mechanism to do. This change allows replacing the cast function over a literal or over another function which can be calculated at compile time with the literal, by making a function available during query compilation - see |
b0262c9 to
bab4481
Compare
|
Dropped MV support. Testing for:
|
| } | ||
|
|
||
| @Test | ||
| public void testCastSum() { |
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.
CAST is not being tested in this SQL because the operator chain compiled in server side doesn't do the casting (it is actually done in PostAggregationFunction.java)
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.
Yes, I realise it isn't being called here.
| } | ||
|
|
||
| @ScalarFunction | ||
| public static Object cast(Object value, String targetTypeLiteral) { |
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.
ScalarFunction / FunctionInvoker doesn't provide a dynamic return type resolution at runtime --> e.g. determine what's being returned based on the argument passed in. which is exactly what's needed here.
The SQL in the non-literal test cases are actually compiled into CastTransformFunction which does support result metadata --> that's dynamically determined.
What's missing here is a "CAST" that's not a transform function, which require changes to function invoker.
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 this works fine when invoked in a filter to handle the case this PR targets - compile time replacement. You're right that it's not getting invoked after aggregation functions though.
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 can follow up with a separate fix if you agree @richardstartin
Agreed @Jackie-Jiang |
|
Can we get this merged then? @Jackie-Jiang @walterddr |
Fixes #8534
Allows
CompileTimeFunctionsInvokerto perform casts on literals and constant functions of literals, which ensures indexes and metadata can be used in queries.