Encode fixed-length byte-array decimals in decimalValue instead of dropping writes

perfloop-oss/parquet-go · Round-trip loss

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

Verdict

VERIFIED · settled 2026-11-24 · merged as parquet-go/parquet-go#749

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

Hypothesis

Writing a Go float32 or float64 value into a Parquet DECIMAL column backed by FIXED_LEN_BYTE_ARRAY silently drops the value without returning an error. When every row has a non-null float on a required column, the written Parquet file ends up with zero row groups and zero rows; when an optional column mixes floats and nulls, only the nulls are written, leaving column value counts mismatched and causing readback to fail with missing column values. How often production workloads write dynamic floats into fixed-length decimal columns remains unmeasured.

In column_buffer_reflect.go:1075-1085, decimalValue switches on typ.Kind() and handles only Int32, Int64, and ByteArray, omitting FixedLenByteArray and having no default branch. It is called by writeValueFuncOfLeaf (column_buffer_reflect.go:930, 939) whenever GenericWriter[any] writes a float32 or float64 from map[string]any, interface fields, or *structpb.Struct into a Decimal-annotated leaf column. By contrast, writeBigFloat (column_buffer_reflect.go:1120-1124) and decimalType.AssignValue (type_decimal.go:454-493) already encode and decode FixedLenByteArray decimals using sign-extended big-endian two's-complement bytes padded to typ.Length().

A bounded search (TestHuntDecimalFloatWriteSearch) across all 4 Parquet DECIMAL physical types (Int32, Int64, ByteArray, and FixedLenByteArray widths 4, 8, 16), scales 0 and 2, required and optional schemas, and float64, float32, and *structpb.Struct inputs (42 cases total) passed all 18/18 Int32, Int64, and ByteArray cases and failed all 24/24 FixedLenByteArray cases. The reduced deterministic replay (TestHuntDecimalFloatWriteReplay) confirms that required FixedLenByteArrayType(8) produces 0 row groups (numRows=0) for 2 written rows and optional FixedLenByteArrayType(8) leaves only 1 value for 2 rows and fails readback with "id → no values found in parquet row for column 1", while the ByteArray control passes. An experimental 3-line edit adding case FixedLenByteArray using padToFixedLen(bigIntToByteArray(big.NewInt(val)), typ.Length(), val < 0) passed all 42/42 search cases.

Upstream check on github.com/parquet-go/parquet-go found no open PRs touching column_buffer_reflect.go. Note that for large float values whose scaled magnitude exceeds int64 (e.g., high precision/scale on 16-byte fixed decimals), converting via big.Float/big.Int instead of int64 may also be evaluated during the Case repair. The Case proof target is to verify that float32, float64, and structpb numeric writes to FixedLenByteArray DECIMAL columns (including widths 4, 8, and 16, positive, negative, zero, and optional nulls) emit one value per row and round-trip accurately; the provisional test file layout is not a frozen requirement.

Change to test: Handle FixedLenByteArray in decimalValue by encoding the scaled integer as sign-extended big-endian two's-complement bytes padded to typ.Length() (reusing bigIntToByteArray and padToFixedLen as writeBigFloat already does) and writing them via col.writeByteArray, and fail explicitly on any unsupported physical kind instead of silently dropping the write.

Where it lives

perfloop-oss/parquet-go · column_buffer_write.go

Evidence

The check fails before this change and passes with it: `GenericWriter[any] preserves row and column value counts and rounded decimal readback for finite float32, float64, interface-field and structpb numeric inputs in the regression corpus at FIXED_LEN_BYTE_ARRAY widths 4, 8 and 16, scales 0 and 2, and required and optional columns, including explicit zero, nulls and signed 16-byte magnitudes beyond int64.`

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

Timeline