aboutsummaryrefslogtreecommitdiff
path: root/unsafe/src/test
diff options
context:
space:
mode:
authorWenchen Fan <cloud0fan@outlook.com>2015-07-13 00:49:39 -0700
committerReynold Xin <rxin@databricks.com>2015-07-13 00:49:39 -0700
commit6b89943834a8d9d5d0ecfd97efcc10056d08532a (patch)
tree7383eb5ef241c044e01393cccedc8fdf5fb94e48 /unsafe/src/test
parent92540d22e45f9300f413f520a1770e9f36cfa833 (diff)
downloadspark-6b89943834a8d9d5d0ecfd97efcc10056d08532a.tar.gz
spark-6b89943834a8d9d5d0ecfd97efcc10056d08532a.tar.bz2
spark-6b89943834a8d9d5d0ecfd97efcc10056d08532a.zip
[SPARK-8944][SQL] Support casting between IntervalType and StringType
Author: Wenchen Fan <cloud0fan@outlook.com> Closes #7355 from cloud-fan/fromString and squashes the following commits: 3bbb9d6 [Wenchen Fan] fix code gen 7dab957 [Wenchen Fan] naming fix 0fbbe19 [Wenchen Fan] address comments ac1f3d1 [Wenchen Fan] Support casting between IntervalType and StringType
Diffstat (limited to 'unsafe/src/test')
-rw-r--r--unsafe/src/test/java/org/apache/spark/unsafe/types/IntervalSuite.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/unsafe/src/test/java/org/apache/spark/unsafe/types/IntervalSuite.java b/unsafe/src/test/java/org/apache/spark/unsafe/types/IntervalSuite.java
index 0f4f38b2b0..44a949a371 100644
--- a/unsafe/src/test/java/org/apache/spark/unsafe/types/IntervalSuite.java
+++ b/unsafe/src/test/java/org/apache/spark/unsafe/types/IntervalSuite.java
@@ -56,4 +56,50 @@ public class IntervalSuite {
i = new Interval(34, 3 * MICROS_PER_WEEK + 13 * MICROS_PER_HOUR + 123);
assertEquals(i.toString(), "interval 2 years 10 months 3 weeks 13 hours 123 microseconds");
}
+
+ @Test
+ public void fromStringTest() {
+ testSingleUnit("year", 3, 36, 0);
+ testSingleUnit("month", 3, 3, 0);
+ testSingleUnit("week", 3, 0, 3 * MICROS_PER_WEEK);
+ testSingleUnit("day", 3, 0, 3 * MICROS_PER_DAY);
+ testSingleUnit("hour", 3, 0, 3 * MICROS_PER_HOUR);
+ testSingleUnit("minute", 3, 0, 3 * MICROS_PER_MINUTE);
+ testSingleUnit("second", 3, 0, 3 * MICROS_PER_SECOND);
+ testSingleUnit("millisecond", 3, 0, 3 * MICROS_PER_MILLI);
+ testSingleUnit("microsecond", 3, 0, 3);
+
+ String input;
+
+ input = "interval -5 years 23 month";
+ Interval result = new Interval(-5 * 12 + 23, 0);
+ assertEquals(Interval.fromString(input), result);
+
+ // Error cases
+ input = "interval 3month 1 hour";
+ assertEquals(Interval.fromString(input), null);
+
+ input = "interval 3 moth 1 hour";
+ assertEquals(Interval.fromString(input), null);
+
+ input = "interval";
+ assertEquals(Interval.fromString(input), null);
+
+ input = "int";
+ assertEquals(Interval.fromString(input), null);
+
+ input = "";
+ assertEquals(Interval.fromString(input), null);
+
+ input = null;
+ assertEquals(Interval.fromString(input), null);
+ }
+
+ private void testSingleUnit(String unit, int number, int months, long microseconds) {
+ String input1 = "interval " + number + " " + unit;
+ String input2 = "interval " + number + " " + unit + "s";
+ Interval result = new Interval(months, microseconds);
+ assertEquals(Interval.fromString(input1), result);
+ assertEquals(Interval.fromString(input2), result);
+ }
}