Skip to content

Commit ec3d552

Browse files
committed
[SPARK-17108][SQL]: Fix BIGINT and INT comparison failure in spark sql
1 parent b512f04 commit ec3d552

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/types/DataType.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ abstract class DataType extends AbstractDataType {
7878
private[spark] def sameType(other: DataType): Boolean =
7979
DataType.equalsIgnoreNullability(this, other)
8080

81+
/**
82+
* Check if two integers are compatible. Returns true if `right` can be converted to `left`.
83+
*/
84+
private[spark] def isCompatibleIntegralType(left: DataType, right: DataType): Boolean = {
85+
(left, right) match {
86+
case (l, r) => l.isInstanceOf[IntegralType] && r.isInstanceOf[IntegralType] &&
87+
l.defaultSize >= r.defaultSize
88+
case _ => false
89+
}
90+
}
91+
8192
/**
8293
* Returns the same data type but set all nullability fields are true
8394
* (`StructField.nullable`, `ArrayType.containsNull`, and `MapType.valueContainsNull`).
@@ -91,7 +102,8 @@ abstract class DataType extends AbstractDataType {
91102

92103
override private[sql] def defaultConcreteType: DataType = this
93104

94-
override private[sql] def acceptsType(other: DataType): Boolean = sameType(other)
105+
override private[sql] def acceptsType(other: DataType): Boolean = sameType(other) ||
106+
isCompatibleIntegralType(this, other)
95107
}
96108

97109

0 commit comments

Comments
 (0)