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/arrow-go.git
The following commit(s) were added to refs/heads/main by this push:
new 2ce24eb5 fix(arrow): include KeysSorted in map equality (#1134)
2ce24eb5 is described below
commit 2ce24eb56572d773f35da93945e34541104b87ed
Author: Minh Vu <[email protected]>
AuthorDate: Wed Aug 12 19:35:13 2026 +0200
fix(arrow): include KeysSorted in map equality (#1134)
### Rationale for this change
MapType includes KeysSorted in its fingerprint and string
representation, but TypeEqual ignores it. Maps with different
key-ordering contracts can therefore compare equal.
### What changes are included in this PR?
Compare KeysSorted as part of map type equality and add coverage for
both values.
### Are these changes tested?
- `go test ./arrow`
### Are there any user-facing changes?
Map types with different KeysSorted values no longer compare equal.
There are no API changes.
---
arrow/compare.go | 16 ++++++++++------
arrow/compare_test.go | 16 ++++++++++++++++
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/arrow/compare.go b/arrow/compare.go
index bdb4ec2b..abf5ac83 100644
--- a/arrow/compare.go
+++ b/arrow/compare.go
@@ -74,23 +74,27 @@ func TypeEqual(left, right DataType, opts
...TypeEqualOption) bool {
}
return l.n == right.(*FixedSizeListType).n && l.elem.Nullable
== right.(*FixedSizeListType).elem.Nullable
case *MapType:
- if !TypeEqual(l.KeyType(), right.(*MapType).KeyType(), opts...)
{
+ r := right.(*MapType)
+ if !TypeEqual(l.KeyType(), r.KeyType(), opts...) {
return false
}
- if !TypeEqual(l.ItemType(), right.(*MapType).ItemType(),
opts...) {
+ if !TypeEqual(l.ItemType(), r.ItemType(), opts...) {
return false
}
- if l.KeyField().Nullable !=
right.(*MapType).KeyField().Nullable {
+ if l.KeysSorted != r.KeysSorted {
return false
}
- if l.ItemField().Nullable !=
right.(*MapType).ItemField().Nullable {
+ if l.KeyField().Nullable != r.KeyField().Nullable {
+ return false
+ }
+ if l.ItemField().Nullable != r.ItemField().Nullable {
return false
}
if cfg.metadata {
- if
!l.KeyField().Metadata.Equal(right.(*MapType).KeyField().Metadata) {
+ if !l.KeyField().Metadata.Equal(r.KeyField().Metadata) {
return false
}
- if
!l.ItemField().Metadata.Equal(right.(*MapType).ItemField().Metadata) {
+ if
!l.ItemField().Metadata.Equal(r.ItemField().Metadata) {
return false
}
}
diff --git a/arrow/compare_test.go b/arrow/compare_test.go
index ca87621e..84f005d3 100644
--- a/arrow/compare_test.go
+++ b/arrow/compare_test.go
@@ -22,6 +22,12 @@ import (
)
func TestTypeEqual(t *testing.T) {
+ mapType := func(keysSorted bool) DataType {
+ typ := MapOf(BinaryTypes.String, PrimitiveTypes.Int32)
+ typ.KeysSorted = keysSorted
+ return typ
+ }
+
tests := []struct {
left, right DataType
want bool
@@ -332,6 +338,16 @@ func TestTypeEqual(t *testing.T) {
MapOf(BinaryTypes.String, PrimitiveTypes.Int32),
true, false,
},
+ {
+ mapType(false),
+ mapType(true),
+ false, false,
+ },
+ {
+ mapType(true),
+ mapType(true),
+ true, false,
+ },
{
MapOf(PrimitiveTypes.Int32,
FixedWidthTypes.Timestamp_ns),
MapOf(PrimitiveTypes.Int32,
FixedWidthTypes.Timestamp_ns),