Skip to content
Snippets Groups Projects
Commit 0158ff77 authored by gatorsmile's avatar gatorsmile Committed by Michael Armbrust
Browse files

[SPARK-8658][SQL][FOLLOW-UP] AttributeReference's equals method compares all the members

Based on the comment of cloud-fan in https://github.com/apache/spark/pull/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.
parent 7b1407c7
No related branches found
No related tags found
No related merge requests found
...@@ -212,9 +212,12 @@ case class AttributeReference( ...@@ -212,9 +212,12 @@ case class AttributeReference(
override def hashCode: Int = { override def hashCode: Int = {
// See http://stackoverflow.com/questions/113511/hash-code-implementation // See http://stackoverflow.com/questions/113511/hash-code-implementation
var h = 17 var h = 17
h = h * 37 + exprId.hashCode() h = h * 37 + name.hashCode()
h = h * 37 + dataType.hashCode() h = h * 37 + dataType.hashCode()
h = h * 37 + nullable.hashCode()
h = h * 37 + metadata.hashCode() h = h * 37 + metadata.hashCode()
h = h * 37 + exprId.hashCode()
h = h * 37 + qualifiers.hashCode()
h h
} }
......
...@@ -25,14 +25,18 @@ class SubexpressionEliminationSuite extends SparkFunSuite { ...@@ -25,14 +25,18 @@ class SubexpressionEliminationSuite extends SparkFunSuite {
val a: AttributeReference = AttributeReference("name", IntegerType)() val a: AttributeReference = AttributeReference("name", IntegerType)()
val b1 = a.withName("name2").withExprId(id) val b1 = a.withName("name2").withExprId(id)
val b2 = a.withExprId(id) val b2 = a.withExprId(id)
val b3 = a.withQualifiers("qualifierName" :: Nil)
assert(b1 != b2) assert(b1 != b2)
assert(a != b1) assert(a != b1)
assert(b1.semanticEquals(b2)) assert(b1.semanticEquals(b2))
assert(!b1.semanticEquals(a)) assert(!b1.semanticEquals(a))
assert(a.hashCode != b1.hashCode) assert(a.hashCode != b1.hashCode)
assert(b1.hashCode == b2.hashCode) assert(b1.hashCode != b2.hashCode)
assert(b1.semanticHash() == b2.semanticHash()) assert(b1.semanticHash() == b2.semanticHash())
assert(a != b3)
assert(a.hashCode != b3.hashCode)
assert(a.semanticEquals(b3))
} }
test("Expression Equivalence - basic") { test("Expression Equivalence - basic") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment