You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "candiduslynx (via GitHub)" <gi...@apache.org> on 2023/05/30 17:39:09 UTC

[GitHub] [arrow] candiduslynx commented on a diff in pull request #35823: GH-35828: [Go] `array.ApproxEqual` allows map entries with different key order

candiduslynx commented on code in PR #35823:
URL: https://github.com/apache/arrow/pull/35823#discussion_r1210608935


##########
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()
+		}
+	}()

Review Comment:
   Done in e66e55c1c241fe081886e07019db750b40ff9fd0



##########
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
+			}
+		}

Review Comment:
   Done in e66e55c1c241fe081886e07019db750b40ff9fd0



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org