-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-6429] Implement hashCode and equals together #12157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,4 +22,8 @@ package org.apache.spark.util.collection | |
| */ | ||
| case class FixedHashObject(v: Int, h: Int) extends Serializable { | ||
| override def hashCode(): Int = h | ||
| override def equals(other: Any): Boolean = other match { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although this very technically changes semantics, given the clear and specific purpose of this class, I don't think it hurts to define reasonable equality semantics instead of leaving it to reference equality.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually if we do call
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha you're right about that. Right, this actually represents no behavior change. |
||
| case that: FixedHashObject => v == that.v && h == that.h | ||
| case _ => false | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
|
|
||
| package org.apache.spark.sql.types | ||
|
|
||
| import java.util.Objects | ||
|
|
||
| import org.json4s.JsonAST.JValue | ||
| import org.json4s.JsonDSL._ | ||
|
|
||
|
|
@@ -83,6 +85,8 @@ abstract class UserDefinedType[UserType >: Null] extends DataType with Serializa | |
|
|
||
| override def sql: String = sqlType.sql | ||
|
|
||
| override def hashCode(): Int = getClass.hashCode() | ||
|
|
||
| override def equals(other: Any): Boolean = other match { | ||
| case that: UserDefinedType[_] => this.acceptsType(that) | ||
| case _ => false | ||
|
|
@@ -115,7 +119,9 @@ private[sql] class PythonUserDefinedType( | |
| } | ||
|
|
||
| override def equals(other: Any): Boolean = other match { | ||
| case that: PythonUserDefinedType => this.pyUDT.equals(that.pyUDT) | ||
| case that: PythonUserDefinedType => pyUDT == that.pyUDT | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ought to be equivalent in Scala right? just triple checking
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the same except that it works event if``pyUDT` is null. |
||
| case _ => false | ||
| } | ||
|
|
||
| override def hashCode(): Int = Objects.hashCode(pyUDT) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may upset MiMa since you effectively remove an 'idx' property but it can be ignored for our purposes as it's a private class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense