You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by at...@apache.org on 2026/08/07 15:56:31 UTC
(iceberg-go) branch main updated: fix(codec): reject nil data files in scan tasks (#1611)
This is an automated email from the ASF dual-hosted git repository.
laskoviymishka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new 687852e7 fix(codec): reject nil data files in scan tasks (#1611)
687852e7 is described below
commit 687852e7a831e2d5fc5862f2fa88473d4006ae60
Author: Minh Vu <vu...@gmail.com>
AuthorDate: Fri Aug 7 17:56:25 2026 +0200
fix(codec): reject nil data files in scan tasks (#1611)
* fix(codec): reject nil data files in scan tasks
Signed-off-by: Minh Vu <vu...@gmail.com>
* fix(codec): reject typed-nil data files
* chore(ci): retrigger pull request checks
---------
Signed-off-by: Minh Vu <vu...@gmail.com>
---
codec/file_scan_task.go | 18 ++++++++++++++++
codec/file_scan_task_test.go | 49 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+)
diff --git a/codec/file_scan_task.go b/codec/file_scan_task.go
index 0c681a20..43001ca5 100644
--- a/codec/file_scan_task.go
+++ b/codec/file_scan_task.go
@@ -23,6 +23,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "reflect"
"github.com/apache/iceberg-go"
"github.com/apache/iceberg-go/table"
@@ -255,6 +256,9 @@ func decodeFileScanTaskResidual(data []byte, schema *iceberg.Schema) (iceberg.Bo
// carrying a different spec would silently mis-map or drop partition values and
// still succeed. Every file in a FileScanTask must therefore share spec.ID().
func checkDataFileSpecID(f iceberg.DataFile, spec iceberg.PartitionSpec) error {
+ if isNilDataFile(f) {
+ return fmt.Errorf("%w: data file is nil", iceberg.ErrInvalidArgument)
+ }
if int(f.SpecID()) != spec.ID() {
return fmt.Errorf("data file spec id %d does not match codec spec id %d (partition evolution requires per-spec grouping)", f.SpecID(), spec.ID())
}
@@ -262,6 +266,20 @@ func checkDataFileSpecID(f iceberg.DataFile, spec iceberg.PartitionSpec) error {
return nil
}
+func isNilDataFile(f iceberg.DataFile) bool {
+ if f == nil {
+ return true
+ }
+
+ v := reflect.ValueOf(f)
+ switch v.Kind() {
+ case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Slice, reflect.UnsafePointer:
+ return v.IsNil()
+ default:
+ return false
+ }
+}
+
func encodeDataFileSlice(files []iceberg.DataFile, spec iceberg.PartitionSpec, schema *iceberg.Schema, version int) ([][]byte, error) {
if len(files) == 0 {
return nil, nil
diff --git a/codec/file_scan_task_test.go b/codec/file_scan_task_test.go
index ac7058fb..576d1762 100644
--- a/codec/file_scan_task_test.go
+++ b/codec/file_scan_task_test.go
@@ -137,6 +137,55 @@ func TestEncodeFileScanTaskRejectsMismatchedPrimaryDataFileSpec(t *testing.T) {
"error must include the codec's spec id")
}
+func TestEncodeFileScanTaskRejectsNilDataFiles(t *testing.T) {
+ spec, schema, task := fullyPopulatedFileScanTask(t, 2)
+ tests := []struct {
+ name string
+ update func(*table.FileScanTask)
+ part string
+ }{
+ {"primary file", func(task *table.FileScanTask) { task.File = nil }, "data file is nil"},
+ {"delete file", func(task *table.FileScanTask) { task.DeleteFiles = []iceberg.DataFile{nil} }, "delete files: entry 0"},
+ {"equality delete file", func(task *table.FileScanTask) { task.EqualityDeleteFiles = []iceberg.DataFile{nil} }, "equality delete files: entry 0"},
+ {"deletion vector file", func(task *table.FileScanTask) { task.DeletionVectorFiles = []iceberg.DataFile{nil} }, "deletion vector files: entry 0"},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ task := task
+ tt.update(&task)
+ _, err := codec.EncodeFileScanTask(task, spec, schema, 2)
+ require.ErrorIs(t, err, iceberg.ErrInvalidArgument)
+ require.ErrorContains(t, err, tt.part)
+ })
+ }
+}
+
+func TestEncodeFileScanTaskRejectsTypedNilDataFiles(t *testing.T) {
+ spec, schema, task := fullyPopulatedFileScanTask(t, 3)
+ var typedNil *stubDataFile
+ tests := []struct {
+ name string
+ update func(*table.FileScanTask)
+ part string
+ }{
+ {"primary file", func(task *table.FileScanTask) { task.File = typedNil }, "data file is nil"},
+ {"delete file", func(task *table.FileScanTask) { task.DeleteFiles = []iceberg.DataFile{typedNil} }, "delete files: entry 0"},
+ {"equality delete file", func(task *table.FileScanTask) { task.EqualityDeleteFiles = []iceberg.DataFile{typedNil} }, "equality delete files: entry 0"},
+ {"deletion vector file", func(task *table.FileScanTask) { task.DeletionVectorFiles = []iceberg.DataFile{typedNil} }, "deletion vector files: entry 0"},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ task := task
+ tt.update(&task)
+ _, err := codec.EncodeFileScanTask(task, spec, schema, 3)
+ require.ErrorIs(t, err, iceberg.ErrInvalidArgument)
+ require.ErrorContains(t, err, tt.part)
+ })
+ }
+}
+
func TestDecodeFileScanTaskErrorCarriesMarker(t *testing.T) {
schema := iceberg.NewSchema(123,
iceberg.NestedField{ID: 1, Name: "id", Type: iceberg.Int64Type{}, Required: true},