Skip to content

Commit

Permalink
Added a few more test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
nongli committed Nov 6, 2015
1 parent e65def9 commit 3a10f7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,24 @@
package org.apache.spark.sql.catalyst.expressions

import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.types.IntegerType

class SubexpressionEliminationSuite extends SparkFunSuite {
test("Semantic equals and hash") {
val id = ExprId(1)
val a: AttributeReference = AttributeReference("name", IntegerType)()
val b1 = a.withName("name2").withExprId(id)
val b2 = a.withExprId(id)

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.semanticHash() == b2.semanticHash())
}

test("Expression Equivalence - basic") {
val equivalence = new EquivalentExpressions
assert(equivalence.getAllEquivalentExprs.isEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2036,6 +2036,9 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
verifyCallCount(
df.selectExpr("testUdf(a + 1) + testUdf(a + 1)", "testUdf(a + 1)"), Row(4, 2), 1)

verifyCallCount(
df.selectExpr("testUdf(a + 1) + testUdf(1 + b)", "testUdf(a + 1)"), Row(4, 2), 2)

// Would be nice if semantic equals for `+` understood commutative
verifyCallCount(
df.selectExpr("testUdf(a + 1) + testUdf(1 + a)", "testUdf(a + 1)"), Row(4, 2), 2)
Expand Down

0 comments on commit 3a10f7d

Please sign in to comment.