cloud-fan commented on a change in pull request #26173: [SPARK-29503][SQL] 
Remove conversion CreateNamedStruct to CreateNamedStructUnsafe
URL: https://github.com/apache/spark/pull/26173#discussion_r337843868
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/DataFrameComplexTypeSuite.scala
 ##########
 @@ -64,6 +70,33 @@ class DataFrameComplexTypeSuite extends QueryTest with 
SharedSparkSession {
     val ds100_5 = Seq(S100_5()).toDS()
     ds100_5.rdd.count
   }
+
+  test("SPARK-29503 nest unsafe struct inside safe array") {
+    withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> "false") {
+      val exampleDS = spark.sparkContext.parallelize(Seq(Seq(1, 2, 
3))).toDF("items")
+
+      // items: Seq[Int] => items.map { item => Seq(Struct(item)) }
+      val result = exampleDS.select(
+        new Column(MapObjects(
+          (item: Expression) => array(struct(new Column(item))).expr,
+          $"items".expr,
+          
exampleDS.schema("items").dataType.asInstanceOf[ArrayType].elementType
+        )) as "items"
+      ).collect()
+
+      def getValueInsideDepth(result: Row, index: Int): Int = {
+        // expected output:
+        // WrappedArray([WrappedArray(WrappedArray([1]), WrappedArray([2]), 
WrappedArray([3]))])
+        result.getSeq[mutable.WrappedArray[_]](0)(index)(0)
+          .asInstanceOf[GenericRowWithSchema].getInt(0)
+      }
+
+      assert(result.size === 1)
+      assert(getValueInsideDepth(result.head, 0) === 1)
+      assert(getValueInsideDepth(result.head, 1) === 2)
+      assert(getValueInsideDepth(result.head, 2) === 3)
 
 Review comment:
   +1

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to