Github user xuanyuanking commented on a diff in the pull request:
https://github.com/apache/spark/pull/14957#discussion_r85656841
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/FileSourceStrategySuite.scala
---
@@ -442,6 +443,79 @@ class FileSourceStrategySuite extends QueryTest with
SharedSQLContext with Predi
}
}
+ test("[SPARK-4502] pruning nested schema by projects correctly") {
+ val testFunc =
PrivateMethod[Seq[StructField]]('generateStructFieldsContainsNesting)
+ // Construct fullSchema like below:
+ // root
+ // |-- col: struct (nullable = true)
+ // | |-- s1: struct (nullable = true)
+ // | | |-- s1_1: long (nullable = true)
+ // | | |-- s1_2: long (nullable = true)
+ // | |-- str: string (nullable = true)
+ // | |-- info_list: array (nullable = true)
+ // | | |-- element: struct (containsNull = true)
+ // | | | |-- s1: struct (nullable = true)
+ // | | | | |-- s1_1: long (nullable = true)
+ // | | | | |-- s1_2: long (nullable = true)
+ // |-- num: long (nullable = true)
+ // |-- str: string (nullable = true)
+ val nested_s1 = StructField("s1",
+ StructType(
+ Seq(
+ StructField("s1_1", LongType, true),
+ StructField("s1_2", LongType, true)
+ )
+ ), true)
+ val flat_str = StructField("str", StringType, true)
+ val nested_arr = StructField("info_list",
ArrayType(StructType(Seq(nested_s1))), true)
+
+ val fullSchema = StructType(
+ Seq(
+ StructField("col", StructType(Seq(nested_s1, flat_str,
nested_arr)), true),
+ StructField("num", LongType, true),
+ flat_str
+ ))
+
+ // Attr of struct col
+ val colAttr = AttributeReference("col", StructType(
+ Seq(nested_s1, flat_str, nested_arr)), true)()
+ // Child expression of col.s1.s1_1
+ val childExp = GetStructField(
+ GetStructField(colAttr, 0, Some("s1")), 0, Some("s1_1"))
+ // Child expression of col.info_list[0].s1.s1_1
+ val arrayChildExp = GetStructField(
+ GetStructField(
+ GetArrayItem(
+ GetStructField(colAttr, 0, Some("info_list")),
+ Literal(0)
+ ), 0, Some("s1")
+ ), 0, Some("s1_1")
+ )
+ // Project list of "select num, col.s1.s1_1 as s1_1,
col.info_list[0].s1.s1_1 as complex_get"
+ val projects = Seq(
+ AttributeReference("num", LongType, true)(),
+ Alias(childExp, "s1_1")(),
+ Alias(arrayChildExp, "complex_get")()
+ )
+ val expextResult =
+ Seq(
+ StructField("num", LongType, true),
+ StructField("col", StructType(
+ Seq(
+ StructField(
+ "s1",
+ StructType(Seq(StructField("s1_1", LongType, true))),
+ true)
+ )
+ ), true),
+ StructField("col", StructType(Seq(nested_arr)))
+ )
+ // Call the function generateStructFieldsContainsNesting
+ val result =
FileSourceStrategy.invokePrivate[Seq[StructField]](testFunc(projects,
+ fullSchema))
+ assert(result == expextResult)
+ }
--- End diff --
fix done. Thanks for liancheng's remind.
Here I considered the CreateStruct(Unsafe) and CreateNamedStruct(Unsafe),
other expressions in complexTypeCreator(CreateArray, CreateMap) just ignore.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]