[SPARK-25605][TESTS] Run cast string to timestamp tests for a subset of timezones

## What changes were proposed in this pull request?

The test `cast string to timestamp` used to run for all time zones. So it run for more than 600 times. Running the tests for a significant subset of time zones is probably good enough and doing this in a randomized manner enforces anyway that we are going to test all time zones in different runs.

## How was this patch tested?

the test time reduces to 11 seconds from more than 2 minutes

Closes #22631 from mgaido91/SPARK-25605.

Authored-by: Marco Gaido <marcogaido91@gmail.com>
Signed-off-by: gatorsmile <gatorsmile@gmail.com>
This commit is contained in:
Marco Gaido 2018-10-04 18:54:46 -07:00 committed by gatorsmile
parent f27d96b9f3
commit 8113b9c966

View file

@ -20,6 +20,8 @@ package org.apache.spark.sql.catalyst.expressions
import java.sql.{Date, Timestamp} import java.sql.{Date, Timestamp}
import java.util.{Calendar, Locale, TimeZone} import java.util.{Calendar, Locale, TimeZone}
import scala.util.Random
import org.apache.spark.SparkFunSuite import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.Row import org.apache.spark.sql.Row
import org.apache.spark.sql.catalyst.InternalRow import org.apache.spark.sql.catalyst.InternalRow
@ -110,7 +112,7 @@ class CastSuite extends SparkFunSuite with ExpressionEvalHelper {
} }
test("cast string to timestamp") { test("cast string to timestamp") {
for (tz <- ALL_TIMEZONES) { for (tz <- Random.shuffle(ALL_TIMEZONES).take(50)) {
def checkCastStringToTimestamp(str: String, expected: Timestamp): Unit = { def checkCastStringToTimestamp(str: String, expected: Timestamp): Unit = {
checkEvaluation(cast(Literal(str), TimestampType, Option(tz.getID)), expected) checkEvaluation(cast(Literal(str), TimestampType, Option(tz.getID)), expected)
} }