Skip to content

Commit

Permalink
[SPARK-26706][SQL][FOLLOWUP] Fix illegalNumericPrecedence for ByteType
Browse files Browse the repository at this point in the history
Removed automatically generated tests in

```
test("canSafeCast and mayTruncate must be consistent for numeric types")
```

since `canSafeCast` doesn't exit in 2.3 branch. We have enough test coverages
in the explict casting tests.

Authored-by: DB Tsai <d_tsai@apple.com>
Signed-off-by: DB Tsai <d_tsai@apple.com>
  • Loading branch information
dbtsai committed Jan 24, 2019
1 parent de3b5c4 commit 23e35d4
Showing 1 changed file with 0 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -934,28 +934,4 @@ class CastSuite extends SparkFunSuite with ExpressionEvalHelper {
assert(Cast.mayTruncate(DoubleType, ByteType))
assert(Cast.mayTruncate(DecimalType.IntDecimal, ByteType))
}

test("canSafeCast and mayTruncate must be consistent for numeric types") {
import DataTypeTestUtils._

def isCastSafe(from: NumericType, to: NumericType): Boolean = (from, to) match {
case (_, dt: DecimalType) => dt.isWiderThan(from)
case (dt: DecimalType, _) => dt.isTighterThan(to)
case _ => numericPrecedence.indexOf(from) <= numericPrecedence.indexOf(to)
}

numericTypes.foreach { from =>
val (safeTargetTypes, unsafeTargetTypes) = numericTypes.partition(to => isCastSafe(from, to))

safeTargetTypes.foreach { to =>
assert(Cast.canSafeCast(from, to), s"It should be possible to safely cast $from to $to")
assert(!Cast.mayTruncate(from, to), s"No truncation is expected when casting $from to $to")
}

unsafeTargetTypes.foreach { to =>
assert(!Cast.canSafeCast(from, to), s"It shouldn't be possible to safely cast $from to $to")
assert(Cast.mayTruncate(from, to), s"Truncation is expected when casting $from to $to")
}
}
}
}

0 comments on commit 23e35d4

Please sign in to comment.