File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments