Mark JSON-bearing string fields with is_json metadata#111
Merged
adriangb merged 4 commits intodatafusion-contrib:mainfrom Apr 25, 2026
Merged
Mark JSON-bearing string fields with is_json metadata#111adriangb merged 4 commits intodatafusion-contrib:mainfrom
adriangb merged 4 commits intodatafusion-contrib:mainfrom
Conversation
`json_get_array` returned `List<Utf8>` whose items are raw JSON strings, but the inner field had no `is_json: true` metadata, so downstream consumers could not detect that the items were JSON. Also mark `json_get_json`'s top-level `Utf8` return field (it returns a raw JSON sub-document). Centralizes the metadata construction in a shared `is_json_metadata()` helper and reuses it from `common_union`. `json_as_text` is intentionally not marked, since for `Peek::String` it returns the unescaped string value (no surrounding quotes), so the output is not consistently valid JSON. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR standardizes how JSON-bearing string outputs are annotated across the JSON UDFs by ensuring Arrow Field metadata includes is_json: true wherever the returned Utf8 (or inner Utf8 list items) contains raw JSON, enabling downstream consumers to reliably detect JSON strings.
Changes:
- Add a shared
is_json_metadata()helper and reuse it for JSON-bearingFieldmetadata. - Mark
json_get_array’s innerUtf8list item field as JSON in both the declared return type and the producedListArraybuilder field. - Mark
json_get_json’s returnedUtf8field as JSON viareturn_field_from_args, and add regression tests for both UDFs.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/common.rs |
Introduces is_json_metadata() helper for consistent is_json field metadata creation. |
src/common_union.rs |
Reuses is_json_metadata() instead of duplicating inline metadata construction for union fields. |
src/json_get_array.rs |
Ensures the list item Field for json_get_array is marked is_json and that produced ListArrays carry the same metadata. |
src/json_get_json.rs |
Sets is_json metadata on the returned field via return_field_from_args. |
tests/main.rs |
Adds tests asserting JSON metadata is present on both schema fields and produced arrays. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
`is_json_metadata()` was ambiguous about direction (check vs. mark). The helper is a constructor of metadata that marks a field as containing JSON-encoded data. Renaming to `json_field_metadata()` makes that unambiguous and stays correct if more keys (e.g. canonical Arrow extension keys) are added to the returned map in the future. Move it to `src/common_union.rs`, which already houses JSON-typing concerns. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
json_get_arrayreturnsList<Utf8>whose items are raw JSON strings, but the inner field was missing theis_json: truefield metadata. This adds it on both the declared return type and the producedListArray(viaListBuilder::with_field), so downstream consumers can detect that the items are JSON.json_get_jsonreturnsUtf8containing a raw JSON sub-document; addedis_json: trueon the top-level return field viareturn_field_from_args.is_json_metadata()helper incommon.rsand reused it incommon_union.rs(was duplicated inline).Audit notes
While auditing, I checked every UDF for missing JSON metadata:
json_get_arrayUtf8items are JSONjson_get_jsonUtf8is raw JSONjson_get/json_from_scalarJsonUnion(array/object members are JSON)union_fields()json_as_textjson_object_keysjson_get_str/int/float/bool,json_length,json_containsjson_as_textis intentionally left unmarked because forPeek::Stringit returns the unescaped string value (no surrounding quotes), so the output is not consistently valid JSON. Happy to revisit if you'd prefer it marked.Test plan
cargo test— all 154 tests passcargo clippy --all-targets— cleantest_json_get_array_inner_field_is_json_metadataverifies the inner field metadata both in schema and in the producedListArraytest_json_get_json_is_json_metadataverifies the top-level field metadata🤖 Generated with Claude Code