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 2021/06/08 04:59:11 UTC

[GitHub] [spark] maropu commented on a change in pull request #32783: [SPARK-35653][SQL] Fix CatalystToExternalMap interpreted path fails for Map with case classes as keys or values

maropu commented on a change in pull request #32783:
URL: https://github.com/apache/spark/pull/32783#discussion_r647110803



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
##########
@@ -1181,21 +1176,25 @@ case class CatalystToExternalMap private(
     newMapBuilderMethod.invoke(moduleField).asInstanceOf[Builder[AnyRef, AnyRef]]
   }
 
+  private def keyValueIterator(md: MapData): Iterator[AnyRef] = {
+    val keyArray = md.keyArray()
+    val valueArray = md.valueArray()
+    val row = new GenericInternalRow(1)
+    0.until(md.numElements()).iterator.map { i =>
+      row.update(0, keyArray.get(i, inputMapType.keyType))
+      val key = keyLambdaFunction.eval(row)
+      row.update(0, valueArray.get(i, inputMapType.valueType))
+      val value = valueLambdaFunction.eval(row)
+      Tuple2(key, value)
+    }
+  }
+
   override def eval(input: InternalRow): Any = {
     val result = inputData.eval(input).asInstanceOf[MapData]
     if (result != null) {
       val builder = newMapBuilder()
       builder.sizeHint(result.numElements())
-      val keyArray = result.keyArray()
-      val valueArray = result.valueArray()
-      var i = 0
-      while (i < result.numElements()) {

Review comment:
       We tend to use `while` for perf-intensive code. The proposed code does not cause any perf overhead? 




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

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



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