WriteRowGroup silently drops source row group SortingColumns metadata
perfloop-oss/parquet-go · Round-trip loss
https://perfloop.ai/t/oss/case_cms9kn8pxh
Verdict
VERIFIED · settled 2026-11-24 · merged as parquet-go/parquet-go#754
What happened: The check fails before this change and passes with it.
Hypothesis
Writing a sorted RowGroup via Writer.WriteRowGroup or GenericWriter.WriteRowGroup to a writer without explicit writer-level SortingColumns silently drops every sorting column from the emitted Parquet RowGroup metadata. Downstream readers and mergers therefore see an unsorted row group and lose sort-order metadata.
In writer.go, writer.writeRowGroup (lines 1804-1821) initializes sortingColumns when len(w.sortingColumns) == 0 && len(rowGroupSortingColumns) > 0 with make([]format.SortingColumn, 0, scLen) (length 0, capacity scLen), or reuses reuseRowGroup.SortingColumns (which RowGroup.Reset cleared to length 0). Line 1813 then checks if sortingIndex := searchSortingColumn(rowGroupSortingColumns, leaf.path); sortingIndex < len(sortingColumns). Because len(sortingColumns) is 0 and sortingIndex is non-negative, the condition is always false and no SortingColumn entry is ever written.
A bounded 10-case search (TestHuntWriteRowGroupSortingColumnsSearch in writer_sorting_columns_hunt_test.go) checked 5 sorting specifications (ascending, descending, nulls-first, 2-column, and 3-column) with and without Reset reuse. All 10 cases failed with got 0 sorting columns []. The deterministic replay TestHuntWriteRowGroupSortingColumnsReplay reproduces the drop on a single Ascending("a") sorted Buffer.
Upstream check: open PRs touching writer.go (#679, #554, #510) were inspected on 2026-11-24 and do not touch sortingColumns in writer.writeRowGroup.
Case proof target: confirm that Writer.WriteRowGroup preserves source SortingColumns (column index, descending, and nulls-first flags) on first writes and after Reset, including when the source row group is split or copied, without overwriting writer-configured SortingColumns. The test layout is provisional.
Change to test: Allocate or resize sortingColumns to length len(rowGroupSortingColumns) before populating entries in writer.writeRowGroup, preserving the source row group's sorting-column metadata across both initial writes and Reset reuse.
Where it lives
perfloop-oss/parquet-go · writer.go
Evidence
The check fails before this change and passes with it: `Writer.WriteRowGroup and GenericWriter.WriteRowGroup preserve source sorting column indexes, order, descending and nulls-first flags for the tested buffer, row-buffer, file and merged row groups, including splits and Reset reuse; writer-configured sorting columns take precedence.`
Checks: 2 of 2 passed. Verification: no defect found.