Skip to content

Add variant_strip_nulls expression#56864

Open
bojana-db wants to merge 2 commits into
apache:masterfrom
bojana-db:variant-strip-nulls
Open

Add variant_strip_nulls expression#56864
bojana-db wants to merge 2 commits into
apache:masterfrom
bojana-db:variant-strip-nulls

Conversation

@bojana-db

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Adds the SQL function variant_strip_nulls(v[, includeArrays]), which recursively removes Variant null fields from objects (and, by default, Variant null elements from arrays) in a Variant value.

Details:

  • Object path: a field whose value is a Variant null (the JSON null literal) is removed entirely; recursion walks nested objects and arrays at all levels;
  • includeArrays (BOOLEAN, default true): when true, Variant null elements are also removed from arrays; when false, array null elements are kept, but null fields of objects nested anywhere (including inside arrays) are still stripped;
  • Empty containers are preserved: an object/array emptied by stripping stays {} / []; the parent is never collapsed to NULL;
  • Non-container inputs — scalars and a top-level Variant null (parse_json('null')) — are returned unchanged;
  • NULL intolerant: any NULL argument returns NULL.

Why are the changes needed?

There is no built-in way to drop Variant null entries from a Variant; today users must convert it to another type (e.g. a map) and back.

Does this PR introduce any user-facing change?

Yes, a new SQL function (and Scala/Python functions API.

How was this patch tested?

Unit tests.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code with Claude Opus 4.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant