Skip to content

Commit 3ea5678

Browse files
committed
MapR [SPARK-170] StackOverflowException in equals method in DBMapValue (apache#233)
1 parent 5ee588f commit 3ea5678

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

external/maprdb/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
<version>${project.version}</version>
2727
<scope>provided</scope>
2828
</dependency>
29+
<dependency>
30+
<groupId>org.apache.spark</groupId>
31+
<artifactId>spark-core_${scala.binary.version}</artifactId>
32+
<version>${project.version}</version>
33+
<type>test-jar</type>
34+
<scope>test</scope>
35+
</dependency>
2936
<dependency>
3037
<groupId>org.apache.spark</groupId>
3138
<artifactId>spark-streaming_${scala.binary.version}</artifactId>

external/maprdb/src/main/scala/com/mapr/db/spark/types/DBMapValue.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ private[spark] final class DBMapValue(
6767
override def hashCode(): Int = this.keySet.size
6868

6969
override def equals(other: Any): Boolean = {
70-
if (other.isInstanceOf[DBMapValue]) {
71-
val that: DBMapValue = other.asInstanceOf[DBMapValue]
72-
this == that
73-
} else if (other.isInstanceOf[Map[_, _]]) {
74-
val that: DBMapValue = new DBMapValue(
75-
other.asInstanceOf[Map[String, AnyRef]])
76-
this.getMap == that
77-
} else false
78-
70+
other match {
71+
case _: Map[_, _] =>
72+
val that: DBMapValue = new DBMapValue(
73+
other.asInstanceOf[Map[String, AnyRef]])
74+
this.getMap == that
75+
case _ => false
76+
}
7977
}
8078
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* Copyright (c) 2015 & onwards. MapR Tech, Inc., All rights reserved */
2+
package com.mapr.db.spark.types
3+
4+
import org.apache.spark.SparkFunSuite
5+
6+
class DBMapValueTest extends SparkFunSuite {
7+
test("Check DBMapValue equals method") {
8+
val map = Map("1" -> "2", "a" -> "b")
9+
val dbMapValue = new DBMapValue(map)
10+
val dbMapValueOther = new DBMapValue(map)
11+
12+
assert(!dbMapValue.equals("StringType"))
13+
assert(dbMapValue.equals(map))
14+
assert(dbMapValue.equals(dbMapValueOther))
15+
}
16+
}

0 commit comments

Comments
 (0)