Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use trim instead of modifying regex.
  • Loading branch information
viirya committed Jul 14, 2015
commit 9eb6831bfc49bf9c2389728dc70fd3153402ccde
10 changes: 5 additions & 5 deletions unsafe/src/main/java/org/apache/spark/unsafe/types/Interval.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ public final class Interval implements Serializable {
* Finally is the unit name, ends with an optional "s".
*/
private static String unitRegex(String unit) {
return "(?:\\s+(-?\\d+)\\s+" + unit + "s?\\s*)?";
return "(?:\\s+(-?\\d+)\\s+" + unit + "s?)?";
}

private static Pattern p = Pattern.compile("\\s*interval" + unitRegex("year") +
unitRegex("month") + unitRegex("week") + unitRegex("day") + unitRegex("hour") +
unitRegex("minute") + unitRegex("second") + unitRegex("millisecond") +
unitRegex("microsecond"));
private static Pattern p = Pattern.compile("interval" + unitRegex("year") + unitRegex("month") +
unitRegex("week") + unitRegex("day") + unitRegex("hour") + unitRegex("minute") +
unitRegex("second") + unitRegex("millisecond") + unitRegex("microsecond"));

private static long toLong(String s) {
if (s == null) {
Expand All @@ -63,6 +62,7 @@ public static Interval fromString(String s) {
if (s == null) {
return null;
}
s = s.trim();
Matcher m = p.matcher(s);
if (!m.matches() || s.equals("interval")) {
return null;
Expand Down