@@ -24,7 +24,7 @@ import org.apache.spark.unsafe.types.CalendarInterval._
2424
2525class IntervalUtilsSuite extends SparkFunSuite {
2626
27- test(" fromString" ) {
27+ test(" fromString: basic " ) {
2828 testSingleUnit(" YEAR" , 3 , 36 , 0 )
2929 testSingleUnit(" Month" , 3 , 3 , 0 )
3030 testSingleUnit(" Week" , 3 , 0 , 3 * MICROS_PER_WEEK )
@@ -60,6 +60,23 @@ class IntervalUtilsSuite extends SparkFunSuite {
6060 }
6161 }
6262
63+ test(" fromString: random order field" ) {
64+ val input = " 1 day 1 year"
65+ val result = new CalendarInterval (12 , MICROS_PER_DAY )
66+ assert(fromString(input) == result)
67+ }
68+
69+ test(" fromString: duplicated fields" ) {
70+ val input = " 1 day 1 day"
71+ val result = new CalendarInterval (0 , 2 * MICROS_PER_DAY )
72+ assert(fromString(input) == result)
73+ }
74+
75+ test(" fromString: value with +/-" ) {
76+ val input = " +1 year -1 day"
77+ val result = new CalendarInterval (12 , - MICROS_PER_DAY )
78+ assert(fromString(input) == result)
79+ }
6380
6481 private def testSingleUnit (unit : String , number : Int , months : Int , microseconds : Long ): Unit = {
6582 for (prefix <- Seq (" interval " , " " )) {
0 commit comments