Skip to content

Commit a5f355f

Browse files
committed
fix test
1 parent 87417d9 commit a5f355f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit
466466
// IntervalConverter
467467
private[this] def castToInterval(from: DataType): Any => Any = from match {
468468
case StringType =>
469-
buildCast[UTF8String](_, s => IntervalUtils.fromString(s.toString))
469+
buildCast[UTF8String](_, s => IntervalUtils.safeFromString(s.toString))
470470
}
471471

472472
// LongConverter
@@ -1215,7 +1215,7 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit
12151215
case StringType =>
12161216
val util = IntervalUtils.getClass.getCanonicalName.stripSuffix("$")
12171217
(c, evPrim, evNull) =>
1218-
code"""$evPrim = $util.fromString($c.toString());
1218+
code"""$evPrim = $util.safeFromString($c.toString());
12191219
if(${evPrim} == null) {
12201220
${evNull} = true;
12211221
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,12 @@ object IntervalUtils {
103103
throw ex
104104
}
105105
}
106+
107+
def safeFromString(str: String): CalendarInterval = {
108+
try {
109+
fromString(str)
110+
} catch {
111+
case _: IllegalArgumentException => null
112+
}
113+
}
106114
}

0 commit comments

Comments
 (0)