Skip to content

Commit ba880d8

Browse files
committed
binary operator should not consider nullability when comparing input types
1 parent eff4aed commit ba880d8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ abstract class BinaryOperator extends BinaryExpression with ExpectsInputTypes {
511511

512512
override def checkInputDataTypes(): TypeCheckResult = {
513513
// First check whether left and right have the same type, then check if the type is acceptable.
514-
if (left.dataType != right.dataType) {
514+
if (!left.dataType.sameType(right.dataType)) {
515515
TypeCheckResult.TypeCheckFailure(s"differing types in '$sql' " +
516516
s"(${left.dataType.simpleString} and ${right.dataType.simpleString}).")
517517
} else if (!inputType.acceptsType(left.dataType)) {

sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,4 +1631,13 @@ class DataFrameSuite extends QueryTest with SharedSQLContext {
16311631
dates.except(widenTypedRows).collect()
16321632
dates.intersect(widenTypedRows).collect()
16331633
}
1634+
1635+
test("SPARK-18070 binary operator should not consider nullability when comparing input types") {
1636+
val rows = Seq(Row(Seq(1), Seq(1)))
1637+
val schema = new StructType()
1638+
.add("array1", ArrayType(IntegerType))
1639+
.add("array2", ArrayType(IntegerType, containsNull = false))
1640+
val df = spark.createDataFrame(spark.sparkContext.makeRDD(rows), schema)
1641+
assert(df.filter($"array1" === $"array2").count() == 1)
1642+
}
16341643
}

0 commit comments

Comments
 (0)