Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9546a0f
[SPARK-35111][SQL] Support Cast string to year-month interval
AngersZhuuuu Apr 21, 2021
691c1f4
Update CastSuite.scala
AngersZhuuuu Apr 21, 2021
f5b02ee
Update CastSuite.scala
AngersZhuuuu Apr 22, 2021
15424a7
Update IntervalUtils.scala
AngersZhuuuu Apr 22, 2021
879817b
Update CastSuite.scala
AngersZhuuuu Apr 22, 2021
62d175b
Update CastSuite.scala
AngersZhuuuu Apr 22, 2021
2c75bba
save
AngersZhuuuu Apr 22, 2021
5b134fa
Merge branch 'master' into SPARK-SPARK-35111
AngersZhuuuu Apr 22, 2021
6d14414
Update CastSuite.scala
AngersZhuuuu Apr 22, 2021
d19bbc8
Update Cast.scala
AngersZhuuuu Apr 23, 2021
ff904a1
save
AngersZhuuuu Apr 25, 2021
d0e30e4
Merge branch 'master' into SPARK-SPARK-35111
AngersZhuuuu Apr 25, 2021
3b84baa
follow comment
AngersZhuuuu Apr 25, 2021
b05f7e6
update
AngersZhuuuu Apr 28, 2021
25c08e0
Update IntervalUtils.scala
AngersZhuuuu Apr 28, 2021
f636d41
update
AngersZhuuuu Apr 28, 2021
ce69004
Update CastSuite.scala
AngersZhuuuu Apr 28, 2021
092d01a
Update IntervalUtils.scala
AngersZhuuuu Apr 28, 2021
f088f64
Update IntervalUtils.scala
AngersZhuuuu Apr 28, 2021
80499b8
Update IntervalUtils.scala
AngersZhuuuu Apr 29, 2021
ca19c09
Update IntervalUtils.scala
AngersZhuuuu Apr 29, 2021
3df92b6
Update Cast.scala
AngersZhuuuu Apr 29, 2021
3adde87
Update IntervalUtils.scala
AngersZhuuuu Apr 29, 2021
0f82987
follow comment
AngersZhuuuu Apr 29, 2021
2c8785b
Update CastSuite.scala
AngersZhuuuu Apr 29, 2021
253c70e
follow comment
AngersZhuuuu Apr 29, 2021
9c70b88
Update IntervalUtils.scala
AngersZhuuuu Apr 29, 2021
5ca83ab
update
AngersZhuuuu Apr 30, 2021
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
update
  • Loading branch information
AngersZhuuuu committed Apr 30, 2021
commit 5ca83abe001897216575fad9f00906de553626c6
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit
private[this] def castToYearMonthIntervalCode(from: DataType): CastFunction = from match {
case StringType =>
val util = IntervalUtils.getClass.getCanonicalName.stripSuffix("$")
(c, evPrim, evNull) => code"$evPrim = $util.castStringToYMInterval($c);"
(c, evPrim, _) => code"$evPrim = $util.castStringToYMInterval($c);"
}

private[this] def decimalToTimestampCode(d: ExprValue): Block = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.apache.spark.sql.catalyst.util

import java.time.{Duration, Period}
import java.time.temporal.ChronoUnit
import java.util.Locale
import java.util.concurrent.TimeUnit

import scala.util.control.NonFatal
Expand Down Expand Up @@ -94,10 +93,10 @@ object IntervalUtils {

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

def castStringToYMInterval(input: UTF8String): Int = {
input.trimAll().toString.toUpperCase(Locale.ROOT) match {
input.trimAll().toString match {
case yearMonthPattern("-", year, month) => toYMInterval(year, month, -1)
case yearMonthPattern(_, year, month) => toYMInterval(year, month, 1)
case yearMonthStringPattern(_, firstSign, _, secondSign, year, month, _, _) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,9 @@ class CastSuite extends CastSuiteBase {
YearMonthIntervalType), 12)
checkEvaluation(cast(Literal.create("INTERVAL +'1-0' YEAR TO MONTH"),
YearMonthIntervalType), 12)
checkEvaluation(cast(Literal.create(" interval +'1-0' YEAR TO MONTH "),
YearMonthIntervalType), 12)
checkEvaluation(cast(Literal.create(" -1-0 "), YearMonthIntervalType), -12)
checkEvaluation(cast(Literal.create("-1-0"), YearMonthIntervalType), -12)
checkEvaluation(cast(Literal.create(null, StringType), YearMonthIntervalType), null)

Expand Down