Repository navigation
[Variant] Parse VariantPath strings with Spark's path syntax - #12247
Conversation
VariantPath::try_from(&str) now follows Spark's VariantPathParser: a required `$` root, then `.name`, `['name']`, `["name"]` or `[N]`. Add VariantPath::parse with QuotedKeyEscapes. Decode (the default) decodes backslash escapes in quoted names as Spark 4.4 does. Literal keeps them as Spark 4.2 and 4.3 do. `[*]` stays an extension for shredding schemas. Closes apache#11627. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
run benchmark variant_path |
|
🤖 Benchmark starting (GKE) | trigger Target: variant_path Sharding factor: 1 (1 workers). Comparing variant-path-spark-grammar (07b11bb) to 0ada6ff (merge-base) diff Run configurationrun benchmark variant_path
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: variant_path Comparing variant-path-spark-grammar (07b11bb) to 0ada6ff (merge-base) diff Run configurationrun benchmark variant_path
shards: 1
DetailsPer-runner informationvariant_path — shard 1/1Node: gk3-benchmark-cluster-nap-ez8gwx9u-c46ae595-fnhr Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_pathCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
@alamb PTAL |
| /// | ||
| /// # Path strings | ||
| /// | ||
| /// [`VariantPath::try_from`] parses the paths that Spark's `variant_get` |
There was a problem hiding this comment.
it would be nice to link to docs of variant_get - https://docs.databricks.com/aws/en/sql/language-manual/functions/variant_get
It seems like it is "valid JSONPath" -- so maybe that would be a better way to describe this rather than spark:
Something like
"parses JSONpath (link), the same as Spark's
variant_getfunction (link)"
| /// let path = VariantPath::try_from("foo.bar.baz").unwrap(); | ||
| /// let expected = VariantPath::try_from("foo").unwrap().join("bar").join("baz"); | ||
| /// # use parquet_variant::{QuotedKeyEscapes, VariantPath, VariantPathElement}; | ||
| /// let path = VariantPath::try_from("$.a['b.c'].d[2]['3']").unwrap(); |
There was a problem hiding this comment.
| /// let path = VariantPath::try_from("$.a['b.c'].d[2]['3']").unwrap(); | |
| /// /// You can also convert strings directly into paths using dot notation | |
| /// let path = VariantPath::try_from("$.a['b.c'].d[2]['3']").unwrap(); |
| /// /// You can also convert strings directly into paths using dot notation | ||
| /// let path = VariantPath::try_from("foo.bar.baz").unwrap(); | ||
| /// let expected = VariantPath::try_from("foo").unwrap().join("bar").join("baz"); | ||
| /// # use parquet_variant::{QuotedKeyEscapes, VariantPath, VariantPathElement}; |
There was a problem hiding this comment.
I think it would help to:
- Start with a simpler example
$.a.b - Then work up to the more advanced example
- Keep the inline commentary
Hmm, it's the difference between shipping now or in December? I wish I had a better sense of how many downstream users relied on the old semantics and also would have difficulty upgrading. |
|
@scovich! 👋 |
Last time I checked no one but datafusion-variant is using arrow-rs 60 because datafusion 56 (which updates to arrow-rs 60) is not released yet. |
That argues for pushing this ASAP because then the behavior change is unobservable and all downstream users start with good habits? |
|
So time to rip off the 🩹 . I agree let's merge this |
|
Let me address the suggestions and I'll merge |
Describe the path syntax as JSONPath-based, link Spark's `variant_get`, and start the path string example with `$.a.b`. Also document that `$` is required, that indexes are zero-based, that `$.*` selects a field named `*`, the quote limit in literal mode, and how `Variant::get_path` matches fields and indexes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚀 |
|
just to check, this means this will go in 60.3.0? |
Now that I think about it, people updating to datafusion 56 will get arrow 60.2 and will get a breaking change in 60.3 without notice It would be better to either backport this or revert and wait for the next major release. Sorry, I think I started working on this before the 60.2 got released |
|
yeah we might need to revert this until after 60.3.0 if thats not too much trouble |
|
Revert PR: #12332 |
I agree -- if we got it out in 60.2 it would probably have been ok, but now it will probably be too disruptive. Sorry about that. |
apache#12247)" (apache#12332) Reverts apache#12247 until after 60.3.0, as suggested by @Jefffrey in apache#12247 (comment)

Which issue does this PR close?
Rationale for this change
VariantPath::try_from(&str)had a grammar of its own: paths without a root (a.b),""for the root, and a backslash in brackets that dropped itself before any character. It matched neither JSONPath nor Spark. It also read$as a field name, so a Spark path such as$.alooked up a field called$and returned nothing.#11627 settled on Spark's
variant_getpath syntax. Spark versions differ only in quoted field names: 4.2 and 4.3 keep backslashes literal, and 4.4 (SPARK-59218, on master) decodes escapes. This PR supports both and decodes by default.What changes are included in this PR?
VariantPath::try_from(&str)follows Spark'sVariantPathParser:$, then any number of.name,['name'],["name"]or[N].$alone is the empty path.VariantPath::parse(path, QuotedKeyEscapes).Decode, the default used bytry_from, decodes\\,\',\",\/,\b,\f,\n,\r,\t,\uXXXXand surrogate pairs as Spark 4.4 does.Literalkeeps backslashes as Spark 4.2 and 4.3 do, for engines that target those versions.[*]stays as an arrow-rs extension forShreddedSchemaBuilder.variant_getandVariant::get_pathalready reject it.$paths.DecodeLiterala.ba,b""$.a$,aaa$.a]ba]ba]b$['a\nb']$,anba, newline,ba\nb$['a\qb']$,aqba\qba\qb$[2147483648]$, index 2147483648Are these changes tested?
Yes.
parquet-variant/src/path.rshas table tests for valid paths, invalid paths, quoted escapes in both modes, error messages and borrowed field names. One test builds an object with the keysanb,a\nbanda<newline>band checks that each mode selects a different key.The expected values come from Spark. I ran Spark's own
VariantPathParser(the pyspark 4.3.0 jars, and the spark-catalyst 4.4.0-SNAPSHOT jar built 2026-11-12) and this parser on the same 91 paths.Literalmatches 4.3 andDecodematches 4.4 on every path except$[*], which Spark rejects.Are there any significant user-facing changes?
Yes, these are breaking:
$. Prefix$., or$before a leading[. Use$instead of""for the root. This includesShreddedSchemaBuilder::with_path("$.items[*].id", ...)..nameruns to the next.or[, so it can now contain]. Indexes abovei32::MAXare errors.New public API:
VariantPath::parseandQuotedKeyEscapes.Writing a
VariantPathback to a string (Spark'squoteKey) is not part of this PR.AI usage disclosure
Claude Code wrote the parser port, the tests, the caller updates and this description, and ran the comparison against Spark.
🤖 Generated with Claude Code