Skip to content

Commit

Permalink
add uts
Browse files Browse the repository at this point in the history
  • Loading branch information
yaooqinn committed Nov 13, 2019
1 parent 0814fc4 commit 3b1667e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ object IntervalUtils {
i += 1
fractionScale = (NANOS_PER_SECOND / 10).toInt
state = VALUE_FRACTIONAL_PART
case _ => exceptionWithState( s"Unrecognized sign '$nextWord'")
case _ => exceptionWithState( s"unrecognized sign '$nextWord'")
}
case TRIM_BEFORE_VALUE => trimToNextState(b, VALUE)
case VALUE =>
Expand All @@ -456,8 +456,7 @@ object IntervalUtils {
try {
currentValue = Math.addExact(Math.multiplyExact(10, currentValue), (b - '0'))
} catch {
case _: ArithmeticException =>
exceptionWithState(s"'$currentValue$nextWord' out of range")
case e: ArithmeticException => exceptionWithState(e.getMessage, e)
}
case ' ' => state = TRIM_BEFORE_UNIT
case '.' =>
Expand All @@ -474,7 +473,9 @@ object IntervalUtils {
case ' ' =>
fraction /= NANOS_PER_MICROS.toInt
state = TRIM_BEFORE_UNIT
case _ => exceptionWithState(s"invalid value fractional part '$fraction$nextWord'")
case _ if '0' <= b && b <= '9' =>
exceptionWithState(s"invalid value fractional part '$fraction$nextWord' out of range")
case _ => exceptionWithState(s"invalid value fractional part '$nextWord'")
}
i += 1
case TRIM_BEFORE_UNIT => trimToNextState(b, UNIT_BEGIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ class IntervalUtilsSuite extends SparkFunSuite {
// Only the seconds units can have the fractional part
checkFromInvalidString("1.5 days", "'days' with fractional part is unsupported")
checkFromInvalidString("1. hour", "'hour' with fractional part is unsupported")
checkFromInvalidString("1 hourX", "invalid unit suffix")
checkFromInvalidString("~1 hour", "unrecognized sign")
checkFromInvalidString("1 Mour", "invalid unit 'mour'")
checkFromInvalidString("1 aour", "invalid unit 'aour'")
checkFromInvalidString("1a1 hour", "invalid value 'a1'")
checkFromInvalidString("1.1a1 seconds", "invalid value fractional part 'a1'")
checkFromInvalidString("2234567890 days", "integer overflow")

}

test("string to interval: seconds with fractional part") {
Expand All @@ -106,7 +114,8 @@ class IntervalUtilsSuite extends SparkFunSuite {
checkFromString("-1.5 seconds", new CalendarInterval(0, 0, -1500000))
// truncate nanoseconds to microseconds
checkFromString("0.999999999 seconds", new CalendarInterval(0, 0, 999999))
checkFromInvalidString("0.123456789123 seconds", "invalid value fractional part '123456789123'")
checkFromString(".999999999 seconds", new CalendarInterval(0, 0, 999999))
checkFromInvalidString("0.123456789123 seconds", "'123456789123' out of range")
}

test("from year-month string") {
Expand Down

0 comments on commit 3b1667e

Please sign in to comment.