Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12640#discussion_r61375365
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/ArrayData.scala 
---
    @@ -29,6 +29,82 @@ abstract class ArrayData extends SpecializedGetters with 
Serializable {
     
       def array: Array[Any]
     
    +  override def equals(o: Any): Boolean = {
    +    if (!o.isInstanceOf[ArrayData]) {
    +      return false
    +    }
    +
    +    val other = o.asInstanceOf[ArrayData]
    +    if (other eq null) {
    +      return false
    +    }
    +
    +    val len = numElements()
    +    if (len != other.numElements()) {
    +      return false
    +    }
    +
    +    var i = 0
    +    while (i < len) {
    +      if (isNullAt(i) != other.isNullAt(i)) {
    +        return false
    +      }
    +      if (!isNullAt(i)) {
    +        val o1 = array(i)
    +        val o2 = other.array(i)
    +        o1 match {
    +          case b1: Array[Byte] =>
    +            if (!o2.isInstanceOf[Array[Byte]] ||
    +              !java.util.Arrays.equals(b1, o2.asInstanceOf[Array[Byte]])) {
    +              return false
    +            }
    +          case f1: Float if java.lang.Float.isNaN(f1) =>
    +            if (!o2.isInstanceOf[Float] || ! 
java.lang.Float.isNaN(o2.asInstanceOf[Float])) {
    +              return false
    +            }
    +          case d1: Double if java.lang.Double.isNaN(d1) =>
    +            if (!o2.isInstanceOf[Double] || ! 
java.lang.Double.isNaN(o2.asInstanceOf[Double])) {
    +              return false
    +            }
    +          case _ => if (o1 != o2) {
    +            return false
    +          }
    +        }
    +      }
    +      i += 1
    +    }
    +    true
    +  }
    +
    +  override def hashCode: Int = {
    +    var result: Int = 37
    +    var i = 0
    +    val len = numElements()
    +    while (i < len) {
    --- End diff --
    
    This could be very expensive for large arrays because it scans all 
elements, which is unnecessary to generate the hashCode.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to