Skip to content

Commit 5ca83ab

Browse files
committed
update
1 parent 9c70b88 commit 5ca83ab

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit
13651365
private[this] def castToYearMonthIntervalCode(from: DataType): CastFunction = from match {
13661366
case StringType =>
13671367
val util = IntervalUtils.getClass.getCanonicalName.stripSuffix("$")
1368-
(c, evPrim, evNull) => code"$evPrim = $util.castStringToYMInterval($c);"
1368+
(c, evPrim, _) => code"$evPrim = $util.castStringToYMInterval($c);"
13691369
}
13701370

13711371
private[this] def decimalToTimestampCode(d: ExprValue): Block = {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package org.apache.spark.sql.catalyst.util
1919

2020
import java.time.{Duration, Period}
2121
import java.time.temporal.ChronoUnit
22-
import java.util.Locale
2322
import java.util.concurrent.TimeUnit
2423

2524
import scala.util.control.NonFatal
@@ -94,10 +93,10 @@ object IntervalUtils {
9493

9594
private val yearMonthPattern = "^([+|-])?(\\d+)-(\\d+)$".r
9695
private val yearMonthStringPattern =
97-
"^(INTERVAL\\s+)([+|-])?(')([+|-])?(\\d+)-(\\d+)(')(\\s+YEAR\\s+TO\\s+MONTH)$".r
96+
"(?i)^(INTERVAL\\s+)([+|-])?(')([+|-])?(\\d+)-(\\d+)(')(\\s+YEAR\\s+TO\\s+MONTH)$".r
9897

9998
def castStringToYMInterval(input: UTF8String): Int = {
100-
input.trimAll().toString.toUpperCase(Locale.ROOT) match {
99+
input.trimAll().toString match {
101100
case yearMonthPattern("-", year, month) => toYMInterval(year, month, -1)
102101
case yearMonthPattern(_, year, month) => toYMInterval(year, month, 1)
103102
case yearMonthStringPattern(_, firstSign, _, secondSign, year, month, _, _) =>

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,9 @@ class CastSuite extends CastSuiteBase {
17881788
YearMonthIntervalType), 12)
17891789
checkEvaluation(cast(Literal.create("INTERVAL +'1-0' YEAR TO MONTH"),
17901790
YearMonthIntervalType), 12)
1791+
checkEvaluation(cast(Literal.create(" interval +'1-0' YEAR TO MONTH "),
1792+
YearMonthIntervalType), 12)
1793+
checkEvaluation(cast(Literal.create(" -1-0 "), YearMonthIntervalType), -12)
17911794
checkEvaluation(cast(Literal.create("-1-0"), YearMonthIntervalType), -12)
17921795
checkEvaluation(cast(Literal.create(null, StringType), YearMonthIntervalType), null)
17931796

0 commit comments

Comments
 (0)