This is an automated email from the ASF dual-hosted git repository.
kontinuation pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new eb897aac8 New instances of RasterUDT object should equal to the
RasterUDT case object (#1444)
eb897aac8 is described below
commit eb897aac82b99e1636eb454eb3363e72289f03e7
Author: Kristin Cowalcijk <[email protected]>
AuthorDate: Thu May 30 12:41:14 2024 +0800
New instances of RasterUDT object should equal to the RasterUDT case object
(#1444)
---
.../spark/sql/sedona_sql/UDT/GeometryUDT.scala | 2 +-
.../spark/sql/sedona_sql/UDT/RasterUDT.scala | 7 ++++
.../apache/sedona/sql/GeometryUdtTestScala.scala | 11 +++++-
.../org/apache/sedona/sql/RasterUDTSuite.scala | 39 ++++++++++++++++++++++
4 files changed, 57 insertions(+), 2 deletions(-)
diff --git
a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/UDT/GeometryUDT.scala
b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/UDT/GeometryUDT.scala
index 427ff8ac9..0e4125e6a 100644
---
a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/UDT/GeometryUDT.scala
+++
b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/UDT/GeometryUDT.scala
@@ -54,7 +54,7 @@ class GeometryUDT extends UserDefinedType[Geometry] {
case _ => false
}
- override def hashCode(): Int = super.hashCode()
+ override def hashCode(): Int = userClass.hashCode()
}
case object GeometryUDT extends
org.apache.spark.sql.sedona_sql.UDT.GeometryUDT with scala.Serializable
diff --git
a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/UDT/RasterUDT.scala
b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/UDT/RasterUDT.scala
index f88d61ccd..14c560ef6 100644
---
a/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/UDT/RasterUDT.scala
+++
b/spark/common/src/main/scala/org/apache/spark/sql/sedona_sql/UDT/RasterUDT.scala
@@ -41,6 +41,13 @@ class RasterUDT extends UserDefinedType[GridCoverage2D] {
}
override def userClass: Class[GridCoverage2D] = classOf[GridCoverage2D]
+
+ override def equals(other: Any): Boolean = other match {
+ case _: UserDefinedType[_] => other.isInstanceOf[RasterUDT]
+ case _ => false
+ }
+
+ override def hashCode(): Int = userClass.hashCode()
}
case object RasterUDT extends RasterUDT with Serializable
diff --git
a/spark/common/src/test/scala/org/apache/sedona/sql/GeometryUdtTestScala.scala
b/spark/common/src/test/scala/org/apache/sedona/sql/GeometryUdtTestScala.scala
index f0d038fea..a5afaeb09 100644
---
a/spark/common/src/test/scala/org/apache/sedona/sql/GeometryUdtTestScala.scala
+++
b/spark/common/src/test/scala/org/apache/sedona/sql/GeometryUdtTestScala.scala
@@ -58,7 +58,16 @@ class GeometryUdtTestScala extends TestBaseScala with
BeforeAndAfter {
}
it("Case object and new instance should be equals") {
- assert(GeometryUDT.equals(new GeometryUDT))
+ assert(GeometryUDT == GeometryUDT)
+ val udt = new GeometryUDT
+ assert(udt.equals(udt))
+ assert(udt.equals(GeometryUDT))
+ assert(GeometryUDT.equals(udt))
+ }
+
+ it("hashCode should work correctly") {
+ val udt = new GeometryUDT
+ assert(udt.hashCode() == GeometryUDT.hashCode())
}
}
diff --git
a/spark/common/src/test/scala/org/apache/sedona/sql/RasterUDTSuite.scala
b/spark/common/src/test/scala/org/apache/sedona/sql/RasterUDTSuite.scala
new file mode 100644
index 000000000..45f669696
--- /dev/null
+++ b/spark/common/src/test/scala/org/apache/sedona/sql/RasterUDTSuite.scala
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sedona.sql
+
+import org.apache.spark.sql.sedona_sql.UDT.RasterUDT
+import org.scalatest.funspec.AnyFunSpec
+
+class RasterUDTSuite extends AnyFunSpec {
+ describe("RasterUDT Test") {
+ it("Case object and new instance should be equals") {
+ assert(RasterUDT == RasterUDT)
+ val udt = new RasterUDT
+ assert(udt.equals(udt))
+ assert(udt.equals(RasterUDT))
+ assert(RasterUDT.equals(udt))
+ }
+
+ it("hashCode should work correctly") {
+ val udt = new RasterUDT
+ assert(udt.hashCode() == RasterUDT.hashCode())
+ }
+ }
+}