Github user HyukjinKwon commented on the issue:
https://github.com/apache/spark/pull/16777
@gatorsmile, Can we make this merged and then add test cases for them
separately? It seems the results are the same. I ran two tests as below:
```scala
val integralTypes =
IndexedSeq(
ByteType,
ShortType,
IntegerType,
LongType)
val decimals = (-38 to 38).flatMap { p =>
(-38 to 38).flatMap(s => allCatch opt DecimalType(p, s))
}
assert(decimals.nonEmpty)
integralTypes.foreach { it =>
test(s"$it test") {
decimals.foreach { d =>
// From TypeCoercion.findWiderTypeForTwo
val maybeType1 = (d, it) match {
case (d: DecimalType, t: IntegralType) =>
Some(DecimalPrecision.widerDecimalType(DecimalType.forType(t), d))
case _ => None
}
// From TypeCoercion.findTightestCommonType
val maybeType2 = (d, it) match {
case (t1: DecimalType, t2: IntegralType) if t1.isWiderThan(t2) =>
Some(t1)
case _ => None
}
if (maybeType2.isDefined) {
val t1 = maybeType1.get
val t2 = maybeType2.get
assert(t1 == t2)
}
}
}
}
```
```scala
val integralTypes =
IndexedSeq(
ByteType,
ShortType,
IntegerType,
LongType)
val decimals = (-38 to 38).flatMap { p =>
(-38 to 38).flatMap(s => allCatch opt DecimalType(p, s))
}
assert(decimals.nonEmpty)
integralTypes.foreach { it =>
test(s"$it test") {
val widenDecimals = decimals.flatMap { d =>
// From TypeCoercion.findWiderTypeForTwo
(d, it) match {
case (d: DecimalType, t: IntegralType) =>
Some(DecimalPrecision.widerDecimalType(DecimalType.forType(t), d))
case _ => None
}
}.toSet
val tightDecimals = decimals.flatMap { d =>
// From TypeCoercion.findTightestCommonType
(d, it) match {
case (t1: DecimalType, t2: IntegralType) if t1.isWiderThan(t2) =>
Some(t1)
case _ => None
}
}.toSet
assert(widenDecimals.nonEmpty)
assert(tightDecimals.nonEmpty)
assert(tightDecimals.subsetOf(widenDecimals))
}
}
```
---
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]