Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/7460#discussion_r34888271
--- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/Row.scala ---
@@ -364,18 +364,33 @@ trait Row extends Serializable {
false
}
- 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.
+ /**
+ * 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: Row) = {
+ // 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]
+ !other.isInstanceOf[InternalRow]
}
override def equals(o: Any): Boolean = {
- if (o == null || !canEqual(o)) return false
-
+ if (!o.isInstanceOf[Row]) return false
val other = o.asInstanceOf[Row]
+
+ if (!canEqual(other)) {
+ throw new UnsupportedOperationException(
+ "cannot check equality between external and internal rows")
+ }
+
+ if (other eq null) return false
--- End diff --
finally figure out how to use `eq` to do null check here...
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]