Skip to content

Commit

Permalink
[SPARK-8658][SQL][FOLLOW-UP] AttributeReference's equals method compa…
Browse files Browse the repository at this point in the history
…res all the members

Based on the comment of cloud-fan in #9216, update the AttributeReference's hashCode function by including the hashCode of the other attributes including name, nullable and qualifiers.

Here, I am not 100% sure if we should include name in the hashCode calculation, since the original hashCode calculation does not include it.

marmbrus cloud-fan Please review if the changes are good.

Author: gatorsmile <gatorsmile@gmail.com>

Closes #9761 from gatorsmile/hashCodeNamedExpression.

(cherry picked from commit 0158ff7)
Signed-off-by: Michael Armbrust <michael@databricks.com>
  • Loading branch information
gatorsmile authored and marmbrus committed Nov 17, 2015
1 parent 167ea61 commit 933f025
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Expand Up @@ -212,9 +212,12 @@ case class AttributeReference(
override def hashCode: Int = {
// See http://stackoverflow.com/questions/113511/hash-code-implementation
var h = 17
h = h * 37 + exprId.hashCode()
h = h * 37 + name.hashCode()
h = h * 37 + dataType.hashCode()
h = h * 37 + nullable.hashCode()
h = h * 37 + metadata.hashCode()
h = h * 37 + exprId.hashCode()
h = h * 37 + qualifiers.hashCode()
h
}

Expand Down
Expand Up @@ -25,14 +25,18 @@ class SubexpressionEliminationSuite extends SparkFunSuite {
val a: AttributeReference = AttributeReference("name", IntegerType)()
val b1 = a.withName("name2").withExprId(id)
val b2 = a.withExprId(id)
val b3 = a.withQualifiers("qualifierName" :: Nil)

assert(b1 != b2)
assert(a != b1)
assert(b1.semanticEquals(b2))
assert(!b1.semanticEquals(a))
assert(a.hashCode != b1.hashCode)
assert(b1.hashCode == b2.hashCode)
assert(b1.hashCode != b2.hashCode)
assert(b1.semanticHash() == b2.semanticHash())
assert(a != b3)
assert(a.hashCode != b3.hashCode)
assert(a.semanticEquals(b3))
}

test("Expression Equivalence - basic") {
Expand Down

0 comments on commit 933f025

Please sign in to comment.