cloud-fan commented on a change in pull request #25107: [SPARK-28344][SQL]
detect ambiguous self-join and fail the query
URL: https://github.com/apache/spark/pull/25107#discussion_r309639009
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/Column.scala
##########
@@ -144,11 +153,16 @@ class Column(val expr: Expression) extends Logging {
override def toString: String = toPrettySQL(expr)
override def equals(that: Any): Boolean = that match {
- case that: Column => that.expr.equals(this.expr)
+ case that: Column => that.normalizedExpr().equals(this.normalizedExpr())
case _ => false
}
- override def hashCode: Int = this.expr.hashCode()
+ override def hashCode: Int = this.normalizedExpr().hashCode()
+
+ private def normalizedExpr(): Expression = expr match {
Review comment:
good catch!
However, I'm not able to test it. The `normalizedExpr` is only used in
`equals` and `hashCode`. For `df("a.b")`, we will create a new alias everytime,
see `AttributeSeq.resolve`.
That said, if we get multiple `Column` instances via calling `df("a.b")`
multiple times, these `Column` instances will never equal to each other,
because the alias is different.
----------------------------------------------------------------
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]