Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/5418#discussion_r28010358
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala
---
@@ -45,8 +45,17 @@ object HiveTypeCoercion {
if (t1 == DecimalType.Unlimited || t2 == DecimalType.Unlimited) {
Some(DecimalType.Unlimited)
} else {
- None
+ val (d1, d2) = (t1.asInstanceOf[DecimalType],
t2.asInstanceOf[DecimalType])
+ val (p1, s1) = (d1.precision, d1.scale)
+ val (p2, s2) = (d2.precision, d2.scale)
+ Some(DecimalType((math.max(p1-s1, p2-s2) + math.max(s1, s2)),
math.max(s1, s2)))
}
+ } else if (t1.isInstanceOf[DecimalType] &&
t2.isInstanceOf[FloatType] ||
+ t2.isInstanceOf[DecimalType] && t1.isInstanceOf[FloatType]) {
+ Some(FloatType)
+ } else if (t1.isInstanceOf[DecimalType] &&
t2.isInstanceOf[DoubleType] ||
+ t2.isInstanceOf[DecimalType] && t1.isInstanceOf[DoubleType]) {
+ Some(DoubleType)
--- End diff --
Why are these the correct types? You are losing precision. It would be
good to look at the rules that other systems use as was done with the other
cases.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]