Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AngersZhuuuu committed Jul 8, 2021
1 parent 9e07e88 commit 0582bda
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Expand Up @@ -770,7 +770,8 @@ class ExpressionParserSuite extends AnalysisTest {
"0:0:0",
"0:0:1")
hourTimeValues.foreach { value =>
val result = Literal(IntervalUtils.fromDayTimeString(value, HOUR, SECOND))
val result = Literal(IntervalUtils.fromDayTimeString(
value, DayTimeIntervalType.HOUR, DayTimeIntervalType.SECOND))
checkIntervals(s"'$value' hour to second", result)
}
}
Expand Down
Expand Up @@ -26,7 +26,6 @@ import org.apache.spark.sql.catalyst.util.DateTimeConstants._
import org.apache.spark.sql.catalyst.util.DateTimeUtils.millisToMicros
import org.apache.spark.sql.catalyst.util.IntervalStringStyles.{ANSI_STYLE, HIVE_STYLE}
import org.apache.spark.sql.catalyst.util.IntervalUtils._
import org.apache.spark.sql.catalyst.util.IntervalUtils.IntervalUnit._
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.DayTimeIntervalType
import org.apache.spark.unsafe.types.{CalendarInterval, UTF8String}
Expand Down Expand Up @@ -203,8 +202,6 @@ class IntervalUtilsSuite extends SparkFunSuite with SQLHelper {

failFuncWithInvalidInput("5 30:12:20", "hour 30 outside range", fromDayTimeString)
failFuncWithInvalidInput("5 30-12", "must match day-time format", fromDayTimeString)
failFuncWithInvalidInput("5 1:12:20", "Cannot support (interval",
s => fromDayTimeString(s, HOUR, MICROSECOND))
}
}

Expand Down Expand Up @@ -314,13 +311,14 @@ class IntervalUtilsSuite extends SparkFunSuite with SQLHelper {
}

test("from day-time string") {
def check(input: String, from: IntervalUnit, to: IntervalUnit, expected: String): Unit = {
import org.apache.spark.sql.types.DayTimeIntervalType._
def check(input: String, from: Byte, to: Byte, expected: String): Unit = {
withClue(s"from = $from, to = $to") {
val expectedUtf8 = UTF8String.fromString(expected)
assert(fromDayTimeString(input, from, to) === safeStringToInterval(expectedUtf8))
}
}
def checkFail(input: String, from: IntervalUnit, to: IntervalUnit, errMsg: String): Unit = {
def checkFail(input: String, from: Byte, to: Byte, errMsg: String): Unit = {
failFuncWithInvalidInput(input, errMsg, s => fromDayTimeString(s, from, to))
}

Expand Down Expand Up @@ -358,10 +356,7 @@ class IntervalUtilsSuite extends SparkFunSuite with SQLHelper {

checkFail("5 30:12:20", DAY, SECOND, "hour 30 outside range")
checkFail("5 30-12", DAY, SECOND, "Interval string does not match day-time format")
withClue("Expected to throw an exception for the invalid input") {
val e = intercept[NoSuchElementException](fromDayTimeString("5 1:12:20", HOUR, MICROSECOND))
assert(e.getMessage.contains("key not found: microsecond"))
}

// whitespaces
check("\t +5 12:40\t ", DAY, MINUTE, "5 days 12 hours 40 minutes")
checkFail("+5\t 12:40", DAY, MINUTE, "Interval string does not match day-time format")
Expand Down

0 comments on commit 0582bda

Please sign in to comment.