File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
sql/catalyst/src/main/scala/org/apache/spark/sql/types Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments