You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ze...@apache.org on 2023/05/25 14:18:05 UTC

[arrow] branch main updated: GH-35761: [Go] Fix map comparison in TypeEqual (#35762)

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.git


The following commit(s) were added to refs/heads/main by this push:
     new 6e9262377a GH-35761: [Go] Fix map comparison in TypeEqual (#35762)
6e9262377a is described below

commit 6e9262377abb46bdaa43ab55f75e1bd693035c97
Author: Herman Schaaf <he...@gmail.com>
AuthorDate: Thu May 25 15:17:57 2023 +0100

    GH-35761: [Go] Fix map comparison in TypeEqual (#35762)
    
    Fixes some edge cases when doing type comparison for the map type.
    * Closes: #35761
    
    Authored-by: Herman Schaaf <he...@gmail.com>
    Signed-off-by: Matt Topol <zo...@gmail.com>
---
 go/arrow/compare.go      | 24 ++++++++++++++++++++-
 go/arrow/compare_test.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/go/arrow/compare.go b/go/arrow/compare.go
index ee84ccf62d..58569b332c 100644
--- a/go/arrow/compare.go
+++ b/go/arrow/compare.go
@@ -29,7 +29,7 @@ type typeEqualsConfig struct {
 type TypeEqualOption func(*typeEqualsConfig)
 
 // CheckMetadata is an option for TypeEqual that allows checking for metadata
-// equality besides type equality. It only makes sense for STRUCT type.
+// equality besides type equality. It only makes sense for types with metadata.
 func CheckMetadata() TypeEqualOption {
 	return func(cfg *typeEqualsConfig) {
 		cfg.metadata = true
@@ -70,6 +70,28 @@ func TypeEqual(left, right DataType, opts ...TypeEqualOption) bool {
 			return false
 		}
 		return l.n == right.(*FixedSizeListType).n && l.elem.Nullable == right.(*FixedSizeListType).elem.Nullable
+	case *MapType:
+		if !TypeEqual(l.KeyType(), right.(*MapType).KeyType(), opts...) {
+			return false
+		}
+		if !TypeEqual(l.ItemType(), right.(*MapType).ItemType(), opts...) {
+			return false
+		}
+		if l.KeyField().Nullable != right.(*MapType).KeyField().Nullable {
+			return false
+		}
+		if l.ItemField().Nullable != right.(*MapType).ItemField().Nullable {
+			return false
+		}
+		if cfg.metadata {
+			if !l.KeyField().Metadata.Equal(right.(*MapType).KeyField().Metadata) {
+				return false
+			}
+			if !l.ItemField().Metadata.Equal(right.(*MapType).ItemField().Metadata) {
+				return false
+			}
+		}
+		return true
 	case *StructType:
 		r := right.(*StructType)
 		switch {
diff --git a/go/arrow/compare_test.go b/go/arrow/compare_test.go
index 567de47b28..b33da3f3ae 100644
--- a/go/arrow/compare_test.go
+++ b/go/arrow/compare_test.go
@@ -18,6 +18,7 @@ package arrow
 
 import (
 	"testing"
+	"time"
 )
 
 func TestTypeEqual(t *testing.T) {
@@ -289,6 +290,59 @@ func TestTypeEqual(t *testing.T) {
 			},
 			false, true,
 		},
+		{
+			MapOf(BinaryTypes.String, PrimitiveTypes.Int32),
+			MapOf(BinaryTypes.String, PrimitiveTypes.Int32),
+			true, false,
+		},
+		{
+			MapOf(PrimitiveTypes.Int32, FixedWidthTypes.Timestamp_ns),
+			MapOf(PrimitiveTypes.Int32, FixedWidthTypes.Timestamp_ns),
+			true, false,
+		},
+		{
+			MapOf(BinaryTypes.String, &TimestampType{
+				Unit:     0,
+				TimeZone: "UTC",
+				loc:      time.UTC,
+			}),
+			MapOf(BinaryTypes.String, &TimestampType{
+				Unit:     0,
+				TimeZone: "UTC",
+				loc:      nil,
+			}),
+			true, false,
+		},
+		{
+			MapOf(PrimitiveTypes.Int32, FixedWidthTypes.Timestamp_ns),
+			MapOf(PrimitiveTypes.Int32, FixedWidthTypes.Timestamp_us),
+			false, false,
+		},
+		{
+			MapOf(BinaryTypes.String, FixedWidthTypes.Timestamp_ns),
+			MapOf(PrimitiveTypes.Int32, FixedWidthTypes.Timestamp_ns),
+			false, false,
+		},
+		{
+			MapOfWithMetadata(BinaryTypes.String, MetadataFrom(map[string]string{"key": "v1"}), FixedWidthTypes.Timestamp_ns, MetadataFrom(map[string]string{"item": "v1"})),
+			MapOfWithMetadata(BinaryTypes.String, MetadataFrom(map[string]string{"key": "v1"}), FixedWidthTypes.Timestamp_ns, MetadataFrom(map[string]string{"item": "v1"})),
+			true, true,
+		},
+		{
+			MapOfWithMetadata(BinaryTypes.String, MetadataFrom(map[string]string{"key": "v1"}), FixedWidthTypes.Timestamp_ns, MetadataFrom(map[string]string{"item": "v1"})),
+			MapOfWithMetadata(BinaryTypes.String, MetadataFrom(map[string]string{"key": "v2"}), FixedWidthTypes.Timestamp_ns, MetadataFrom(map[string]string{"item": "v2"})),
+			true, false,
+		},
+		{
+			MapOfWithMetadata(BinaryTypes.String, MetadataFrom(map[string]string{"key": "v1"}), FixedWidthTypes.Timestamp_ns, MetadataFrom(map[string]string{"item": "v1"})),
+			MapOfWithMetadata(BinaryTypes.String, MetadataFrom(map[string]string{"key": "v1"}), FixedWidthTypes.Timestamp_ns, MetadataFrom(map[string]string{"item": "v2"})),
+			false, true,
+		},
+		{
+			MapOfWithMetadata(BinaryTypes.String, MetadataFrom(map[string]string{"key": "v1"}), FixedWidthTypes.Timestamp_ns, MetadataFrom(map[string]string{"item": "v1"})),
+			MapOfWithMetadata(BinaryTypes.String, MetadataFrom(map[string]string{"key": "v2"}), FixedWidthTypes.Timestamp_ns, MetadataFrom(map[string]string{"item": "v1"})),
+			false, true,
+		},
 	}
 
 	for _, test := range tests {