You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ze...@apache.org on 2026/06/26 17:11:36 UTC

(iceberg-go) branch main updated: fix(literals): incorrect comparison result for (false, false) in BoolLiteral.Comparator (#1317)

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 ed207d84 fix(literals): incorrect comparison result for (false, false) in BoolLiteral.Comparator (#1317)
ed207d84 is described below

commit ed207d846227630c6296f030f3ccb0ebc9c8ba10
Author: Badal Prasad Singh <ba...@datazip.io>
AuthorDate: Fri Jun 26 22:41:30 2026 +0530

    fix(literals): incorrect comparison result for (false, false) in BoolLiteral.Comparator (#1317)
    
    BoolLiteral.Comparator returned -1 for (false, false) because it fell through the v1 branch unconditionally; replace with an explicit v1 == v2 equality check. Adds a comparator test covering all four boolean pairs.
---
 literals.go      |  7 +++----
 literals_test.go | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/literals.go b/literals.go
index 3301cea7..05bc4fdf 100644
--- a/literals.go
+++ b/literals.go
@@ -376,11 +376,10 @@ type BoolLiteral bool
 
 func (BoolLiteral) Comparator() Comparator[bool] {
 	return func(v1, v2 bool) int {
+		if v1 == v2 {
+			return 0
+		}
 		if v1 {
-			if v2 {
-				return 0
-			}
-
 			return 1
 		}
 
diff --git a/literals_test.go b/literals_test.go
index e42987b6..70403abb 100644
--- a/literals_test.go
+++ b/literals_test.go
@@ -736,6 +736,27 @@ func TestInvalidBoolLiteralConversions(t *testing.T) {
 	})
 }
 
+func TestBoolLiteralComparator(t *testing.T) {
+	cmp := iceberg.BoolLiteral(false).Comparator()
+
+	tests := []struct {
+		name     string
+		v1, v2   bool
+		expected int
+	}{
+		{"false_equals_false", false, false, 0},
+		{"true_equals_true", true, true, 0},
+		{"false_less_than_true", false, true, -1},
+		{"true_greater_than_false", true, false, 1},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			assert.Equal(t, tt.expected, cmp(tt.v1, tt.v2))
+		})
+	}
+}
+
 func TestInvalidNumericConversions(t *testing.T) {
 	testInvalidLiteralConversions(t, iceberg.NewLiteral(int32(34)), []iceberg.Type{
 		iceberg.PrimitiveTypes.Bool,