Github user rxin commented on a diff in the pull request: https://github.com/apache/spark/pull/7460#discussion_r34866819 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/Row.scala --- @@ -364,16 +364,29 @@ trait Row extends Serializable { false } + /** + * Returns true if we can check equality for these 2 rows. + * Equality check between external row and internal row is not allowed. + * Here we do this check to prevent call `equals` on external row with internal row. + */ protected def canEqual(other: Any) = { - // Note that InternalRow overrides canEqual. These two canEqual's together makes sure that - // comparing the external Row and InternalRow will always yield false. + // Note that `Row` is not only the interface of external row but also the parent + // of `InternalRow`, so we have to ensure `other` is not a internal row here to prevent + // call `equals` on external row with internal row. + // `InternalRow` overrides canEqual, and these two canEquals together makes sure that + // equality check between external Row and InternalRow will always fail. // In the future, InternalRow should not extend Row. In that case, we can remove these // canEqual methods. other.isInstanceOf[Row] && !other.isInstanceOf[InternalRow] } override def equals(o: Any): Boolean = { - if (o == null || !canEqual(o)) return false + if (!canEqual(o)) { + throw new UnsupportedOperationException( + "cannot check equality between external and internal rows") + } + + if (o == null) return false --- End diff -- technically you want .eq instead of == i think, because == actually triggers the equality of the other function
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org