Skip to content
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

[SPARK-32090][SQL] Improve UserDefinedType.equal() to make it be symmetrical #28923

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ abstract class UserDefinedType[UserType >: Null] extends DataType with Serializa
override def hashCode(): Int = getClass.hashCode()

override def equals(other: Any): Boolean = other match {
case that: UserDefinedType[_] => this.acceptsType(that)
case that: UserDefinedType[_] => this.getClass == that.getClass
case _ => false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ class UserDefinedTypeSuite extends QueryTest with SharedSparkSession with Parque
MyLabeledPoint(1.0, new TestUDT.MyDenseVector(Array(0.1, 1.0))),
MyLabeledPoint(0.0, new TestUDT.MyDenseVector(Array(0.3, 3.0)))).toDF()


test("SPARK-32090: equal") {
val udt1 = new ExampleBaseTypeUDT
val udt2 = new ExampleSubTypeUDT
val udt3 = new ExampleSubTypeUDT
assert(udt1 !== udt2)
assert(udt2 !== udt1)
assert(udt2 === udt3)
assert(udt3 === udt2)
}

test("SPARK-32090: acceptsType") {
val udt1 = new ExampleBaseTypeUDT
val udt2 = new ExampleSubTypeUDT
assert(udt1.acceptsType(udt2))
assert(!udt2.acceptsType(udt1))
}

test("register user type: MyDenseVector for MyLabeledPoint") {
val labels: RDD[Double] = pointsRDD.select('label).rdd.map { case Row(v: Double) => v }
val labelsArrays: Array[Double] = labels.collect()
Expand Down