Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Fix equals and tests
  • Loading branch information
c27kwan committed Sep 6, 2022
commit 02a55323aa4640c80c51a39d556ee3d46e48ee52
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,10 @@ class ArrayBasedMapData(val keyArray: ArrayData, val valueArray: ArrayData) exte
}

override def equals(obj: Any): Boolean = {
if (obj == null && this == null) {
return true
obj match {
case other: ArrayBasedMapData => keyArray == other.keyArray && valueArray == other.valueArray
case _ => false
}

if (obj == null || !obj.isInstanceOf[ArrayBasedMapData]) {
return false
}

val other = obj.asInstanceOf[ArrayBasedMapData]

keyArray.equals(other.keyArray) && valueArray.equals(other.valueArray)
}

// Hash this class as a Product of two hashCodes. We don't know the DataType which prevents us
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ package org.apache.spark.sql.catalyst.util
import org.apache.spark.sql.types.DataType

/**
* This is an internal data representation for map type in Spark SQL. This should not implement
* `equals` and `hashCode` because the type cannot be used as join keys, grouping keys, or
* in equality tests. See SPARK-9415 and PR#13847 for the discussions.
* This is an internal data representation for map type in Spark SQL. This type cannot be used as
* join keys, grouping keys, or in equality tests. See SPARK-9415 and PR#13847 for the discussions.
*/
abstract class MapData extends Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,11 @@ class ArrayBasedMapBuilderSuite extends SparkFunSuite with SQLHelper {

// We expect two objects to be equal and to have the same hashCode if they have the same
// elements.
assert(arrayBasedMapData1 == arrayBasedMapData2)
assert(arrayBasedMapData1.equals(arrayBasedMapData2))
assert(arrayBasedMapData1.hashCode() == arrayBasedMapData2.hashCode())

// If two objects have different elements, we expect them to not be equal and their hashCode
// If two objects have different elements, we expect them not to be equal and their hashCode
// to be different.
assert(arrayBasedMapData1 != arrayBasedMapData3)
assert(!arrayBasedMapData1.equals(arrayBasedMapData3))
assert(arrayBasedMapData1.hashCode() != arrayBasedMapData3.hashCode())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class ComplexDataSuite extends SparkFunSuite {
val testArrayMap2 = ArrayBasedMapData(testMap2.toMap)
val testArrayMap3 = ArrayBasedMapData(testMap3.toMap)
val testArrayMap4 = ArrayBasedMapData(testMap4.toMap)
assert(testArrayMap1 !== testArrayMap3)
assert(testArrayMap2 !== testArrayMap4)

// UnsafeMapData
val unsafeConverter = UnsafeProjection.create(Array[DataType](MapType(StringType, IntegerType)))
Expand Down