candiduslynx commented on code in PR #35823:
URL: https://github.com/apache/arrow/pull/35823#discussion_r1210621506
##########
go/arrow/array/compare.go:
##########
@@ -732,3 +732,57 @@ func arrayApproxEqualStruct(left, right *Struct, opt
equalOption) bool {
}
return true
}
+
+// arrayApproxEqualMap doesn't care about the order of keys (in Go map
traversal order is undefined)
+func arrayApproxEqualMap(left, right *Map, opt equalOption) bool {
+ for i := 0; i < left.Len(); i++ {
+ if left.IsNull(i) {
+ continue
+ }
+ if
!arrayApproxEqualSingleMapEntry(left.newListValue(i).(*Struct),
right.newListValue(i).(*Struct), opt) {
+ return false
+ }
+ }
+ return true
+}
+
+// arrayApproxEqualSingleMapEntry is a helper function that checks if a single
entry pair is approx equal.
+// Basically, it doesn't care about key order.
+// structs passed will be released
+func arrayApproxEqualSingleMapEntry(left, right *Struct, opt equalOption) bool
{
+ defer left.Release()
+ defer right.Release()
+
+ // Every element here is a key-value pair
+ lElems := make([]arrow.Array, left.Len())
+ rElems := make([]arrow.Array, right.Len())
+ for i := 0; i < left.Len(); i++ {
+ lElems[i] = NewSlice(left, int64(i), int64(i+1))
+ rElems[i] = NewSlice(right, int64(i), int64(i+1))
+ }
+ defer func() {
+ for i := range lElems {
+ lElems[i].Release()
+ rElems[i].Release()
+ }
+ }()
+
+ used := make(map[int]bool, right.Len())
+ for _, ll := range lElems {
+ found := false
+ for i, rr := range rElems {
+ if used[i] {
+ continue
+ }
+ if arrayApproxEqual(ll, rr, opt) {
+ found = true
+ used[i] = true
+ break
+ }
+ }
+ if !found {
+ return false
+ }
+ }
+ return true
Review Comment:
More versatile testing added in 0d82c068e0f85f00dfa91d87232f859e4b6d99e3
--
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]