Skip to content

fix(parquet/variant): correct binary search bounds in ObjectValue.ValueByKey - #841

Merged
zeroshade merged 1 commit into
apache:mainfrom
qzyu999:fix/variant-object-binary-search
Jun 8, 2026
Merged

zeroshade merged 1 commit into
apache:mainfrom
qzyu999:fix/variant-object-binary-search

Conversation

@qzyu999

@qzyu999 qzyu999 commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Closes #842

The ObjectValue.ValueByKey function implements a custom binary search on the v.value array of field IDs to look up fields by key. It initializes its boundaries using an exclusive upper bound (i, j := 0, n).
However, when the target key is smaller than the key at the mid index, it updates the upper bound with:
j = mid - 1

Since j is exclusive, setting it to mid - 1 excludes the index mid - 1 from the search space entirely. If the target key is located at mid - 1, the lookup will fail and return arrow.ErrNotFound. This results in missing fields or lookups failing on objects containing >= 32 fields.

What changes are included in this PR?

  • Correct the exclusive upper bound update in ObjectValue.ValueByKey from j = mid - 1 to j = mid.

Are these changes tested?

  • Added TestObjectBinarySearch in parquet/variant/variant_test.go which constructs a 32-field object and verifies that all 32 lookups using ValueByKey succeed.

Are there any user-facing changes?

  • No API changes. This is a correctness bug fix.

Copilot AI 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.

Pull request overview

Fixes a correctness bug in parquet/variant where ObjectValue.ValueByKey’s binary search used an exclusive upper bound but updated it as if it were inclusive, causing certain keys (notably at mid-1) to be skipped for objects with 32+ fields.

Changes:

  • Correct binary search upper-bound update in ObjectValue.ValueByKey from j = mid - 1 to j = mid for a [i, j) search interval.
  • Add a regression test that builds a 32-field object and verifies all keys are retrievable via ValueByKey.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
parquet/variant/variant.go Fixes binary search bounds update to match exclusive-upper-bound interval semantics.
parquet/variant/variant_test.go Adds a regression test that exercises the binary-search path (32 elements) and validates lookups for all keys.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@qzyu999
qzyu999 force-pushed the fix/variant-object-binary-search branch from 1f91ec8 to 9a16c3b Compare June 7, 2026 18:27
@qzyu999

qzyu999 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

Hi @zeroshade, removed an empty line that was breaking the linter in 9a16c3b.

@zeroshade
zeroshade merged commit 6a332c9 into apache:main Jun 8, 2026
40 of 41 checks passed
@qzyu999
qzyu999 deleted the fix/variant-object-binary-search branch June 8, 2026 17:30
laskoviymishka pushed a commit to apache/iceberg-go that referenced this pull request Jun 10, 2026
## Changes

Bumps arrow-go to
[88561cf](apache/arrow-go@88561cf)
to pick up apache/arrow-go#840 and
[#841](apache/arrow-go#841) (variant fixes;
neither reachable via iceberg-go's public API).
  
The bump window includes unrelated Parquet encoder changes (arrow-go
#779/#786/#807) that produce different output bytes; tests asserting
exact file/column sizes are updated accordingly.
  
Adds defensive coverage at the variant boundary in literals_test.go and
table/arrow_utils_test.go.
  
Will follow up to swap the pseudo-version for a tagged release when
arrow-go cuts one. Refs #929
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.

[Go][Parquet] ObjectValue.ValueByKey binary search skips elements at mid - 1

3 participants