Align descending repeated-prefix ordering across buffer comparators

perfloop-oss/parquet-go · Uncatalogued correctness

https://perfloop.ai/t/oss/case_s0fhhq9gby

Verdict

VERIFIED · settled 2026-11-20 · merged as parquet-go/parquet-go#703

What happened: The check fails before this change and passes with it.

Hypothesis

Two public comparison APIs disagree about descending repeated keys when one key is an exact prefix of the other. The same sorting columns therefore describe opposite row orders depending on which comparator is used. The intended prefix rule and compatibility consequences still need to be established; this finding does not presume that the buffer rather than the schema comparator must change.

repeatedColumnBuffer.Less returns row1Length < row2Length after an equal prefix at column_buffer_repeated.go:196-209. reversedColumnBuffer.Less swaps the complete comparison at column_buffer.go:134, putting the longer key first in descending order. Schema.Comparator instead reverses element comparison at compare.go:433-434 but resolves an exhausted prefix with unconditional shorter-first order at lines 489-502. Schema.Comparator promises to order rows according to the sorting columns at schema.go:463-466. RowBuffer is documented as a row-layout alternative for the same in-memory sorting use case at row_buffer.go:12-20 and uses Schema.Comparator at lines 49-52. These APIs do not document different prefix rules in the inspected source.

The provisional checker in hunt_repeated_prefix_consistency_test.go targets all 30 nonempty prefixes of lengths 1..2 over {0, min-int64, -1, 1, max-int64}, each extended by each of five values, both row orders, and four direction/null modes: 1,200 cases if completed. `go test -run '^TestHuntRepeatedPrefixConsistencySearch$' -count=1 -v .` stopped at case 3: input=[[0] [0 0]], desc=true, nullsFirst=false, Buffer.Less(0,1)=false while Schema.Comparator requires true, with the opposite disagreement in reverse. The failing search did not complete its domain.

The deterministic minimal replay is `go test -run '^TestHuntRepeatedPrefixConsistencyReplay$' -count=1 -v .`. It writes exactly [0] and [0,0] under Descending plus NullsFirst and compares both public APIs on the same schema and rows. It failed with `Buffer.Less01=false Schema.Less01=true Buffer.Less10=true Schema.Less10=false`. Both cited commands exited 1 on the consistency assertion after successful writes. There is no differing suffix, NaN, null value, or page read, so the previously admitted repairs do not resolve this disagreement. The independent Case proof target is a coherent public prefix-order rule and agreement between these comparison routes. The finite checker layout is provisional, not a requirement to retain this exact harness; CONTRIBUTING.md:50 requires bug-fix tests.

Concrete prior searches for descending prefix and compareRowsFuncOfColumnValues returned no match. The upstream open-PR index https://github.com/parquet-go/parquet-go/pulls, observed 2026-11-17, showed no matching comparator change. The checkout is shallow and bounded upstream file-history reads were refused, leaving recent merged-history coverage unknown. No replacement decision excluding GenericBuffer correctness work is documented by the RowBuffer recommendation.

Change to test: Establish one rule for descending repeated keys when one key is an exact prefix of the other, and make buffer comparisons and Schema.Comparator agree. Add native consistency regressions while preserving ordinary element comparison, ascending order, null placement, and later-key tie breaks.

Where it lives

perfloop-oss/parquet-go · buffer.go

Evidence

The check fails before this change and passes with it: `Buffer, GenericBuffer, RowBuffer and Schema.Comparator agree in both comparison directions on repeated int64 keys [0] and [0,0]: shorter prefixes sort first ascending and last descending with either null policy, and unconfigured sorting leaves both rows unordered.`

The check fails before this change and passes with it: `MergeRowGroups merges descending repeated int64 keys [0] and [0,0] from one sorted group with [0,0,0] from another into [0,0,0], [0,0], [0].`

Checks: 5 of 5 passed. Verification: no defect found.

Timeline