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 @@ -52,10 +52,10 @@ object TypeCoercion {
DecimalPrecision ::
BooleanEquality ::
StringToIntegralCasts ::
Division ::
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be sure: are you moving the Division rule above the FunctionArgumentConversion rule in order to pass correct double arguments to functions? If so, could you add a test for this?

FunctionArgumentConversion ::
CaseWhenCoercion ::
IfCoercion ::
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of switching orders, can we spend some more time to make these rules non-order-sensitive? thanks

Division ::
PropagateTypes ::
ImplicitTypeCasts ::
DateTimeOperations ::
Expand Down
15 changes: 15 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 @@ -2843,4 +2843,19 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
sql(s"SELECT '$literal' AS DUMMY"),
Row(s"$expected") :: Nil)
}

test("SPARK-15776: Type coercionn incorrect") {
Seq(
(1, 11),
(3, 25),
(5, 37)
).toDF("k", "v").createOrReplaceTempView("tc")

// If Division is after FunctionArgumentConversion then for the first query it's output
// data type is bigint and second is double. But actually both these two query it's
// output data type should be double.
checkAnswer(
sql("SELECT SUM(CASE WHEN k in (3, 5) THEN v / 10 ELSE 0 END) FROM tc"),
sql("SELECT SUM(CASE WHEN k in (3, 5) THEN v / 10.0 ELSE 0 END) FROM tc"))
}
}