Github user cloud-fan commented on a diff in the pull request: https://github.com/apache/spark/pull/16308#discussion_r96626629 --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CastSuite.scala --- @@ -107,108 +109,119 @@ class CastSuite extends SparkFunSuite with ExpressionEvalHelper { } test("cast string to timestamp") { - checkEvaluation(Cast(Literal("123"), TimestampType), null) - - var c = Calendar.getInstance() - c.set(2015, 0, 1, 0, 0, 0) - c.set(Calendar.MILLISECOND, 0) - checkEvaluation(Cast(Literal("2015"), TimestampType), - new Timestamp(c.getTimeInMillis)) - c = Calendar.getInstance() - c.set(2015, 2, 1, 0, 0, 0) - c.set(Calendar.MILLISECOND, 0) - checkEvaluation(Cast(Literal("2015-03"), TimestampType), - new Timestamp(c.getTimeInMillis)) - c = Calendar.getInstance() - c.set(2015, 2, 18, 0, 0, 0) - c.set(Calendar.MILLISECOND, 0) - checkEvaluation(Cast(Literal("2015-03-18"), TimestampType), - new Timestamp(c.getTimeInMillis)) - checkEvaluation(Cast(Literal("2015-03-18 "), TimestampType), - new Timestamp(c.getTimeInMillis)) - checkEvaluation(Cast(Literal("2015-03-18T"), TimestampType), - new Timestamp(c.getTimeInMillis)) - - c = Calendar.getInstance() - c.set(2015, 2, 18, 12, 3, 17) - c.set(Calendar.MILLISECOND, 0) - checkEvaluation(Cast(Literal("2015-03-18 12:03:17"), TimestampType), - new Timestamp(c.getTimeInMillis)) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17"), TimestampType), - new Timestamp(c.getTimeInMillis)) - - c = Calendar.getInstance(TimeZone.getTimeZone("UTC")) - c.set(2015, 2, 18, 12, 3, 17) - c.set(Calendar.MILLISECOND, 0) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17Z"), TimestampType), - new Timestamp(c.getTimeInMillis)) - checkEvaluation(Cast(Literal("2015-03-18 12:03:17Z"), TimestampType), - new Timestamp(c.getTimeInMillis)) - - c = Calendar.getInstance(TimeZone.getTimeZone("GMT-01:00")) - c.set(2015, 2, 18, 12, 3, 17) - c.set(Calendar.MILLISECOND, 0) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17-1:0"), TimestampType), - new Timestamp(c.getTimeInMillis)) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17-01:00"), TimestampType), - new Timestamp(c.getTimeInMillis)) - - c = Calendar.getInstance(TimeZone.getTimeZone("GMT+07:30")) - c.set(2015, 2, 18, 12, 3, 17) - c.set(Calendar.MILLISECOND, 0) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17+07:30"), TimestampType), - new Timestamp(c.getTimeInMillis)) - - c = Calendar.getInstance(TimeZone.getTimeZone("GMT+07:03")) - c.set(2015, 2, 18, 12, 3, 17) - c.set(Calendar.MILLISECOND, 0) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17+7:3"), TimestampType), - new Timestamp(c.getTimeInMillis)) - - c = Calendar.getInstance() - c.set(2015, 2, 18, 12, 3, 17) - c.set(Calendar.MILLISECOND, 123) - checkEvaluation(Cast(Literal("2015-03-18 12:03:17.123"), TimestampType), - new Timestamp(c.getTimeInMillis)) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17.123"), TimestampType), - new Timestamp(c.getTimeInMillis)) - - c = Calendar.getInstance(TimeZone.getTimeZone("UTC")) - c.set(2015, 2, 18, 12, 3, 17) - c.set(Calendar.MILLISECOND, 456) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17.456Z"), TimestampType), - new Timestamp(c.getTimeInMillis)) - checkEvaluation(Cast(Literal("2015-03-18 12:03:17.456Z"), TimestampType), - new Timestamp(c.getTimeInMillis)) - - c = Calendar.getInstance(TimeZone.getTimeZone("GMT-01:00")) - c.set(2015, 2, 18, 12, 3, 17) - c.set(Calendar.MILLISECOND, 123) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17.123-1:0"), TimestampType), - new Timestamp(c.getTimeInMillis)) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17.123-01:00"), TimestampType), - new Timestamp(c.getTimeInMillis)) - - c = Calendar.getInstance(TimeZone.getTimeZone("GMT+07:30")) - c.set(2015, 2, 18, 12, 3, 17) - c.set(Calendar.MILLISECOND, 123) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17.123+07:30"), TimestampType), - new Timestamp(c.getTimeInMillis)) - - c = Calendar.getInstance(TimeZone.getTimeZone("GMT+07:03")) - c.set(2015, 2, 18, 12, 3, 17) - c.set(Calendar.MILLISECOND, 123) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17.123+7:3"), TimestampType), - new Timestamp(c.getTimeInMillis)) - - checkEvaluation(Cast(Literal("2015-03-18 123142"), TimestampType), null) - checkEvaluation(Cast(Literal("2015-03-18T123123"), TimestampType), null) - checkEvaluation(Cast(Literal("2015-03-18X"), TimestampType), null) - checkEvaluation(Cast(Literal("2015/03/18"), TimestampType), null) - checkEvaluation(Cast(Literal("2015.03.18"), TimestampType), null) - checkEvaluation(Cast(Literal("20150318"), TimestampType), null) - checkEvaluation(Cast(Literal("2015-031-8"), TimestampType), null) - checkEvaluation(Cast(Literal("2015-03-18T12:03:17-0:70"), TimestampType), null) + for (tz <- ALL_TIMEZONES) { --- End diff -- I didn't check this code block line by line, I assume it just iterates all time zone ids and adds it to all the `Cast`. @ueshin please highlight important changes here, if there are any.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org