Skip to content

Commit 7f34035

Browse files
belieferMaxGekk
authored andcommitted
[SPARK-34715][SQL][TESTS] Add round trip tests for period <-> month and 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>
1 parent 1d1ed3e commit 7f34035

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/IntervalUtilsSuite.scala

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,51 @@ class IntervalUtilsSuite extends SparkFunSuite with SQLHelper {
443443
}
444444
}
445445

446+
test("SPARK-34715: Add round trip tests for period <-> month and duration <-> micros") {
447+
// Months -> Period -> Months
448+
Seq(
449+
0,
450+
MONTHS_PER_YEAR - 1,
451+
MONTHS_PER_YEAR + 1,
452+
MONTHS_PER_YEAR,
453+
-MONTHS_PER_YEAR,
454+
Int.MaxValue - MONTHS_PER_YEAR,
455+
Int.MinValue + MONTHS_PER_YEAR,
456+
Int.MaxValue,
457+
Int.MinValue).foreach { months =>
458+
val period = monthsToPeriod(months)
459+
assert(periodToMonths(period) === months)
460+
}
461+
// Period -> Months -> Period
462+
Seq(
463+
monthsToPeriod(0),
464+
monthsToPeriod(MONTHS_PER_YEAR - 1),
465+
monthsToPeriod(MONTHS_PER_YEAR + 1),
466+
monthsToPeriod(MONTHS_PER_YEAR),
467+
monthsToPeriod(-MONTHS_PER_YEAR),
468+
monthsToPeriod(Int.MaxValue - MONTHS_PER_YEAR),
469+
monthsToPeriod(Int.MinValue + MONTHS_PER_YEAR),
470+
monthsToPeriod(Int.MaxValue),
471+
monthsToPeriod(Int.MinValue)).foreach { period =>
472+
val months = periodToMonths(period)
473+
assert(monthsToPeriod(months) === period)
474+
}
475+
// Duration -> micros -> Duration
476+
Seq(
477+
microsToDuration(0),
478+
microsToDuration(MICROS_PER_SECOND - 1),
479+
microsToDuration(-MICROS_PER_SECOND + 1),
480+
microsToDuration(MICROS_PER_SECOND),
481+
microsToDuration(-MICROS_PER_SECOND),
482+
microsToDuration(Long.MaxValue - MICROS_PER_SECOND),
483+
microsToDuration(Long.MinValue + MICROS_PER_SECOND),
484+
microsToDuration(Long.MaxValue),
485+
microsToDuration(Long.MinValue)).foreach { duration =>
486+
val micros = durationToMicros(duration)
487+
assert(microsToDuration(micros) === duration)
488+
}
489+
}
490+
446491
test("SPARK-35016: format year-month intervals") {
447492
Seq(
448493
0 -> ("0-0", "INTERVAL '0-0' YEAR TO MONTH"),

0 commit comments

Comments
 (0)