FrankChen021 opened a new pull request #11722: URL: https://github.com/apache/druid/pull/11722
Fixes #11292. ### Description This PR allows users to use [JsonPath](https://github.com/jayway/JsonPath) functions in JsonPath expressions during ingestion. Currently, JsonPath is used to extract values inside a JSON object. However, JsonPath supports a bunch of function expressions which are not supported by Druid now. For example, '$.property_name.length()' can be used to get the length of a Json array object 'property_name'. This function would be useful in some cases. The reason why Druid does not support JsonPath functions is very simple, the original code assumes that the JsonPath expressions would return a Json object. However, if a JsonPath function is applied, the return type is the raw object instead of Json object. So fixing the bug of 'length()' function also brings support to other functions. I also brings the support of these functions to orc/avro/parquet data format. Following matrix shows the current supported JsonPath functions and corresponding data formats. | Function | Description | Output type | json | orc | avro | parquet | | :----------| :------------------------------------------------------------------ |:----------- |:-----|:----|:-----|:-----| | min() | Provides the min value of an array of numbers | Double | ✓ | ✓ | ✓ | ✓ | | max() | Provides the max value of an array of numbers | Double | ✓ | ✓ | ✓ | ✓ | | avg() | Provides the average value of an array of numbers | Double | ✓ | ✓ | ✓ | ✓ | | stddev() | Provides the standard deviation value of an array of numbers | Double | ✓ | ✓ | ✓ | ✓ | | length() | Provides the length of an array | Integer | ✓ | ✓ | ✓ | ✓ | | sum() | Provides the sum value of an array of numbers | Double | ✓ | ✓ | ✓ | ✓ | | concat(X) | Provides a concatenated version of the path output with a new item | like input | ✓ | ✗ | ✗ | ✗ | | append(X) | add an item to the json path output array | like input | ✓ | ✗ | ✗ | ✗ | | keys() | Provides the property keys (An alternative for terminal tilde ~) | Set<E> | ✗ | ✗ | ✗ | ✗ | - `append`, `concat` are not fully supported, because I don't see there's strong need to use them. - `keys()` is not supported because it's not supported by current JsonPath library used by Druid. And also I don't see there's a strong need to use this JsonPath function. <hr> <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. --> This PR has: - [X] been self-reviewed. - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.) - [X] added documentation for new or modified features or behaviors. - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links. - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md) - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader. - [X] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met. - [X] added integration tests. - [X] been tested in a test Druid cluster. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
