Skip to content

fix(variant): support closing brackets inside quoted path fields - #11231

Merged
sdf-jkl merged 2 commits into
apache:mainfrom
DKER2:fix/variant-path-quoted-closing-bracket
Oct 2, 2026
Merged

sdf-jkl merged 2 commits into
apache:mainfrom
DKER2:fix/variant-path-quoted-closing-bracket

Conversation

@DKER2

@DKER2 DKER2 commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Quoted VariantPath fields can contain a literal closing bracket, but the parser currently terminates the bracket segment at the first unescaped ], even when it appears inside matching quotes. This rejects paths such as ["a]b"] and can silently split some field names into multiple path elements.

What changes are included in this PR?

  • Track the active quote while parsing a bracket path element.
  • Treat an unescaped ] as the closing delimiter only outside matching quotes.
  • Preserve the existing \] escape behavior.
  • Document the quote-aware behavior.
  • Add regression coverage for single and double quotes, subsequent path elements, escaped quotes, and the legacy escaped spelling.

Are these changes tested?

Yes. The following checks pass:

  • cargo test -p parquet-variant
  • cargo clippy -p parquet-variant --all-targets --all-features -- -D warnings
  • cargo +stable fmt --all -- --check
  • git diff --check

Are there any user-facing changes?

Yes. Quoted VariantPath fields may now contain an unescaped ]. Existing paths using \] remain supported. There are no public API changes.

AI usage

OpenAI Codex was used to inspect the existing parser, help implement the quote-state change, add regression tests, and run validation. I reviewed the resulting code and test behavior and can own and debug the change.

@sdf-jkl sdf-jkl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @DKER2 LGTM

@klion26 PTAL

@sdf-jkl
sdf-jkl enabled auto-merge October 2, 2026 21:11
@sdf-jkl
sdf-jkl added this pull request to the merge queue Oct 2, 2026
Merged via the queue into apache:main with commit 705e640 Oct 2, 2026
24 checks passed
@sdf-jkl

sdf-jkl commented Oct 2, 2026

Copy link
Copy Markdown
Member

Thanks again @DKER2 🚀

@Jefffrey Jefffrey added the bug Squash those bugs label Oct 3, 2026
codewarnab pushed a commit to codewarnab/arrow-rs that referenced this pull request Oct 27, 2026
# Which issue does this PR close?

- Closes apache#9493.

# Rationale for this change

`parse_in_bracket` currently allocates a `String` for every bracket
expression, including indexes, wildcards, and quoted fields that require
no unescaping. `VariantPathElement::Field` already stores `Cow<str>`, so
unescaped field names can borrow directly from the input path.

# What changes are included in this PR?

- Defer creation of the unescaped `String` until the first backslash is
encountered.
- Borrow the original bracket-content slice when no escape processing is
required.
- Preserve ownership for escaped fields and strip their surrounding
quotes in place.
- Add tests proving unescaped bracket fields use `Cow::Borrowed` while
escaped fields use `Cow::Owned`.

This branch includes `main` with apache#11231 (closing brackets inside quoted
fields). The quote tracking added there relied on the eagerly built
buffer, so it is adapted here: an opening quote is now detected by its
offset in the bracket content rather than by the buffer being empty, and
quoted fields containing `]` (e.g. `['a]b']`) still borrow.

# Are these changes tested?

Yes. The existing path parsing tests cover behavior, and a new test
asserts the ownership of each case: empty, plain, and `]`-containing
quoted fields are borrowed, and an escaped field is owned.

The benchmark for this change is in apache#11508 (`cargo bench -p
parquet-variant --bench variant_path`), split out as requested so it is
available on `main` as a baseline. I will merge `main` here once it
lands so the numbers can be reproduced.

Earlier local measurements, taken with a temporary Criterion harness on
aarch64 macOS before apache#11231 was merged in:

| Case | Before | After | Change |
|---|---:|---:|---:|
| Three quoted bracket fields | 300.22 ns | 54.10 ns | -81.7% |
| Three bracket indexes | 146.13 ns | 45.57 ns | -68.2% |
| Escaped bracket field | 140.41 ns | 111.37 ns | -24.9% |
| Dot-path control | 38.68 ns | 40.88 ns | Within noise |

# Are there any user-facing changes?

No semantic or public API changes. Parsed paths remain the same;
unescaped bracket fields now borrow their names instead of allocating
owned strings.

# AI usage

OpenAI Codex was used to inspect the parser, help implement the lazy
allocation path, construct ownership tests, and run validation and
benchmarks. Claude Code was used to adapt the change to apache#11231 after
merging `main`. I reviewed the resulting code and behavior and can own
and debug the change.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Kosta Tarasov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Squash those bugs parquet-variant parquet-variant* crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Variant] Support unescaped closing brackets inside quoted VariantPath fields

3 participants