kupferk commented on code in PR #37251:
URL: https://github.com/apache/spark/pull/37251#discussion_r927415479
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/CollapseProjectSuite.scala:
##########
@@ -223,6 +224,24 @@ class CollapseProjectSuite extends PlanTest {
assert(hasMetadata(optimized))
}
+ test("reset top-level alias metadata while collapsing projects") {
+ def hasNoMetadata(logicalPlan: LogicalPlan): Boolean = {
+
!logicalPlan.asInstanceOf[Project].projectList.exists(_.metadata.contains("key"))
+ }
+
+ val metadata = new MetadataBuilder().putLong("key", 1).build()
+ val analyzed =
+ Project(Seq(Alias('a_with_metadata, "b")(explicitMetadata =
Some(Metadata.empty))),
+ Project(Seq(Alias('a, "a_with_metadata")(explicitMetadata =
Some(metadata))),
+ testRelation.logicalPlan)).analyze
+ require(hasNoMetadata(analyzed))
Review Comment:
This is the implementation of "Alias.metadata", which either picks the
explicitly provided metadata OR passes on the one of the child. It does not
merge both of them.
```scala
override def metadata: Metadata = {
explicitMetadata.getOrElse {
child match {
case named: NamedExpression =>
removeNonInheritableMetadata(named.metadata)
case structField: GetStructField =>
removeNonInheritableMetadata(structField.metadata)
case _ => Metadata.empty
}
}
}
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]