AngersZhuuuu commented on a change in pull request #30467:
URL: https://github.com/apache/spark/pull/30467#discussion_r528521220



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/ComplexTypesSuite.scala
##########
@@ -117,4 +116,13 @@ class ComplexTypesSuite extends QueryTest with 
SharedSparkSession {
     val df = spark.createDataFrame(List(Row(Seq(Row(1), Row(null)))).asJava, 
schema)
     checkAnswer(df.select($"arr".getField("i")), Row(Seq(1, null)))
   }
+
+  test("SPARK-32002: Support ExtractValue from nested ArrayStruct") {
+    val jsonStr1 = """{"a": [{"b": [{"c": [1,2]}]}]}"""
+    val jsonStr2 = """{"a": [{"b": [{"c": [1]}, {"c": [2]}]}]}"""
+    val df = spark.read.json(Seq(jsonStr1, jsonStr2).toDS())
+    checkAnswer(df.select($"a.b.c"), Row(Seq(Seq(Seq(1, 2))))
+      :: Row(Seq(Seq(Seq(1), Seq(2)))) :: Nil)
+  }
+

Review comment:
       Can you add more test case show more depth such as `a.b.c.d` etc..

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/ComplexTypesSuite.scala
##########
@@ -18,11 +18,10 @@
 package org.apache.spark.sql
 
 import scala.collection.JavaConverters._
-
 import org.apache.spark.sql.catalyst.expressions.CreateNamedStruct

Review comment:
       nit:unnecessary change

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeExtractors.scala
##########
@@ -218,6 +226,77 @@ case class GetArrayStructFields(
   }
 }
 
+object ExtractNestedArray {
+  type ReturnType = Option[(DataType, Boolean, Seq[Boolean])]
+
+  def unapply(dataType: DataType): ReturnType = {
+    extractArrayType(dataType)
+  }
+
+  def extractArrayType(dataType: DataType): ReturnType = {
+    dataType match {
+      case ArrayType(dt, containsNull) =>
+        extractArrayType(dt) match {
+          case Some((d, cn, seq)) => Some((d, cn, containsNull +: seq))
+          case None => Some((dt, containsNull, Seq.empty[Boolean]))
+        }
+      case _ => None
+    }
+  }
+}
+
+case class ExtractNestedArrayField(
+  child: Expression,
+  ordinal: Int,
+  numFields: Int,
+  field: StructField,
+  containsNullSeq: Seq[Boolean]) extends UnaryExpression
+  with ExtractValue with NullIntolerant with CodegenFallback {

Review comment:
       Nit:  Indentation is 4 




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



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

Reply via email to