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 @@ -473,8 +473,7 @@ object TypeCoercion {
val rhs = sub.output

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

// The number of columns/expressions must match between LHS and RHS of an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CREATE TEMPORARY VIEW t4 AS SELECT * FROM VALUES
AS t1(t4a, t4b, t4c);

CREATE TEMPORARY VIEW t5 AS SELECT * FROM VALUES
(CAST(1 AS DECIMAL(18, 0)), CAST(2 AS STRING), CAST(3 AS BIGINT))
(CAST('2011-01-01 01:01:01' AS TIMESTAMP), CAST(2 AS STRING), CAST(3 AS BIGINT))
AS t1(t5a, t5b, t5c);

-- TC 01.01
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct<>

-- !query 4
CREATE TEMPORARY VIEW t5 AS SELECT * FROM VALUES
(CAST(1 AS DECIMAL(18, 0)), CAST(2 AS STRING), CAST(3 AS BIGINT))
(CAST('2011-01-01 01:01:01' AS TIMESTAMP), CAST(2 AS STRING), CAST(3 AS BIGINT))
AS t1(t5a, t5b, t5c)
-- !query 4 schema
struct<>
Expand Down Expand Up @@ -139,8 +139,8 @@ cannot resolve '(named_struct('t4a', t4.`t4a`, 't4b', t4.`t4b`, 't4c', t4.`t4c`)
The data type of one or more elements in the left hand side of an IN subquery
is not compatible with the data type of the output of the subquery
Mismatched columns:
[(t4.`t4a`:double, t5.`t5a`:decimal(18,0)), (t4.`t4c`:string, t5.`t5c`:bigint)]
[(t4.`t4a`:double, t5.`t5a`:timestamp), (t4.`t4c`:string, t5.`t5c`:bigint)]
Left side:
[double, string, string].
Right side:
[decimal(18,0), string, bigint].;
[timestamp, string, bigint].;
21 changes: 21 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3313,6 +3313,27 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession {
cubeDF.join(cubeDF, "nums"),
Row(1, 0, 0) :: Row(2, 0, 0) :: Row(3, 0, 0) :: Nil)
}

test("SPARK-29860: Fix dataType mismatch issue for InSubquery") {
withTempView("ta", "tb", "tc", "td", "te", "tf") {
sql("CREATE TEMPORARY VIEW ta AS SELECT * FROM VALUES(CAST(1 AS DECIMAL(8, 0))) AS ta(id)")
sql("CREATE TEMPORARY VIEW tb AS SELECT * FROM VALUES(CAST(1 AS DECIMAL(7, 2))) AS tb(id)")
sql("CREATE TEMPORARY VIEW tc AS SELECT * FROM VALUES(CAST(1 AS DOUBLE)) AS tc(id)")
sql("CREATE TEMPORARY VIEW td AS SELECT * FROM VALUES(CAST(1 AS FLOAT)) AS td(id)")
sql("CREATE TEMPORARY VIEW te AS SELECT * FROM VALUES(CAST(1 AS BIGINT)) AS te(id)")
sql("CREATE TEMPORARY VIEW tf AS SELECT * FROM VALUES(CAST(1 AS DECIMAL(38, 38))) AS tf(id)")
val df1 = sql("SELECT id FROM ta WHERE id IN (SELECT id FROM tb)")
checkAnswer(df1, Row(new java.math.BigDecimal(1)))
val df2 = sql("SELECT id FROM ta WHERE id IN (SELECT id FROM tc)")
checkAnswer(df2, Row(new java.math.BigDecimal(1)))
val df3 = sql("SELECT id FROM ta WHERE id IN (SELECT id FROM td)")
checkAnswer(df3, Row(new java.math.BigDecimal(1)))
val df4 = sql("SELECT id FROM ta WHERE id IN (SELECT id FROM te)")
checkAnswer(df4, Row(new java.math.BigDecimal(1)))
val df5 = sql("SELECT id FROM ta WHERE id IN (SELECT id FROM tf)")
checkAnswer(df5, Array.empty[Row])
}
}
}

case class Foo(bar: Option[String])