hcrosse opened a new issue, #1558:
URL: https://github.com/apache/arrow-go/issues/1558

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   A `ColumnChunk`'s `encoding_stats` order follows Go map iteration, so 
writing the same table twice can give different footer bytes. This happens when 
one page type has more than one encoding. For example, a dictionary can fall 
back to `PLAIN` when it outgrows its page size limit, even with default 
settings. Both orders are valid. This affects reproducible writes, not 
correctness.
   
   I reproduced this on v18.8.0 and main, with Go 1.26.10 on macOS arm64.
   
   **Key calls and results**
   
   For a table with one `int64` column containing 20,000 values `i * 7919`, 
these settings cause dictionary fallback. I compared file hashes and the 
`encoding_stats` order of each write:
   
   ```go
   props := parquet.NewWriterProperties(
        parquet.WithDictionaryPageSizeLimit(1024),
        parquet.WithDataPageSize(4096),
        parquet.WithBatchSize(1000),
   )
   distinctBytes := map[[32]byte]int{}
   distinctOrders := map[string]int{}
   for i := 0; i < 20; i++ {
        var buf bytes.Buffer
        w, _ := pqarrow.NewFileWriter(sc, &buf, props, 
pqarrow.DefaultWriterProps())
        w.Write(rec)
        w.Close()
        data := buf.Bytes()
        distinctBytes[sha256.Sum256(data)]++
        r, _ := file.NewParquetReader(bytes.NewReader(data))
        cc, _ := r.MetaData().RowGroup(0).ColumnChunk(0)
        order := ""
        for _, s := range cc.EncodingStats() {
                order += fmt.Sprintf("%v:%v ", s.PageType, s.Encoding)
        }
        distinctOrders[order]++
   }
   ```
   
   Both versions wrote 2 different files in 20 writes. On v18.8.0 the orders 
were:
   
   ```text
      2 x DICTIONARY_PAGE:PLAIN DATA_PAGE:PLAIN DATA_PAGE:RLE_DICTIONARY
     18 x DICTIONARY_PAGE:PLAIN DATA_PAGE:RLE_DICTIONARY DATA_PAGE:PLAIN
   ```
   
   On main:
   
   ```text
     19 x DICTIONARY_PAGE:PLAIN DATA_PAGE:RLE_DICTIONARY DATA_PAGE:PLAIN
      1 x DICTIONARY_PAGE:PLAIN DATA_PAGE:PLAIN DATA_PAGE:RLE_DICTIONARY
   ```
   
   Expected: the same order on every write.
   
   **Cause**
   
   `ColumnChunkMetaDataBuilder.Finish` appends the entries while ranging over 
`DictEncodingStats` and `DataEncodingStats`:
   
   
https://github.com/apache/arrow-go/blob/fc5d5ce5a99b8583448b2cb70d0e9357dd10a420/parquet/metadata/column_chunk.go#L459-L474
   
   Arrow C++ writes dictionary entries first, then data entries, each in 
ascending encoding order:
   
   
https://github.com/apache/arrow/blob/976779b2aac587f51b87c3bd2e6ae4c36f75ab6c/cpp/src/parquet/metadata.cc#L1735-L1766
   
   I have a patch with tests and can open a PR.
   
   ### Component(s)
   
   Parquet
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to