HyukjinKwon commented on a change in pull request #27517:
[WIP][SPARK-29721][SQL] Prune unnecessary nested fields from Generate without
Project
URL: https://github.com/apache/spark/pull/27517#discussion_r376898122
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/NestedColumnAliasing.scala
##########
@@ -155,6 +161,56 @@ object NestedColumnAliasing {
case MapType(keyType, valueType, _) => totalFieldNum(keyType) +
totalFieldNum(valueType)
case _ => 1 // UDT and others
}
+}
+
+/**
+ * This prunes unnessary nested columns from `Generate` and optional `Project`
on top
+ * of it.
+ */
+object GeneratorNestedColumnAliasing {
+ def unapply(plan: LogicalPlan): Option[LogicalPlan] = plan match {
+ // Either `nestedPruningOnExpressions` or `nestedSchemaPruningEnabled` is
enabled, we
+ // need to prune nested columns through Project and under Generate. The
difference is
+ // when `nestedSchemaPruningEnabled` is on, nested columns will be pruned
further at
+ // file format readers if it is supported.
+ case Project(projectList, g: Generate) if
(SQLConf.get.nestedPruningOnExpressions ||
+ SQLConf.get.nestedSchemaPruningEnabled) &&
canPruneGenerator(g.generator) =>
+ // On top on `Generate`, a `Project` that might have nested column
accessors.
+ // We try to get alias maps for both project list and generator's
children expressions.
+ NestedColumnAliasing.getAliasSubMap(projectList ++
g.generator.children).map {
+ case (nestedFieldToAlias, attrToAliases) =>
+ val newChild = pruneGenerate(g, nestedFieldToAlias, attrToAliases)
+ Project(NestedColumnAliasing.getNewProjectList(projectList,
nestedFieldToAlias), newChild)
+ }
+
+ case g: Generate if SQLConf.get.nestedSchemaPruningEnabled &&
+ canPruneGenerator(g.generator) =>
+ // For the child outputs required by the operator on top of `Generate`,
we do not want
+ // to prune it.
Review comment:
@viirya I think it's better to elaborate this comment a bit more the reason
why we don't want to prune it. It's basically to keep the child in case it's
referred from higher projection (that was missed from `case
Project(projectList, g: Generate)` case).
----------------------------------------------------------------
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]