You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/02/15 10:20:45 UTC

[GitHub] HyukjinKwon commented on a change in pull request #23789: [SPARK-26878] QueryTest.compare() does not handle maps with array keys correctly

HyukjinKwon commented on a change in pull request #23789: [SPARK-26878] QueryTest.compare() does not handle maps with array keys correctly
URL: https://github.com/apache/spark/pull/23789#discussion_r257178264
 
 

 ##########
 File path: sql/core/src/test/scala/org/apache/spark/sql/QueryTest.scala
 ##########
 @@ -341,9 +341,15 @@ 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)
+      if (a.size == b.size && a.size > 0) {
+        a.keys.map { aKey =>
+          b.keys.find(bKey => compare(aKey, bKey))
+            .map(bKey => compare(a(aKey), b(bKey)))
+            .getOrElse(false)
+        }.reduce(_ && _)
+      } else {
+        a.size == b.size
+      }
 
 Review comment:
   How about:
   
   ```scala
         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.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org