diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala index deaa49bf423b..0759234ffb8e 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala @@ -511,9 +511,18 @@ object TypeCoercion { i } - case i @ In(a, b) if b.exists(_.dataType != a.dataType) => - findWiderCommonType(i.children.map(_.dataType)) match { - case Some(finalDataType) => i.withNewChildren(i.children.map(Cast(_, finalDataType))) + case i @ In(value, list) if list.exists(_.dataType != value.dataType) => + findWiderCommonType(list.map(_.dataType)) match { + case Some(listWiderCommonType) => + findCommonTypeForBinaryComparison(value.dataType, listWiderCommonType, conf).map { + finalDataType => i.withNewChildren(i.children.map(Cast(_, finalDataType))) + }.getOrElse { + findWiderCommonType(Seq(value.dataType, listWiderCommonType)) match { + case Some(finalDataType) => + i.withNewChildren(i.children.map(Cast(_, finalDataType))) + case None => i + } + } case None => i } }