cloud-fan commented on code in PR #40300:
URL: https://github.com/apache/spark/pull/40300#discussion_r1129167837
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala:
##########
@@ -340,13 +358,26 @@ trait ExposesMetadataColumns extends LogicalPlan {
val resolve = conf.resolver
val outputNames = outputSet.map(_.name)
- def isOutputColumn(col: AttributeReference): Boolean = {
- outputNames.exists(name => resolve(col.name, name))
+ // Generate a unique name by prepending underscores.
+ @scala.annotation.tailrec
+ def makeUnique(name: String): String = name match {
+ case name if outputNames.exists(resolve(_, name)) =>
makeUnique(s"_$name")
+ case name => name
+ }
+
+ // Rename metadata struct columns whose names conflict with output
columns.
Review Comment:
Name is not the id of a column, e.g. people can do `SELECT 1 a, 2 a`. I
don't quite understand why we need to rename here. What we need is to resolve
`_metadata` to the actual metadata `AttributeReference`. At the end Spark will
bind `AttributeReference` correctly by looking at `exprId`.
--
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]