This is an automated email from the ASF dual-hosted git repository.
zeroshade 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 b653f8b22 fix(table): make NotIn skip NULL rows in scans (#2369)
b653f8b22 is described below
commit b653f8b227b69b10e13e6ee0d3ddff381b68b35f
Author: Anurag-S1ngh <[email protected]>
AuthorDate: Fri Oct 30 22:28:39 2026 +0530
fix(table): make NotIn skip NULL rows in scans (#2369)
Why: the record filter compiled a multi-value NOT IN as not(is_in(x, set)),
and is_in is false for a NULL term, so the negation was true and the NULL
row matched. A one-value NOT IN binds to NOT_EQ, which is NULL for a NULL
term, so the two paths disagreed, and copy-on-write deletes diverged from
scans for the multi-value form. Guard the negation with is_not_null so
NOT IN never matches NULL, whichever path built it.
Fixes #2132
Signed-off-by: Anurag Singh <[email protected]>
---
table/not_in_null_semantics_test.go | 43 +++++++++++++++++++++++++++++++++++++
table/substrait/substrait.go | 7 +++++-
table/substrait/substrait_test.go | 6 +++++-
3 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/table/not_in_null_semantics_test.go
b/table/not_in_null_semantics_test.go
new file mode 100644
index 000000000..8a3b0f842
--- /dev/null
+++ b/table/not_in_null_semantics_test.go
@@ -0,0 +1,43 @@
+// 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 (
+ "testing"
+
+ "github.com/apache/iceberg-go"
+ "github.com/stretchr/testify/require"
+)
+
+// A scan must use SQL three-valued logic for NotIn: a NULL term is neither in
+// nor out of the set, so the row does not match, whatever the number of
values.
+func TestScanNotInDoesNotMatchNullRows(t *testing.T) {
+ age := iceberg.Reference("age")
+
+ for _, version := range []string{"2", "3"} {
+ t.Run("v"+version, func(t *testing.T) {
+ tbl := newCopyOnWriteNullRowsTable(t, version)
+
+ // rows: id=1 {25}, id=2 {30}, id=3 {NULL}, id=4 {40}
+ require.Equal(t, []int64{1},
+ scanIDsMatching(t, tbl, iceberg.NotIn(age,
int64(30), int64(40))))
+ require.Equal(t, []int64{1, 4},
+ scanIDsMatching(t, tbl, iceberg.NotIn(age,
int64(30), int64(30))))
+ })
+ }
+}
diff --git a/table/substrait/substrait.go b/table/substrait/substrait.go
index c8a871e6c..e781f47a3 100644
--- a/table/substrait/substrait.go
+++ b/table/substrait/substrait.go
@@ -410,7 +410,12 @@ func (t *toSubstraitExpr) VisitIn(term iceberg.BoundTerm,
lits iceberg.Set[icebe
}
func (t *toSubstraitExpr) VisitNotIn(term iceberg.BoundTerm, lits
iceberg.Set[iceberg.Literal]) expr.Builder {
- return t.bldr.ScalarFunc(notID).Args(t.makeSetFunc(isInID, term,
lits).(expr.FuncArgBuilder))
+ notIn := t.bldr.ScalarFunc(notID).Args(t.makeSetFunc(isInID, term,
lits).(expr.FuncArgBuilder))
+
+ return t.bldr.ScalarFunc(andID).Args(
+ t.makeRefFunc(isNotNullID, term).(expr.FuncArgBuilder),
+ notIn,
+ )
}
func (t *toSubstraitExpr) makeRefFunc(id extensions.ID, term
iceberg.BoundTerm) expr.Builder {
diff --git a/table/substrait/substrait_test.go
b/table/substrait/substrait_test.go
index 9d4f380ce..fbc771eea 100644
--- a/table/substrait/substrait_test.go
+++ b/table/substrait/substrait_test.go
@@ -165,6 +165,10 @@ func TestExprs(t *testing.T) {
{iceberg.LessThan(ref, "hello"), tableSchemaSimple,
"lt(.field(0) => string?, string(hello)) => boolean?"},
{iceberg.StartsWith(ref, "he"), tableSchemaSimple,
"starts_with(.field(0) => string?, string(he)) => boolean?"},
{iceberg.NotStartsWith(ref, "he"), tableSchemaSimple,
"not(starts_with(.field(0) => string?, string(he)) => boolean?) => boolean?"},
+ {
+ iceberg.NotIn(ref, "hello", "world"), tableSchemaSimple,
+ "and(is_not_null(.field(0) => string?) => boolean,
not(is_in(.field(0) => string?, list<string>([string(hello) string(world)])) =>
boolean?) => boolean?) => boolean?",
+ },
{
iceberg.NewAnd(iceberg.EqualTo(ref, "hello"),
iceberg.IsNull(ref)), tableSchemaSimple,
"and(equal(.field(0) => string?, string(hello)) =>
boolean?, is_null(.field(0) => string?) => boolean) => boolean?",
@@ -241,7 +245,7 @@ func TestNanosecondTimestampLiterals(t *testing.T) {
name: "timestamp with timezone not in",
fieldType: iceberg.PrimitiveTypes.TimestampTzNs,
predicate: iceberg.NotIn(iceberg.Reference("ts"),
iceberg.TimestampNano(-1), iceberg.TimestampNano(1001)),
- wantExpr: "not(is_in(.field(0) =>
precision_timestamp_tz?<9>,
list<precision_timestamp_tz<9>>([precision_timestamp_tz<9>(1969-12-31T23:59:59.999999999Z)
precision_timestamp_tz<9>(1970-01-01T00:00:00.000001001Z)])) => boolean?) =>
boolean?",
+ wantExpr: "and(is_not_null(.field(0) =>
precision_timestamp_tz?<9>) => boolean, not(is_in(.field(0) =>
precision_timestamp_tz?<9>,
list<precision_timestamp_tz<9>>([precision_timestamp_tz<9>(1969-12-31T23:59:59.999999999Z)
precision_timestamp_tz<9>(1970-01-01T00:00:00.000001001Z)])) => boolean?) =>
boolean?) => boolean?",
},
{
name: "timestamp greater than",