riverandeye opened a new pull request, #2782: URL: https://github.com/apache/iceberg-go/pull/2782
Fixes #2781 `Transaction.Append` and `AppendTable` accepted nulls in required fields and wrote them as zero values. The commit succeeded, the manifest reported no nulls for the column, and a scan returned `0` or `""`. A non-null struct whose required child was null was read back as a null struct, and a null element in a `list<int required>` column made the column unreadable after a scan. ### Cause [`WriteRecords`](https://github.com/apache/iceberg-go/blob/3637784d/table/write_records.go#L208) checks the Arrow schema against the table schema, but `Append` passes the reader straight to [`recordsToDataFiles`](https://github.com/apache/iceberg-go/blob/3637784d/table/transaction.go#L1033-L1038). Nothing on the write path looks at the data. Even `WriteRecords` lets through a batch whose Arrow field is non-nullable but holds nulls. The Parquet writer then writes the column as required and drops the validity bitmap. ### Fix - `checkRequiredNulls` walks the projected batch with the file schema. It returns `ErrInvalidArgument` and names the field when a required field holds a null and all of its parents are non-null. Nulls under a null optional struct, list or map are allowed. - `RollingDataWriter` runs the check right after `toRequestedSchema`. `Append`, `AppendTable`, `Overwrite`, dynamic partition overwrite, copy-on-write rewrites and `WriteRecords` all go through it. - Nullable Arrow fields that hold no nulls are still accepted, as before. - `TestPartitionedLogicalTypesRequireIntFieldIDCase` wrote nulls into required columns. Those columns are now optional, since the test is about partition values for logical types. ### Tests - `TestAppendRejectsNullsInRequiredFields` appends a null in a top-level column, in a non-nullable Arrow field, in a required field of a non-null struct and in a required list element. It runs each case on an unpartitioned and a partitioned table. - `TestAppendTableRejectsNullsInRequiredFields` checks the same error through `AppendTable`. - `TestAppendAllowsNullsUnderNullOptionalParents` appends a null struct with a required child and a null list with required elements, and checks that both read back as null. - `TestWriteRecordsRejectsNullsInNonNullableArrowFields` checks that `WriteRecords` rejects nulls in a non-nullable Arrow field that passes the schema check. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
