Skip to content

[Variant] Parse VariantPath strings with Spark's path syntax - #12247

Merged
sdf-jkl merged 2 commits into
apache:mainfrom
sdf-jkl:variant-path-spark-grammar
Nov 18, 2026
Merged

sdf-jkl merged 2 commits into
apache:mainfrom
sdf-jkl:variant-path-spark-grammar

Conversation

@sdf-jkl

@sdf-jkl sdf-jkl commented Nov 13, 2026

Copy link
Copy Markdown
Member

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 $.a looked up a field called $ and returned nothing.

#11627 settled on Spark's variant_get path 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's VariantPathParser: $, then any number of .name, ['name'], ["name"] or [N]. $ alone is the empty path.
  • New VariantPath::parse(path, QuotedKeyEscapes). Decode, the default used by try_from, decodes \\, \', \", \/, \b, \f, \n, \r, \t, \uXXXX and surrogate pairs as Spark 4.4 does. Literal keeps backslashes as Spark 4.2 and 4.3 do, for engines that target those versions.
  • [*] stays as an arrow-rs extension for ShreddedSchemaBuilder. variant_get and Variant::get_path already reject it.
  • Doc examples, tests and the path benchmark use $ paths.
Path Before After, Decode After, Literal
a.b a, b error error
"" root error error
$.a $, a a a
$.a]b error a]b a]b
$['a\nb'] $, anb a, newline, b a\nb
$['a\qb'] $, aqb a\qb a\qb
$[2147483648] $, index 2147483648 error error

Are these changes tested?

Yes. parquet-variant/src/path.rs has 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 keys anb, a\nb and a<newline>b and 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. Literal matches 4.3 and Decode matches 4.4 on every path except $[*], which Spark rejects.

Are there any significant user-facing changes?

