Fix #5176: Return actual null from JSON_EXTRACT for missing/null paths#5196
Conversation
… missing/null paths The doJsonize() method in JsonExtractFunctionImpl was explicitly converting null values to the string "null". When JSON_EXTRACT encounters a missing path or an explicit JSON null value, it should return actual null instead of the string "null". Signed-off-by: opensearchpplteam <opensearchpplteam@gmail.com>
…arch-project#5176) Address review feedback: - Add integration test for null-return behavior (missing path and explicit null) - Add integration test for multi-path extraction with missing path - Add unit tests for multi-path extraction where some/all paths are missing Signed-off-by: opensearchpplteam <opensearchpplteam@gmail.com>
PR Reviewer Guide 🔍(Review updated until commit abdc19d)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to abdc19d Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit d3f1413
Suggestions up to commit b6e1150
|
Signed-off-by: opensearchpplteam <opensearchpplteam@gmail.com>
|
Persistent review updated to latest commit d3f1413 |
…t#5176) Signed-off-by: opensearchpplteam <opensearchpplteam@gmail.com>
|
Persistent review updated to latest commit abdc19d |
Description
Root cause:
JsonExtractFunctionImpl.doJsonize()explicitly returned the string"null"when the candidate object wasnull. When JSON_EXTRACT encounters a missing path or an explicit JSON null value, both Calcite'sjsonQuery()andjsonValue()return Javanull, anddoJsonize(null)converted this to string"null"instead of propagating actualnull.Fix: Changed
doJsonize()to returnnull(Java null) when candidate is null. The function's return type is already declared asSTRING_FORCE_NULLABLE(nullable VARCHAR), so Calcite's expression framework correctly handles null returns. This is consistent with other JSON UDFs in the codebase (e.g.,JsonExtractAllFunctionImpl).Testing:
CalcitePPLJsonBuiltinFunctionITverifying null-return behavior through the REST API for both missing paths and explicit JSON null values, plus multi-path extraction with missing pathsRelated Issues
#5176
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.