slachiewicz commented on code in PR #2487: URL: https://github.com/apache/iceberg-go/pull/2487#discussion_r4729001642
########## table/identity_partition_projection_internal_test.go: ########## @@ -0,0 +1,413 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package table + +import ( + "context" + "fmt" + "iter" + "os" + "path/filepath" + "sort" + "testing" + + "github.com/apache/arrow-go/v18/arrow" + "github.com/apache/arrow-go/v18/arrow/array" + "github.com/apache/arrow-go/v18/arrow/decimal128" + "github.com/apache/arrow-go/v18/arrow/memory" + "github.com/apache/arrow-go/v18/parquet/pqarrow" + "github.com/apache/iceberg-go" + iceio "github.com/apache/iceberg-go/io" + "github.com/stretchr/testify/require" +) + +// A writer may leave an identity partition column out of its data files, as +// Delta and Hive-style layouts do. The spec's column projection reads such a +// field from the file's partition value (rule 1), required or not. +func TestScanFillsIdentityPartitionColumnMissingFromDataFile(t *testing.T) { + ctx := context.Background() + location := filepath.ToSlash(t.TempDir()) + schema := iceberg.NewSchema(0, + iceberg.NestedField{ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int64, Required: true}, + iceberg.NestedField{ID: 2, Name: "region", Type: iceberg.PrimitiveTypes.String, Required: true}, + ) + spec := iceberg.NewPartitionSpec(iceberg.PartitionField{ + SourceIDs: []int{2}, FieldID: 1000, Name: "region", Transform: iceberg.IdentityTransform{}, + }) + meta, err := NewMetadata(schema, &spec, UnsortedSortOrder, location, nil) + require.NoError(t, err) + tbl := New(Identifier{"db", "identity"}, meta, location+"/metadata/v1.metadata.json", + func(context.Context) (iceio.IO, error) { return iceio.LocalFS{}, nil }, &countingCatalog{metadata: meta}) + + // Each file stores only id; its region lives in the manifest. + idOnly := arrow.NewSchema([]arrow.Field{{ + Name: "id", Type: arrow.PrimitiveTypes.Int64, + Metadata: arrow.NewMetadata([]string{ArrowParquetFieldIDKey}, []string{"1"}), + }}, nil) + files := make([]iceberg.DataFile, 0, 2) + for _, part := range []struct { + region string + ids string + }{{"east", `[{"id":1},{"id":2}]`}, {"west", `[{"id":3}]`}} { + data, err := array.TableFromJSON(memory.DefaultAllocator, idOnly, []string{part.ids}) + require.NoError(t, err) + path := location + "/data/" + part.region + ".parquet" + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + f, err := os.Create(path) + require.NoError(t, err) + require.NoError(t, pqarrow.WriteTable(data, f, 1024, nil, pqarrow.DefaultWriterProps())) + info, err := os.Stat(path) + require.NoError(t, err) + + b, err := iceberg.NewDataFileBuilder(spec, iceberg.EntryContentData, path, iceberg.ParquetFile, + map[int]any{1000: part.region}, nil, nil, data.NumRows(), info.Size()) + require.NoError(t, err) + files = append(files, b.Build()) + data.Release() + } + txn := tbl.NewTransaction() + require.NoError(t, txn.AddDataFiles(ctx, files, nil)) + tbl, err = txn.Commit(ctx) + require.NoError(t, err) + + result, err := tbl.Scan().ToArrowTable(ctx) + require.NoError(t, err) + defer result.Release() + + got := map[int64]string{} + reader := array.NewTableReader(result, -1) + defer reader.Release() + for reader.Next() { + rec := reader.RecordBatch() + ids := rec.Column(0).(*array.Int64) + regions := rec.Column(1).(*array.String) + for i := range int(rec.NumRows()) { + got[ids.Value(i)] = regions.Value(i) + } + } + require.Equal(t, map[int64]string{1: "east", 2: "east", 3: "west"}, got) + + // A filter on the partition column prunes by it and still fills it. + filtered, err := tbl.Scan(WithRowFilter(iceberg.EqualTo(iceberg.Reference("region"), "west"))).ToArrowTable(ctx) + require.NoError(t, err) + defer filtered.Release() + require.EqualValues(t, 1, filtered.NumRows()) +} + +// Partition values come back from the manifest as literals; a decimal one +// must still fill the column rather than fail the scan. +func TestScanFillsDecimalIdentityPartitionColumnMissingFromDataFile(t *testing.T) { + ctx := context.Background() + location := filepath.ToSlash(t.TempDir()) + schema := iceberg.NewSchema(0, + iceberg.NestedField{ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int64, Required: true}, + iceberg.NestedField{ID: 2, Name: "amount", Type: iceberg.MustDecimalTypeOf(9, 2)}, + ) + spec := iceberg.NewPartitionSpec(iceberg.PartitionField{ + SourceIDs: []int{2}, FieldID: 1000, Name: "amount", Transform: iceberg.IdentityTransform{}, + }) + meta, err := NewMetadata(schema, &spec, UnsortedSortOrder, location, nil) + require.NoError(t, err) + tbl := New(Identifier{"db", "identity_decimal"}, meta, location+"/metadata/v1.metadata.json", + func(context.Context) (iceio.IO, error) { return iceio.LocalFS{}, nil }, &countingCatalog{metadata: meta}) + + idOnly := arrow.NewSchema([]arrow.Field{{ + Name: "id", Type: arrow.PrimitiveTypes.Int64, + Metadata: arrow.NewMetadata([]string{ArrowParquetFieldIDKey}, []string{"1"}), + }}, nil) + data, err := array.TableFromJSON(memory.DefaultAllocator, idOnly, []string{`[{"id":1},{"id":2}]`}) + require.NoError(t, err) + defer data.Release() + path := location + "/data/amount.parquet" + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + f, err := os.Create(path) + require.NoError(t, err) + require.NoError(t, pqarrow.WriteTable(data, f, 1024, nil, pqarrow.DefaultWriterProps())) + info, err := os.Stat(path) + require.NoError(t, err) + + value := iceberg.Decimal{Val: decimal128.FromI64(1234), Scale: 2} + b, err := iceberg.NewDataFileBuilder(spec, iceberg.EntryContentData, path, iceberg.ParquetFile, + map[int]any{1000: value}, nil, nil, data.NumRows(), info.Size()) + require.NoError(t, err) + txn := tbl.NewTransaction() + require.NoError(t, txn.AddDataFiles(ctx, []iceberg.DataFile{b.Build()}, nil)) + tbl, err = txn.Commit(ctx) + require.NoError(t, err) + + result, err := tbl.Scan().ToArrowTable(ctx) + require.NoError(t, err) + defer result.Release() + require.EqualValues(t, 2, result.NumRows()) + for _, chunk := range result.Column(1).Data().Chunks() { + amounts := chunk.(*array.Decimal128) + for i := range amounts.Len() { + require.False(t, amounts.IsNull(i)) + require.Equal(t, "12.34", amounts.ValueStr(i)) + } + } +} + +// identityPartitionTestTable returns an empty table at a fresh location. +func identityPartitionTestTable(t *testing.T, schema *iceberg.Schema, spec iceberg.PartitionSpec, props iceberg.Properties) *Table { + t.Helper() + + location := filepath.ToSlash(t.TempDir()) + meta, err := NewMetadata(schema, &spec, UnsortedSortOrder, location, props) + require.NoError(t, err) + + return New(Identifier{"db", "identity"}, meta, location+"/metadata/v1.metadata.json", + func(context.Context) (iceio.IO, error) { return iceio.LocalFS{}, nil }, &countingCatalog{metadata: meta}) +} + +// addIDOnlyFile commits a data file that stores only the id column (field ID +// 1), with partition as its partition data under the table's current spec. +func addIDOnlyFile(t *testing.T, tbl *Table, name string, partition map[int]any, ids string) *Table { + t.Helper() + + idOnly := arrow.NewSchema([]arrow.Field{{ + Name: "id", Type: arrow.PrimitiveTypes.Int64, + Metadata: arrow.NewMetadata([]string{ArrowParquetFieldIDKey}, []string{"1"}), + }}, nil) + data, err := array.TableFromJSON(memory.DefaultAllocator, idOnly, []string{ids}) + require.NoError(t, err) + defer data.Release() + + path := tbl.Location() + "/data/" + name + ".parquet" + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + f, err := os.Create(path) + require.NoError(t, err) + require.NoError(t, pqarrow.WriteTable(data, f, 1024, nil, pqarrow.DefaultWriterProps())) + info, err := os.Stat(path) + require.NoError(t, err) + + b, err := iceberg.NewDataFileBuilder(tbl.Spec(), iceberg.EntryContentData, path, iceberg.ParquetFile, + partition, nil, nil, data.NumRows(), info.Size()) + require.NoError(t, err) + if tbl.Metadata().FormatVersion() >= 3 { + b.FirstRowID(tbl.Metadata().NextRowID()) + } + txn := tbl.NewTransaction() + require.NoError(t, txn.AddDataFiles(t.Context(), []iceberg.DataFile{b.Build()}, nil)) + tbl, err = txn.Commit(t.Context()) + require.NoError(t, err) + + return tbl +} + +// scanIDAndColumn returns each row of a two-column (id, value) scan as +// "id:value", sorted, with "id:<null>" for a null value. +func scanIDAndColumn(t *testing.T, tbl *Table, opts ...ScanOption) []string { + t.Helper() + + result, err := tbl.Scan(opts...).ToArrowTable(t.Context()) + require.NoError(t, err) + defer result.Release() + + rows := []string{} + reader := array.NewTableReader(result, -1) + defer reader.Release() + for reader.Next() { + rec := reader.RecordBatch() + ids := rec.Column(0).(*array.Int64) + for i := range int(rec.NumRows()) { + value := "<null>" + if !rec.Column(1).IsNull(i) { + value = rec.Column(1).ValueStr(i) + } + rows = append(rows, fmt.Sprintf("%d:%s", ids.Value(i), value)) + } + } + sort.Strings(rows) + + return rows +} + +// regionTestTable has id 1 in both partitions, in files that store only id. +func regionTestTable(t *testing.T, props iceberg.Properties) *Table { + t.Helper() + + schema := iceberg.NewSchema(0, + iceberg.NestedField{ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int64, Required: true}, + iceberg.NestedField{ID: 2, Name: "region", Type: iceberg.PrimitiveTypes.String, Required: true}, + ) + spec := iceberg.NewPartitionSpec(iceberg.PartitionField{ + SourceIDs: []int{2}, FieldID: 1000, Name: "region", Transform: iceberg.IdentityTransform{}, + }) + tbl := identityPartitionTestTable(t, schema, spec, props) + tbl = addIDOnlyFile(t, tbl, "east", map[int]any{1000: "east"}, `[{"id":1},{"id":2}]`) + + return addIDOnlyFile(t, tbl, "west", map[int]any{1000: "west"}, `[{"id":1},{"id":3}]`) +} + +// A row filter must see the partition value of a column the file does not +// store, not a null. A scan takes each file's residual from planning, which +// substitutes the partition value already; this pins that it stays so. +func TestFilterOnIdentityPartitionColumnMissingFromDataFile(t *testing.T) { Review Comment: Added in 0a9ff1c as `TestFoldIdentityPartitionConstants`, which calls the folder directly with OR, NOT, IN, NOT IN, IsNull and NotNull on the missing column. ########## table/identity_partition_projection_internal_test.go: ########## @@ -0,0 +1,413 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package table + +import ( + "context" + "fmt" + "iter" + "os" + "path/filepath" + "sort" + "testing" + + "github.com/apache/arrow-go/v18/arrow" + "github.com/apache/arrow-go/v18/arrow/array" + "github.com/apache/arrow-go/v18/arrow/decimal128" + "github.com/apache/arrow-go/v18/arrow/memory" + "github.com/apache/arrow-go/v18/parquet/pqarrow" + "github.com/apache/iceberg-go" + iceio "github.com/apache/iceberg-go/io" + "github.com/stretchr/testify/require" +) + +// A writer may leave an identity partition column out of its data files, as +// Delta and Hive-style layouts do. The spec's column projection reads such a +// field from the file's partition value (rule 1), required or not. +func TestScanFillsIdentityPartitionColumnMissingFromDataFile(t *testing.T) { + ctx := context.Background() + location := filepath.ToSlash(t.TempDir()) + schema := iceberg.NewSchema(0, + iceberg.NestedField{ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int64, Required: true}, + iceberg.NestedField{ID: 2, Name: "region", Type: iceberg.PrimitiveTypes.String, Required: true}, + ) + spec := iceberg.NewPartitionSpec(iceberg.PartitionField{ + SourceIDs: []int{2}, FieldID: 1000, Name: "region", Transform: iceberg.IdentityTransform{}, + }) + meta, err := NewMetadata(schema, &spec, UnsortedSortOrder, location, nil) + require.NoError(t, err) + tbl := New(Identifier{"db", "identity"}, meta, location+"/metadata/v1.metadata.json", + func(context.Context) (iceio.IO, error) { return iceio.LocalFS{}, nil }, &countingCatalog{metadata: meta}) + + // Each file stores only id; its region lives in the manifest. + idOnly := arrow.NewSchema([]arrow.Field{{ + Name: "id", Type: arrow.PrimitiveTypes.Int64, + Metadata: arrow.NewMetadata([]string{ArrowParquetFieldIDKey}, []string{"1"}), + }}, nil) + files := make([]iceberg.DataFile, 0, 2) + for _, part := range []struct { + region string + ids string + }{{"east", `[{"id":1},{"id":2}]`}, {"west", `[{"id":3}]`}} { + data, err := array.TableFromJSON(memory.DefaultAllocator, idOnly, []string{part.ids}) + require.NoError(t, err) + path := location + "/data/" + part.region + ".parquet" + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + f, err := os.Create(path) + require.NoError(t, err) + require.NoError(t, pqarrow.WriteTable(data, f, 1024, nil, pqarrow.DefaultWriterProps())) + info, err := os.Stat(path) + require.NoError(t, err) + + b, err := iceberg.NewDataFileBuilder(spec, iceberg.EntryContentData, path, iceberg.ParquetFile, + map[int]any{1000: part.region}, nil, nil, data.NumRows(), info.Size()) + require.NoError(t, err) + files = append(files, b.Build()) + data.Release() + } + txn := tbl.NewTransaction() + require.NoError(t, txn.AddDataFiles(ctx, files, nil)) + tbl, err = txn.Commit(ctx) + require.NoError(t, err) + + result, err := tbl.Scan().ToArrowTable(ctx) + require.NoError(t, err) + defer result.Release() + + got := map[int64]string{} + reader := array.NewTableReader(result, -1) + defer reader.Release() + for reader.Next() { + rec := reader.RecordBatch() + ids := rec.Column(0).(*array.Int64) + regions := rec.Column(1).(*array.String) + for i := range int(rec.NumRows()) { + got[ids.Value(i)] = regions.Value(i) + } + } + require.Equal(t, map[int64]string{1: "east", 2: "east", 3: "west"}, got) + + // A filter on the partition column prunes by it and still fills it. + filtered, err := tbl.Scan(WithRowFilter(iceberg.EqualTo(iceberg.Reference("region"), "west"))).ToArrowTable(ctx) + require.NoError(t, err) + defer filtered.Release() + require.EqualValues(t, 1, filtered.NumRows()) +} + +// Partition values come back from the manifest as literals; a decimal one +// must still fill the column rather than fail the scan. +func TestScanFillsDecimalIdentityPartitionColumnMissingFromDataFile(t *testing.T) { + ctx := context.Background() + location := filepath.ToSlash(t.TempDir()) + schema := iceberg.NewSchema(0, + iceberg.NestedField{ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int64, Required: true}, + iceberg.NestedField{ID: 2, Name: "amount", Type: iceberg.MustDecimalTypeOf(9, 2)}, + ) + spec := iceberg.NewPartitionSpec(iceberg.PartitionField{ + SourceIDs: []int{2}, FieldID: 1000, Name: "amount", Transform: iceberg.IdentityTransform{}, + }) + meta, err := NewMetadata(schema, &spec, UnsortedSortOrder, location, nil) + require.NoError(t, err) + tbl := New(Identifier{"db", "identity_decimal"}, meta, location+"/metadata/v1.metadata.json", + func(context.Context) (iceio.IO, error) { return iceio.LocalFS{}, nil }, &countingCatalog{metadata: meta}) + + idOnly := arrow.NewSchema([]arrow.Field{{ + Name: "id", Type: arrow.PrimitiveTypes.Int64, + Metadata: arrow.NewMetadata([]string{ArrowParquetFieldIDKey}, []string{"1"}), + }}, nil) + data, err := array.TableFromJSON(memory.DefaultAllocator, idOnly, []string{`[{"id":1},{"id":2}]`}) + require.NoError(t, err) + defer data.Release() + path := location + "/data/amount.parquet" + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + f, err := os.Create(path) + require.NoError(t, err) + require.NoError(t, pqarrow.WriteTable(data, f, 1024, nil, pqarrow.DefaultWriterProps())) + info, err := os.Stat(path) + require.NoError(t, err) + + value := iceberg.Decimal{Val: decimal128.FromI64(1234), Scale: 2} + b, err := iceberg.NewDataFileBuilder(spec, iceberg.EntryContentData, path, iceberg.ParquetFile, + map[int]any{1000: value}, nil, nil, data.NumRows(), info.Size()) + require.NoError(t, err) + txn := tbl.NewTransaction() + require.NoError(t, txn.AddDataFiles(ctx, []iceberg.DataFile{b.Build()}, nil)) + tbl, err = txn.Commit(ctx) + require.NoError(t, err) + + result, err := tbl.Scan().ToArrowTable(ctx) + require.NoError(t, err) + defer result.Release() + require.EqualValues(t, 2, result.NumRows()) + for _, chunk := range result.Column(1).Data().Chunks() { + amounts := chunk.(*array.Decimal128) + for i := range amounts.Len() { + require.False(t, amounts.IsNull(i)) + require.Equal(t, "12.34", amounts.ValueStr(i)) + } + } +} + +// identityPartitionTestTable returns an empty table at a fresh location. +func identityPartitionTestTable(t *testing.T, schema *iceberg.Schema, spec iceberg.PartitionSpec, props iceberg.Properties) *Table { + t.Helper() + + location := filepath.ToSlash(t.TempDir()) + meta, err := NewMetadata(schema, &spec, UnsortedSortOrder, location, props) + require.NoError(t, err) + + return New(Identifier{"db", "identity"}, meta, location+"/metadata/v1.metadata.json", + func(context.Context) (iceio.IO, error) { return iceio.LocalFS{}, nil }, &countingCatalog{metadata: meta}) +} + +// addIDOnlyFile commits a data file that stores only the id column (field ID +// 1), with partition as its partition data under the table's current spec. +func addIDOnlyFile(t *testing.T, tbl *Table, name string, partition map[int]any, ids string) *Table { + t.Helper() + + idOnly := arrow.NewSchema([]arrow.Field{{ + Name: "id", Type: arrow.PrimitiveTypes.Int64, + Metadata: arrow.NewMetadata([]string{ArrowParquetFieldIDKey}, []string{"1"}), + }}, nil) + data, err := array.TableFromJSON(memory.DefaultAllocator, idOnly, []string{ids}) + require.NoError(t, err) + defer data.Release() + + path := tbl.Location() + "/data/" + name + ".parquet" + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + f, err := os.Create(path) + require.NoError(t, err) + require.NoError(t, pqarrow.WriteTable(data, f, 1024, nil, pqarrow.DefaultWriterProps())) + info, err := os.Stat(path) + require.NoError(t, err) + + b, err := iceberg.NewDataFileBuilder(tbl.Spec(), iceberg.EntryContentData, path, iceberg.ParquetFile, + partition, nil, nil, data.NumRows(), info.Size()) + require.NoError(t, err) + if tbl.Metadata().FormatVersion() >= 3 { + b.FirstRowID(tbl.Metadata().NextRowID()) + } + txn := tbl.NewTransaction() + require.NoError(t, txn.AddDataFiles(t.Context(), []iceberg.DataFile{b.Build()}, nil)) + tbl, err = txn.Commit(t.Context()) + require.NoError(t, err) + + return tbl +} + +// scanIDAndColumn returns each row of a two-column (id, value) scan as +// "id:value", sorted, with "id:<null>" for a null value. +func scanIDAndColumn(t *testing.T, tbl *Table, opts ...ScanOption) []string { + t.Helper() + + result, err := tbl.Scan(opts...).ToArrowTable(t.Context()) + require.NoError(t, err) + defer result.Release() + + rows := []string{} + reader := array.NewTableReader(result, -1) + defer reader.Release() + for reader.Next() { + rec := reader.RecordBatch() + ids := rec.Column(0).(*array.Int64) + for i := range int(rec.NumRows()) { + value := "<null>" + if !rec.Column(1).IsNull(i) { + value = rec.Column(1).ValueStr(i) + } + rows = append(rows, fmt.Sprintf("%d:%s", ids.Value(i), value)) + } + } + sort.Strings(rows) + + return rows +} + +// regionTestTable has id 1 in both partitions, in files that store only id. +func regionTestTable(t *testing.T, props iceberg.Properties) *Table { + t.Helper() + + schema := iceberg.NewSchema(0, + iceberg.NestedField{ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int64, Required: true}, + iceberg.NestedField{ID: 2, Name: "region", Type: iceberg.PrimitiveTypes.String, Required: true}, + ) + spec := iceberg.NewPartitionSpec(iceberg.PartitionField{ + SourceIDs: []int{2}, FieldID: 1000, Name: "region", Transform: iceberg.IdentityTransform{}, + }) + tbl := identityPartitionTestTable(t, schema, spec, props) + tbl = addIDOnlyFile(t, tbl, "east", map[int]any{1000: "east"}, `[{"id":1},{"id":2}]`) + + return addIDOnlyFile(t, tbl, "west", map[int]any{1000: "west"}, `[{"id":1},{"id":3}]`) +} + +// A row filter must see the partition value of a column the file does not +// store, not a null. A scan takes each file's residual from planning, which +// substitutes the partition value already; this pins that it stays so. +func TestFilterOnIdentityPartitionColumnMissingFromDataFile(t *testing.T) { + tbl := regionTestTable(t, nil) + region, id := iceberg.Reference("region"), iceberg.Reference("id") + westOne := iceberg.NewAnd(iceberg.EqualTo(region, "west"), iceberg.EqualTo(id, int64(1))) + + tests := []struct { + name string + filter iceberg.BooleanExpression + want []string + }{ + {"and", westOne, []string{"1:west"}}, + {"not and", iceberg.NewNot(westOne), []string{"1:east", "2:east", "3:west"}}, + {"not equal", iceberg.NotEqualTo(region, "east"), []string{"1:west", "3:west"}}, + { + "or", iceberg.NewOr(iceberg.EqualTo(region, "east"), iceberg.EqualTo(id, int64(3))), + []string{"1:east", "2:east", "3:west"}, + }, + {"in", iceberg.IsIn(region, "west", "north"), []string{"1:west", "3:west"}}, + {"not in", iceberg.NotIn(region, "west", "north"), []string{"1:east", "2:east"}}, + {"starts with", iceberg.StartsWith(region, "ea"), []string{"1:east", "2:east"}}, + {"is null", iceberg.IsNull(region), []string{}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.want, scanIDAndColumn(t, tbl, WithRowFilter(tt.filter))) + }) + } +} + +// Delete evaluates its filter per file: copy-on-write keeps the rows that do +// not match, and merge-on-read writes position deletes for the rows that do. +func TestDeleteOnIdentityPartitionColumnMissingFromDataFile(t *testing.T) { + for _, mode := range []string{WriteModeCopyOnWrite, WriteModeMergeOnRead} { + t.Run(mode, func(t *testing.T) { + tbl := regionTestTable(t, iceberg.Properties{ + PropertyFormatVersion: "2", Review Comment: a9c1fa4 added v3 copy-on-write runs, but they still passed with the fold in `processRecordsWithPlans` disabled: their kept-rows filter can't prune on a null column. 737b0d6 adds a delete that keeps `region = 'east' AND id != 1`. Its v3 copy-on-write run fails without that fold, since id 2 is lost, and passes with it. ########## table/arrow_utils.go: ########## @@ -1549,6 +1571,33 @@ func toRequestedSchema(ctx context.Context, requested, fileSchema *iceberg.Schem return out, nil } +// convertPartitionConstants widens each constant to the type its field has in +// the requested schema: a manifest keeps the partition type the file was +// written with, so a field promoted since still carries the narrower value. +// It returns constants itself when nothing needs converting. Review Comment: Done in a9c1fa4: the doc comment says it allocates a new map per call, once per record batch. Converting once per file is #2755. -- 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]
