-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add ScalarFunction for JSON_EXTRACT_SCALAR #16910
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
base: master
Are you sure you want to change the base?
Conversation
This would also solve #16495 |
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 the contribution! Let's make sure the behavior for the scalar function is the same as JsonExtractScalarTransformFunction
@ScalarFunction | ||
public static Object jsonExtractScalar(Object jsonInput, String jsonPath, String dataType, Object defaultValue) { | ||
try { | ||
switch (dataType.toUpperCase()) { |
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.
Several data types are not supported. Could you please make sure all types supported in JsonExtractScalarTransformFunction
are also supported here?
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 have tried to make it exactly similar to JsonExtractScalarTransformFunction. Can you please verify?
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java
Outdated
Show resolved
Hide resolved
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java
Outdated
Show resolved
Hide resolved
Hi @Jackie-Jiang, Should both follow a consistent behavior? If so, which approach would be preferable, returning the default value (like JsonFunctions) or throwing an exception? |
@manikBS Good finding! Yeah we should make the behavior consistent, and I'd suggest following the behavior of |
@Jackie-Jiang Case: JSON object is malformed, JSON path is malformed, or JSON path does not exist
Case: JSON object and JSON path is correct
can you please review it? |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #16910 +/- ##
============================================
- Coverage 63.55% 63.27% -0.29%
Complexity 1411 1411
============================================
Files 3073 3071 -2
Lines 180687 180504 -183
Branches 27624 27615 -9
============================================
- Hits 114837 114206 -631
- Misses 57003 57546 +543
+ Partials 8847 8752 -95
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:
|
Summary
This PR adds a new scalar function jsonExtractScalar to enable flexible extraction of scalar values from JSON fields in Pinot queries.
Key Changes
Testing