Github user cloud-fan commented on a diff in the pull request: https://github.com/apache/spark/pull/16308#discussion_r96628119 --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala --- @@ -143,72 +159,114 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper { } test("Seconds") { - assert(Second(Literal.create(null, DateType)).resolved === false) - checkEvaluation(Second(Cast(Literal(d), TimestampType)), 0) - checkEvaluation(Second(Cast(Literal(sdf.format(d)), TimestampType)), 15) - checkEvaluation(Second(Literal(ts)), 15) + assert(Second(Literal.create(null, DateType), gmtId).resolved === false) + assert(Second(Cast(Literal(d), TimestampType), null).resolved === true) + checkEvaluation(Second(Cast(Literal(d), TimestampType, gmtId), gmtId), 0) + checkEvaluation(Second(Cast(Literal(sdf.format(d)), TimestampType, gmtId), gmtId), 15) + checkEvaluation(Second(Literal(ts), gmtId), 15) val c = Calendar.getInstance() - (0 to 60 by 5).foreach { s => - c.set(2015, 18, 3, 3, 5, s) - checkEvaluation(Second(Literal(new Timestamp(c.getTimeInMillis))), - c.get(Calendar.SECOND)) + for (tz <- Seq(TimeZoneGMT, TimeZonePST, TimeZoneJST)) { + val timeZoneId = Option(tz.getID) + c.setTimeZone(tz) + (0 to 60 by 5).foreach { s => + c.set(2015, 18, 3, 3, 5, s) + checkEvaluation( + Second(Literal(new Timestamp(c.getTimeInMillis)), timeZoneId), + c.get(Calendar.SECOND)) + } + checkConsistencyBetweenInterpretedAndCodegen( + (child: Expression) => Second(child, timeZoneId), TimestampType) } - checkConsistencyBetweenInterpretedAndCodegen(Second, TimestampType) } test("WeekOfYear") { checkEvaluation(WeekOfYear(Literal.create(null, DateType)), null) checkEvaluation(WeekOfYear(Literal(d)), 15) - checkEvaluation(WeekOfYear(Cast(Literal(sdfDate.format(d)), DateType)), 15) - checkEvaluation(WeekOfYear(Cast(Literal(ts), DateType)), 45) - checkEvaluation(WeekOfYear(Cast(Literal("2011-05-06"), DateType)), 18) + checkEvaluation(WeekOfYear(Cast(Literal(sdfDate.format(d)), DateType, gmtId)), 15) + checkEvaluation(WeekOfYear(Cast(Literal(ts), DateType, gmtId)), 45) + checkEvaluation(WeekOfYear(Cast(Literal("2011-05-06"), DateType, gmtId)), 18) checkConsistencyBetweenInterpretedAndCodegen(WeekOfYear, DateType) } test("DateFormat") { - checkEvaluation(DateFormatClass(Literal.create(null, TimestampType), Literal("y")), null) - checkEvaluation(DateFormatClass(Cast(Literal(d), TimestampType), - Literal.create(null, StringType)), null) - checkEvaluation(DateFormatClass(Cast(Literal(d), TimestampType), - Literal("y")), "2015") - checkEvaluation(DateFormatClass(Literal(ts), Literal("y")), "2013") + checkEvaluation( + DateFormatClass(Literal.create(null, TimestampType), Literal("y"), gmtId), + null) + checkEvaluation(DateFormatClass(Cast(Literal(d), TimestampType, gmtId), + Literal.create(null, StringType), gmtId), null) + + checkEvaluation(DateFormatClass(Cast(Literal(d), TimestampType, gmtId), + Literal("y"), gmtId), "2015") + checkEvaluation(DateFormatClass(Literal(ts), Literal("y"), gmtId), "2013") + checkEvaluation(DateFormatClass(Cast(Literal(d), TimestampType, gmtId), + Literal("H"), gmtId), "0") + checkEvaluation(DateFormatClass(Literal(ts), Literal("H"), gmtId), "13") + + checkEvaluation(DateFormatClass(Cast(Literal(d), TimestampType, pstId), + Literal("y"), pstId), "2015") + checkEvaluation(DateFormatClass(Literal(ts), Literal("y"), pstId), "2013") + checkEvaluation(DateFormatClass(Cast(Literal(d), TimestampType, pstId), + Literal("H"), pstId), "0") + checkEvaluation(DateFormatClass(Literal(ts), Literal("H"), pstId), "5") + + checkEvaluation(DateFormatClass(Cast(Literal(d), TimestampType, jstId), + Literal("y"), jstId), "2015") + checkEvaluation(DateFormatClass(Literal(ts), Literal("y"), jstId), "2013") + checkEvaluation(DateFormatClass(Cast(Literal(d), TimestampType, jstId), + Literal("H"), jstId), "0") + checkEvaluation(DateFormatClass(Literal(ts), Literal("H"), jstId), "22") } test("Hour") { - assert(Hour(Literal.create(null, DateType)).resolved === false) - checkEvaluation(Hour(Cast(Literal(d), TimestampType)), 0) - checkEvaluation(Hour(Cast(Literal(sdf.format(d)), TimestampType)), 13) - checkEvaluation(Hour(Literal(ts)), 13) + assert(Hour(Literal.create(null, DateType), gmtId).resolved === false) + assert(Hour(Literal(ts), null).resolved === true) + checkEvaluation(Hour(Cast(Literal(d), TimestampType, gmtId), gmtId), 0) + checkEvaluation(Hour(Cast(Literal(sdf.format(d)), TimestampType, gmtId), gmtId), 13) + checkEvaluation(Hour(Literal(ts), gmtId), 13) val c = Calendar.getInstance() - (0 to 24).foreach { h => - (0 to 60 by 15).foreach { m => - (0 to 60 by 15).foreach { s => - c.set(2015, 18, 3, h, m, s) - checkEvaluation(Hour(Literal(new Timestamp(c.getTimeInMillis))), - c.get(Calendar.HOUR_OF_DAY)) + for (tz <- Seq(TimeZoneGMT, TimeZonePST, TimeZoneJST)) { + val timeZoneId = Option(tz.getID) + c.setTimeZone(tz) + (0 to 24).foreach { h => + (0 to 60 by 15).foreach { m => + (0 to 60 by 15).foreach { s => + c.set(2015, 18, 3, h, m, s) + checkEvaluation( + Hour(Literal(new Timestamp(c.getTimeInMillis)), timeZoneId), + c.get(Calendar.HOUR_OF_DAY)) + } } } + checkConsistencyBetweenInterpretedAndCodegen( + (child: Expression) => Hour(child, timeZoneId), TimestampType) } - checkConsistencyBetweenInterpretedAndCodegen(Hour, TimestampType) } test("Minute") { - assert(Minute(Literal.create(null, DateType)).resolved === false) - checkEvaluation(Minute(Cast(Literal(d), TimestampType)), 0) - checkEvaluation(Minute(Cast(Literal(sdf.format(d)), TimestampType)), 10) - checkEvaluation(Minute(Literal(ts)), 10) + assert(Minute(Literal.create(null, DateType), gmtId).resolved === false) + assert(Minute(Literal(ts), null).resolved === true) --- End diff -- same here
--- 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