Skip to content

Commit 6f64746

Browse files
committed
Move equalsIgnoreNullability method into DataType.
1 parent 5a90e02 commit 6f64746

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,27 @@ object DataType {
171171
case _ =>
172172
}
173173
}
174+
175+
/**
176+
* Compares two types, ignoring nullability of ArrayType, MapType, StructType.
177+
*/
178+
def equalsIgnoreNullability(left: DataType, right: DataType): Boolean = {
179+
(left, right) match {
180+
case (ArrayType(leftElementType, _), ArrayType(rightElementType, _)) =>
181+
equalsIgnoreNullability(leftElementType, rightElementType)
182+
case (MapType(leftKeyType, leftValueType, _), MapType(rightKeyType, rightValueType, _)) =>
183+
equalsIgnoreNullability(leftKeyType, rightKeyType) &&
184+
equalsIgnoreNullability(leftValueType, rightValueType)
185+
case (StructType(leftFields), StructType(rightFields)) =>
186+
leftFields.size == rightFields.size &&
187+
leftFields.zip(rightFields)
188+
.forall{
189+
case (left, right) =>
190+
left.name == right.name && equalsIgnoreNullability(left.dataType, right.dataType)
191+
}
192+
case (left, right) => left == right
193+
}
194+
}
174195
}
175196

176197
abstract class DataType {

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private[hive] class HiveMetastoreCatalog(hive: HiveContext) extends Catalog with
284284
p
285285
} else if (childOutputDataTypes.size == tableOutputDataTypes.size &&
286286
childOutputDataTypes.zip(tableOutputDataTypes)
287-
.forall(InsertIntoHiveType.equalsIgnoreNullability)) {
287+
.forall { case (left, right) => DataType.equalsIgnoreNullability(left, right) }) {
288288
// If both types ignoring nullability of ArrayType, MapType, StructType are the same,
289289
// use InsertIntoHiveTable instead of InsertIntoTable.
290290
InsertIntoHiveTable(p.table, p.partition, p.child, p.overwrite)
@@ -335,28 +335,7 @@ private[hive] case class InsertIntoHiveTable(
335335

336336
override lazy val resolved = childrenResolved && child.output.zip(table.output).forall {
337337
case (childAttr, tableAttr) =>
338-
InsertIntoHiveType.equalsIgnoreNullability(childAttr.dataType, tableAttr.dataType)
339-
}
340-
}
341-
342-
private[hive] object InsertIntoHiveType {
343-
344-
/**
345-
* Compares two types, ignoring nullability of ArrayType, MapType, StructType.
346-
*/
347-
def equalsIgnoreNullability(dataTypePair: (DataType, DataType)): Boolean = {
348-
dataTypePair match {
349-
case (ArrayType(leftElementType, _), ArrayType(rightElementType, _)) =>
350-
equalsIgnoreNullability(leftElementType, rightElementType)
351-
case (MapType(leftKeyType, leftValueType, _), MapType(rightKeyType, rightValueType, _)) =>
352-
equalsIgnoreNullability(leftKeyType, rightKeyType) &&
353-
equalsIgnoreNullability(leftValueType, rightValueType)
354-
case (StructType(leftFields), StructType(rightFields)) =>
355-
leftFields.size == rightFields.size &&
356-
leftFields.map(_.dataType).zip(rightFields.map(_.dataType))
357-
.forall(equalsIgnoreNullability)
358-
case (left, right) => left == right
359-
}
338+
DataType.equalsIgnoreNullability(childAttr.dataType, tableAttr.dataType)
360339
}
361340
}
362341

0 commit comments

Comments
 (0)