Repository navigation
Fold a string cast of json_get to json_as_text - #146
Merged
Merged
Conversation
`CAST(json_get(j, 'k') AS VARCHAR)` folded to `json_get_str`, which is NULL for any JSON value that is not a string. A cast to a string type now folds to `json_as_text`, the function behind `->>`: a JSON string still gives its value without quotes, a number, boolean, object or array now gives its JSON text, and a JSON null or a missing key still gives NULL. `json_as_text` has the same return type rules as `json_get_str`, so the cast is dropped or kept in the same cases as before.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #146 +/- ##
==========================================
- Coverage 94.00% 93.95% -0.06%
==========================================
Files 18 18
Lines 1902 1902
Branches 1902 1902
==========================================
- Hits 1788 1787 -1
Misses 64 64
- Partials 50 51 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Sep 29, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CAST(json_get(j, 'k') AS VARCHAR), and so(j -> 'k')::text, is folded tojson_get_str. That function returns NULL for every JSON value that is not a string:Other engines (Postgres, DuckDB, ClickHouse, Spark) return text for a number, boolean, object or array cast to a string. (Postgres and DuckDB quote strings; this keeps the existing unquoted result.) With this change a cast to
Utf8,Utf8VieworLargeUtf8folds tojson_as_text, the function behind->>:nullor a missing key gives NULL, as before.Only results that were NULL change. For example,
json_get(j, 'k')::string = 'abc'is nowfalseinstead of NULL whenkholds an array or object. Usejson_get_strto read only JSON strings.json_as_texthas the same return type rules asjson_get_str:Utf8, orDictionary(Int64, Utf8)for a dictionary-encoded JSON argument. So the cast is dropped or kept in the same cases as before.Tests cover each JSON value type, a nested path, each string target type, and plain, view, large and dictionary-encoded JSON input.