-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26878] QueryTest.compare() does not handle maps with array keys correctly #23789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -341,9 +341,11 @@ object QueryTest { | |
| case (a: Array[_], b: Array[_]) => | ||
| a.length == b.length && a.zip(b).forall { case (l, r) => compare(l, r)} | ||
| case (a: Map[_, _], b: Map[_, _]) => | ||
| val entries1 = a.iterator.toSeq.sortBy(_.toString()) | ||
| val entries2 = b.iterator.toSeq.sortBy(_.toString()) | ||
| compare(entries1, entries2) | ||
| a.size == b.size && a.keys.forall { aKey => | ||
| b.keys.find(bKey => compare(aKey, bKey)) | ||
| .map(bKey => compare(a(aKey), b(bKey))) | ||
|
||
| .getOrElse(false) | ||
|
||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about: a.size == b.size && a.keys.forall { aKey =>
val maybeBKey = b.keys.find(bKey => compare(aKey, bKey))
maybeBKey.isDefined && compare(a(aKey), b(maybeBKey.get))
}? I think it's similar with other iterable or array comparison. cc @cloud-fan who touched this code lately.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, this looks cleaner |
||
| case (a: Iterable[_], b: Iterable[_]) => | ||
| a.size == b.size && a.zip(b).forall { case (l, r) => compare(l, r)} | ||
| case (a: Product, b: Product) => | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 2 space indentation.