Fix #5176: Return actual null from JSON_EXTRACT for missing/null paths#5196
Fix #5176: Return actual null from JSON_EXTRACT for missing/null paths#5196opensearchpplteam wants to merge 2 commits intoopensearch-project:mainfrom
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 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
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.