apache / apache/parquet-java

Variant field names not being ordered correctly via UTF-8 byte order

Open
#3,735 0 comments 0 reactions 0 assignees View on GitHub
Type: bug
Dominant language
Java
Stars
3.1k
Forks
1.6k
Avg merge
3d 12h
Merged PRs (30d)
33

Description

### Describe the bug, including details regarding any error messages, version, and platform.

The Variant spec requires the field ids in an object's header to be sorted by the
**UTF-8 byte order** of the field names, so a reader can binary-search them.
`VariantBuilder` sorted the fields — and `Variant.getFieldByKey` binary-searched them —
using `String.compareTo`, which orders by **UTF-16 code units**, not UTF-8 bytes.

The two orderings are identical for all field names in the Basic Multilingual Plane, but
they diverge for names containing supplementary-plane characters (U+10000 and above):
`String.compareTo` orders a leading high surrogate (0xD800–0xDBFF) before code points in
U+E000..U+FFFF, whereas UTF-8 byte order (and the spec) orders them after. Consequences:

- An object parquet-java builds with such keys has field ids sorted in an order that
violates the spec.
- A spec-compliant reader (e.g. the Apache Arrow C++/Rust/Go Variant readers) binary-searching
that object can fail to find fields.
- Conversely, parquet-java's own binary search fails to find a supplementary-plane key in an
object produced by a spec-compliant writer.

The bug only surfaces when an object both contains a supplementary-plane key and is large
enough to take the binary-search path, so it has gone unnoticed.

### Component(s)
Core

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with VariantBuilder and Variant.getFieldByKey, then reproduce the issue using an object with a supplementary-plane field name and enough fields to trigger binary search. Verify that field ids follow UTF-8 byte order and that lookup succeeds for objects produced by both parquet-java and spec-compliant writers.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
data-engineering
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.