eneskeles commented on code in PR #2111: URL: https://github.com/apache/iceberg-go/pull/2111#discussion_r4210201324
########## table/copy_on_write_null_rows_test.go: ########## @@ -0,0 +1,347 @@ +// 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_test + +import ( + "context" + "math" + "path/filepath" + "slices" + "testing" + + "github.com/apache/arrow-go/v18/arrow" + "github.com/apache/arrow-go/v18/arrow/array" + "github.com/apache/arrow-go/v18/arrow/memory" + "github.com/apache/iceberg-go" + iceio "github.com/apache/iceberg-go/io" + "github.com/apache/iceberg-go/table" + "github.com/stretchr/testify/require" +) + +// A copy-on-write delete must remove only the rows the filter is true for. +// Rows where the filter is NULL (because a referenced column is NULL) don't +// match it and must survive the rewrite. +func TestCopyOnWriteDeleteKeepsRowsWhereFilterIsNull(t *testing.T) { + age := iceberg.Reference("age") + name := iceberg.Reference("name") + + // rows: id=1 {25, "a"}, id=2 {30, NULL}, id=3 {NULL, "c"}, id=4 {40, "d"} + cases := []struct { + name string + filter iceberg.BooleanExpression + want []int64 + }{ + {"equal", iceberg.EqualTo(age, int64(30)), []int64{1, 3, 4}}, + {"greater than", iceberg.GreaterThan(age, int64(35)), []int64{1, 2, 3}}, + {"in", iceberg.IsIn(age, int64(30), int64(40)), []int64{1, 3}}, + // binding reduces the set to one value and the predicate to Equal + {"in with duplicate values", iceberg.IsIn(age, int64(30), int64(30)), []int64{1, 3, 4}}, + {"not in", iceberg.NotIn(age, int64(30), int64(40)), []int64{2, 3, 4}}, + {"not in with duplicate values", iceberg.NotIn(age, int64(30), int64(30)), []int64{2, 3}}, + {"not", iceberg.NewNot(iceberg.EqualTo(age, int64(30))), []int64{2, 3}}, + {"is null", iceberg.IsNull(age), []int64{1, 2, 4}}, + {"and", iceberg.NewAnd(iceberg.EqualTo(age, int64(30)), iceberg.EqualTo(name, "c")), []int64{1, 2, 3, 4}}, + {"or", iceberg.NewOr(iceberg.EqualTo(age, int64(25)), iceberg.EqualTo(name, "c")), []int64{2, 4}}, + {"not and", iceberg.NewNot(iceberg.NewAnd(iceberg.EqualTo(age, int64(30)), iceberg.EqualTo(name, "c"))), []int64{2, 3}}, + // the literal is outside the file's bounds, so every non-NULL row + // matches and only the NULL row keeps the file from being deleted whole + {"not equal outside bounds", iceberg.NotEqualTo(age, int64(100)), []int64{3}}, Review Comment: I added the asserts. -- 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]
