Skip to content
Closed
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
Next Next commit
Update IntervalUtils.scala
  • Loading branch information
AngersZhuuuu committed Apr 22, 2021
commit 15424a75adac714f38aca0615ae92362ba34d31b
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,22 @@ object IntervalUtils {

private val yearMonthPattern = "^([+|-])?(\\d+)-(\\d+)$".r

private val yearMonthFuzzyPattern = "[^-|+]*?([+|-]?[\\d]+-[\\d]+).*".r
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a new regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a new regex?

Since yearMonthPattern only support [+|-]yy-mmmm

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do we want to support here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am discussing this here #32266 (comment) with @MaxGekk ,
Do you have any other supplementary suggestions?


def safeFromYearMonthString(input: UTF8String): Option[Int] = {
try {
if (input == null || input.toString == null) {
throw new IllegalArgumentException("Interval year-month string must be not null")
} else {
val regex = "INTERVAL '([-|+]?[0-9]+-[-|+]?[0-9]+)' YEAR TO MONTH".r
// scalastyle:off caselocale .toLowerCase
val intervalString = input.trimAll().toUpperCase.toString
// scalastyle:on
val interval = regex.findFirstMatchIn(intervalString)
.map(_.group(1)).getOrElse(intervalString)
Some(fromYearMonthString(interval).months)
intervalString match {
case yearMonthFuzzyPattern(payLoad) =>
Some(fromYearMonthString(payLoad).months)
case _ =>
throw new IllegalArgumentException(
s"Interval string does not match year-month format of 'y-m': $input")
}
}
} catch {
case _: IllegalArgumentException => None
Expand Down