-
Notifications
You must be signed in to change notification settings - Fork 28.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-8944][SQL] Support casting between IntervalType and StringType #7355
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,4 +56,34 @@ public void toStringTest() { | |
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() { | ||
String s; | ||
Interval i; | ||
|
||
s = "interval 2 weeks -6 minute"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a unit test where there is only # month specified, but nothing else. and one for only day, week, ... all the units. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also add a unit test where the string is just "int", and one for empty string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to test all the combinations of units? |
||
i = new Interval(0, 2 * MICROS_PER_WEEK - 6 * MICROS_PER_MINUTE); | ||
assertEquals(Interval.fromString(s), i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to test all the combinations of units? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably not - but we should definitely test each unit at least once. |
||
|
||
s = "interval -5 years 23 month"; | ||
i = new Interval(-5 * 12 + 23, 0); | ||
assertEquals(Interval.fromString(s), i); | ||
|
||
s = "interval 3month 1 hour"; | ||
i = null; | ||
assertEquals(Interval.fromString(s), i); | ||
|
||
s = "interval 3 moth 1 hour"; | ||
i = null; | ||
assertEquals(Interval.fromString(s), i); | ||
|
||
s = "interval"; | ||
i = null; | ||
assertEquals(Interval.fromString(s), i); | ||
|
||
s = null; | ||
i = null; | ||
assertEquals(Interval.fromString(s), i); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add more comments explaining the regex, since most people would need to look up documentation on the regex.