Yes, these are breaking:

  • String paths must start with $. Prefix $., or $ before a leading [. Use $ instead of "" for the root. This includes ShreddedSchemaBuilder::with_path("$.items[*].id", ...).
  • Backslashes in quoted field names have new meanings, shown in the table above.
  • .name runs to the next . or [, so it can now contain ]. Indexes above i32::MAX are errors.

New public API: VariantPath::parse and QuotedKeyEscapes.

Writing a VariantPath back to a string (Spark's quoteKey) 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

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]>
@boring-cyborg boring-cyborg Bot added the parquet-variant parquet-variant* crates label Nov 13, 2026
@sdf-jkl

sdf-jkl commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

run benchmark variant_path

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: variant_path

Sharding factor: 1 (1 workers).

Comparing variant-path-spark-grammar (07b11bb) to 0ada6ff (merge-base) diff

Run configuration
run benchmark variant_path
shards: 1

Results will be posted when all workers finish.


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Target: variant_path

Comparing variant-path-spark-grammar (07b11bb) to 0ada6ff (merge-base) diff

Run configuration
run benchmark variant_path
shards: 1
Details
group                                       base                                   changed
-----                                       ----                                   -------
variant_path_parse/bracket_escaped_field    1.17     68.1±0.43ns        ? ?/sec    1.00     58.4±0.25ns        ? ?/sec
variant_path_parse/bracket_indexes          1.24     39.3±0.28ns        ? ?/sec    1.00     31.6±0.16ns        ? ?/sec
variant_path_parse/bracket_quoted_fields    1.46     54.0±0.24ns        ? ?/sec    1.00     37.0±0.14ns        ? ?/sec
variant_path_parse/bracket_wildcards        1.30     36.0±0.56ns        ? ?/sec    1.00     27.7±0.20ns        ? ?/sec
variant_path_parse/dot_fields               1.06     31.2±0.15ns        ? ?/sec    1.00     29.4±0.26ns        ? ?/sec
variant_path_parse/mixed                    1.11     84.1±0.30ns        ? ?/sec    1.00     75.8±0.19ns        ? ?/sec

Per-runner information
variant_path — shard 1/1

Node: gk3-benchmark-cluster-nap-ez8gwx9u-c46ae595-fnhr

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c6867442825-5082-c225j 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench variant_path
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

base (merge-base)

Metric Value
Wall time 65.0s
Peak memory 9.4 MiB
Avg memory 7.5 MiB
CPU user 58.8s
CPU sys 0.0s
Peak spill 0 B

branch

Metric Value
Wall time 60.0s
Peak memory 9.9 MiB
Avg memory 7.8 MiB
CPU user 56.1s
CPU sys 0.0s
Peak spill 0 B

File an issue against this benchmark runner

@sdf-jkl

sdf-jkl commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

@alamb PTAL

@alamb alamb added the api-change Breaking API change, needs to wait for a major version release label Nov 14, 2026
@alamb

alamb commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

the basic idea looks great to me (thank you for the table in this PR)

I think the key question is if we want to send out breaking API changes in a minor release. Technically it is probably ok given

https://crates.io/crates/parquet-variant

Screenshot 2026-11-14 at 9 08 38 AM

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sdf-jkl -- I think some of the docs could be improved, but the semantics look good to me.

My biggest question is if we should wait for 61 or just merge now

any thoughts @klion26 or @scovich or @adriangb ?

Comment thread parquet-variant/src/path.rs Outdated
///
/// # Path strings
///
/// [`VariantPath::try_from`] parses the paths that Spark's `variant_get`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_get function (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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would help to:

  1. Start with a simpler example $.a.b
  2. Then work up to the more advanced example
  3. Keep the inline commentary

@scovich

scovich commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

My biggest question is if we should wait for 61 or just merge now

any thoughts @klion26 or @scovich or @adriangb ?

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.

@sdf-jkl

sdf-jkl commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

@scovich! 👋

@Rich-T-kid Rich-T-kid added enhancement New feature/addition next-major-release the PR has API changes and it waiting on the next major version labels Nov 16, 2026
@sdf-jkl

sdf-jkl commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

I wish I had a better sense of how many downstream users relied on the old semantics and also would have difficulty upgrading.

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.

@scovich

scovich commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

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?

@alamb

alamb commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

So time to rip off the 🩹 . I agree let's merge this

@alamb alamb removed the next-major-release the PR has API changes and it waiting on the next major version label Nov 17, 2026
@sdf-jkl

sdf-jkl commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

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]>
@sdf-jkl
sdf-jkl added this pull request to the merge queue Nov 18, 2026
@sdf-jkl

sdf-jkl commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

Thank you @alamb @scovich 🙏

@alamb

alamb commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

🚀

Merged via the queue into apache:main with commit 8e2f379 Nov 18, 2026
22 checks passed
@Jefffrey

Copy link
Copy Markdown
Contributor

just to check, this means this will go in 60.3.0?

@sdf-jkl

sdf-jkl commented Nov 19, 2026 •

Copy link
Copy Markdown
Member Author

That argues for pushing this ASAP because then the behavior change is unobservable and all downstream users start with good habits?

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

@Jefffrey

Copy link
Copy Markdown
Contributor

yeah we might need to revert this until after 60.3.0 if thats not too much trouble

@alamb

alamb commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Revert PR: #12332

@alamb

alamb commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

yeah we might need to revert this until after 60.3.0 if thats not too much trouble

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.

@sdf-jkl
sdf-jkl deleted the variant-path-spark-grammar branch November 19, 2026 17:35
shashank11yadav pushed a commit to shashank11yadav/arrow-rs that referenced this pull request Nov 19, 2026
@Jefffrey Jefffrey added development-process Internal changes; PRs with this label are excluded from changelog and removed enhancement New feature/addition api-change Breaking API change, needs to wait for a major version release labels Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

development-process Internal changes; PRs with this label are excluded from changelog parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define VariantPath's grammar and compatibility target

6 participants