Skip to content

Commit 0cb4edc

Browse files
committed
Fix
1 parent 2f845c3 commit 0cb4edc

File tree

1 file changed

+6
-5
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,16 +1151,17 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit
11511151
from match {
11521152
case StringType =>
11531153
(c, evPrim, evNull) =>
1154+
val handleException = if (ansiEnabled) {
1155+
s"""throw new NumberFormatException("invalid input syntax for type numeric: $c");"""
1156+
} else {
1157+
s"$evNull =true;"
1158+
}
11541159
code"""
11551160
try {
11561161
Decimal $tmp = Decimal.apply(new java.math.BigDecimal($c.toString().trim()));
11571162
${changePrecision(tmp, target, evPrim, evNull, canNullSafeCast)}
11581163
} catch (java.lang.NumberFormatException e) {
1159-
if ($ansiEnabled) {
1160-
throw new NumberFormatException("invalid input syntax for type numeric: $c");
1161-
} else {
1162-
$evNull =true;
1163-
}
1164+
$handleException
11641165
}
11651166
"""
11661167
case BooleanType =>

0 commit comments

Comments
 (0)