Skip to content

Commit

Permalink
[SPARK-34715][SQL][TESTS] Add round trip tests for period <-> month a…
Browse files Browse the repository at this point in the history
…nd duration <-> micros

### What changes were proposed in this pull request?
Similarly to the test from the PR #31799, add tests:
1. Months -> Period -> Months
2. Period -> Months -> Period
3. Duration -> micros -> Duration

### Why are the changes needed?
Add round trip tests for period <-> month and duration <-> micros

### Does this PR introduce _any_ user-facing change?
'No'. Just test cases.

### How was this patch tested?
Jenkins test

Closes #32234 from beliefer/SPARK-34715.

Authored-by: gengjiaan <gengjiaan@360.cn>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
  • Loading branch information
beliefer authored and MaxGekk committed Apr 19, 2021
1 parent 1d1ed3e commit 7f34035
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,51 @@ class IntervalUtilsSuite extends SparkFunSuite with SQLHelper {
}
}

test("SPARK-34715: Add round trip tests for period <-> month and duration <-> micros") {
// Months -> Period -> Months
Seq(
0,
MONTHS_PER_YEAR - 1,
MONTHS_PER_YEAR + 1,
MONTHS_PER_YEAR,
-MONTHS_PER_YEAR,
Int.MaxValue - MONTHS_PER_YEAR,
Int.MinValue + MONTHS_PER_YEAR,
Int.MaxValue,
Int.MinValue).foreach { months =>
val period = monthsToPeriod(months)
assert(periodToMonths(period) === months)
}
// Period -> Months -> Period
Seq(
monthsToPeriod(0),
monthsToPeriod(MONTHS_PER_YEAR - 1),
monthsToPeriod(MONTHS_PER_YEAR + 1),
monthsToPeriod(MONTHS_PER_YEAR),
monthsToPeriod(-MONTHS_PER_YEAR),
monthsToPeriod(Int.MaxValue - MONTHS_PER_YEAR),
monthsToPeriod(Int.MinValue + MONTHS_PER_YEAR),
monthsToPeriod(Int.MaxValue),
monthsToPeriod(Int.MinValue)).foreach { period =>
val months = periodToMonths(period)
assert(monthsToPeriod(months) === period)
}
// Duration -> micros -> Duration
Seq(
microsToDuration(0),
microsToDuration(MICROS_PER_SECOND - 1),
microsToDuration(-MICROS_PER_SECOND + 1),
microsToDuration(MICROS_PER_SECOND),
microsToDuration(-MICROS_PER_SECOND),
microsToDuration(Long.MaxValue - MICROS_PER_SECOND),
microsToDuration(Long.MinValue + MICROS_PER_SECOND),
microsToDuration(Long.MaxValue),
microsToDuration(Long.MinValue)).foreach { duration =>
val micros = durationToMicros(duration)
assert(microsToDuration(micros) === duration)
}
}

test("SPARK-35016: format year-month intervals") {
Seq(
0 -> ("0-0", "INTERVAL '0-0' YEAR TO MONTH"),
Expand Down

0 comments on commit 7f34035

Please sign in to comment.