Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ object TypeCoercion {

val commonTypes = lhs.zip(rhs).flatMap { case (l, r) =>
findCommonTypeForBinaryComparison(l.dataType, r.dataType, conf)
.orElse(findTightestCommonType(l.dataType, r.dataType))
.orElse(findWiderTypeForTwo(l.dataType, r.dataType))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we make this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be coherent with what is done when there are literals instead of a subquery.

}

// The number of columns/expressions must match between LHS and RHS of an
Expand All @@ -493,7 +493,10 @@ object TypeCoercion {
}

case i @ In(a, b) if b.exists(_.dataType != a.dataType) =>
findWiderCommonType(i.children.map(_.dataType)) match {
findWiderCommonType(b.map(_.dataType)).flatMap { listDataType =>
findCommonTypeForBinaryComparison(listDataType, a.dataType, conf)
.orElse(findWiderTypeForTwo(listDataType, a.dataType))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason we need to call findWiderTypeForTwo ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before this PR, we were calling always findWiderCommonType and this was applied to all the elements of the list and the value. Here, I am calling findWiderTypeForTwo if findCommonTypeForBinaryComparison fails to have the same previous behavior in those cases.

} match {
case Some(finalDataType) => i.withNewChildren(i.children.map(Cast(_, finalDataType)))
case None => i
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,14 @@ class DataFrameSuite extends QueryTest with SharedSparkSession {
assert(mean.collect().toSet === Set(Row("0.0345678900000000000000000000000000000")))
}

test("SPARK-22398: type coercion for IN predicates should be coherent") {
val df = spark.range(2)
val inWithLiterals = df.where("id in ('01')")
val inWithSubquery = df.where("id in (select '01' from (select 1))")
assert(inWithLiterals.count() == inWithSubquery.count(),
"IN behavior is not the same with list of Literals and with a subquery")
}

test("SPARK-22520: support code generation for large CaseWhen") {
val N = 30
var expr1 = when($"id" === lit(0), 0)
Expand Down