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

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   V2 data pages containing nulls report `num_nulls` as 0 when statistics are 
disabled or the column has no defined sort order. `INT96`, `INTERVAL`, the Null 
logical type and geospatial types have no defined sort order. They trigger this 
with default statistics settings when writing V2 pages.
   
   The specification defines `num_values - num_nulls` as the number of encoded 
values, so these headers misstate how many values each page encodes.
   
   I reproduced this on v18.8.0 and main, with Go 1.26.10 on macOS arm64. I 
checked `INT96`, `INTERVAL` and the Null type on main only.
   
   **Key calls and results**
   
   For a table with an optional `int32` column containing `[1, null, 3, null]`:
   
   ```go
   for _, stats := range []bool{true, false} {
        props := parquet.NewWriterProperties(
                parquet.WithDataPageVersion(parquet.DataPageV2),
                parquet.WithStats(stats),
        )
        var buf bytes.Buffer
        pqarrow.WriteTable(tbl, &buf, 1024, props, pqarrow.DefaultWriterProps())
   
        rdr, _ := file.NewParquetReader(bytes.NewReader(buf.Bytes()))
        pages, _ := rdr.RowGroup(0).GetColumnPageReader(0)
        for pages.Next() {
                p := pages.Page().(*file.DataPageV2)
                fmt.Printf("stats=%t num_values=%d num_nulls=%d\n", stats, 
p.NumValues(), p.NumNulls())
        }
   }
   ```
   
   Both versions print:
   
   ```text
   stats=true num_values=4 num_nulls=2
   stats=false num_values=4 num_nulls=0
   ```
   
   Expected: `num_nulls=2` in both cases.
   
   A `GEOMETRY` column containing one value and one null reports `num_values=2 
num_nulls=0` on both versions, instead of `num_nulls=1`, even with default 
statistics settings and V2 pages.
   
   **Cause**
   
   `buildDataPageV2` takes `num_nulls` from `pageStats.NullCount`:
   
   
https://github.com/apache/arrow-go/blob/7e088cdf58c2bb6388deed332295c1b83ab99f98/parquet/file/column_writer.go#L439-L446
   
   Page statistics are created only when enabled and the sort order is known. 
Otherwise, `getPageStatistics` returns zero values:
   
   
https://github.com/apache/arrow-go/blob/7e088cdf58c2bb6388deed332295c1b83ab99f98/parquet/file/column_writer.go#L184-L187
   
   
https://github.com/apache/arrow-go/blob/7e088cdf58c2bb6388deed332295c1b83ab99f98/parquet/file/column_writer.go#L691-L696
   
   The V2 header's null count is required independently of statistics:
   
   
https://github.com/apache/parquet-format/blob/ec90dd4661ff1c4d77f06b5b5232c5aedf68ffc5/src/main/thrift/parquet.thrift#L767-L771
   
   Arrow C++ tracks `num_buffered_nulls_` separately, resets it per page and 
uses it for the V2 header:
   
   
https://github.com/apache/arrow/blob/976779b2aac587f51b87c3bd2e6ae4c36f75ab6c/cpp/src/parquet/column_writer.cc#L1858-L1862
   
   
https://github.com/apache/arrow/blob/976779b2aac587f51b87c3bd2e6ae4c36f75ab6c/cpp/src/parquet/column_writer.cc#L995-L1000
   
   
https://github.com/apache/arrow/blob/976779b2aac587f51b87c3bd2e6ae4c36f75ab6c/cpp/src/parquet/column_writer.cc#L1084-L1093
   
   https://github.com/apache/arrow-go/pull/1533 notes the same problem and 
leaves it out of scope.
   
   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