dongjoon-hyun commented on a change in pull request #23740: [SPARK-26837][SQL]
Pruning nested fields from object serializers
URL: https://github.com/apache/spark/pull/23740#discussion_r254575772
##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DatasetSuite.scala
##########
@@ -1680,6 +1681,62 @@ class DatasetSuite extends QueryTest with
SharedSQLContext {
checkAnswer(ds, Seq(Row("a"), Row("b"), Row("c")))
}
+ test("SPARK-26837:Prune nested serializers") {
+ def testSerializer(df: DataFrame, structFields: Seq[Seq[String]]): Unit = {
+ val serializer = df.queryExecution.optimizedPlan.collect {
+ case s: SerializeFromObject => s
+ }.head
+
+ val structs = serializer.serializer(0).collect {
+ case c: CreateNamedStruct => c
+ }
+ assert(structs.size == structFields.size)
+ structs.zip(structFields).foreach { case (struct, fieldNames) =>
+ assert(struct.names.map(_.toString) == fieldNames)
+ }
+ }
+ withSQLConf(SQLConf.SERIALIZER_NESTED_SCHEMA_PRUNING_ENABLED.key ->
"true") {
+ val data = Seq((("a", 1, ("aa", 1.0)), 1), (("b", 2, ("bb", 2.0)), 2),
+ (("c", 3, ("cc", 3.0)), 3))
+ val ds = data.toDS().map(t => (t._1, t._2 + 1))
+
+ val df1 = ds.select("_1._1")
+ testSerializer(df1, Seq(Seq("_1")))
+ checkAnswer(df1, Seq(Row("a"), Row("b"), Row("c")))
+
+ val df2 = ds.select("_1._2")
+ testSerializer(df2, Seq(Seq("_2")))
+ checkAnswer(df2, Seq(Row(1), Row(2), Row(3)))
+
+ val df3 = ds.select("_1._3._1")
+ testSerializer(df3, Seq(Seq("_3"), Seq("_1")))
+ checkAnswer(df3, Seq(Row("aa"), Row("bb"), Row("cc")))
+
+ val df4 = ds.select("_1._3._1", "_1._2")
+ testSerializer(df4, Seq(Seq("_2", "_3"), Seq("_1")))
+ checkAnswer(df4, Seq(Row("aa", 1), Row("bb", 2), Row("cc", 3)))
+
+ val arrayData = Seq((Seq(("a", 1, ("a_1", 11)), ("b", 2, ("b_1", 22))),
1, ("aa", 1.0)),
Review comment:
Shall we split this into another test case because this function is a little
long?
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]