superdupershant commented on a change in pull request #35661: URL: https://github.com/apache/spark/pull/35661#discussion_r815539428
########## File path: sql/core/src/test/resources/sql-tests/results/ansi/date.sql.out ########## @@ -660,3 +660,83 @@ struct<> -- !query output org.apache.spark.SparkUpgradeException You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'dd/MMMMM/yyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select dateadd(MICROSECOND, 1001, timestamp'2022-02-25 01:02:03.123') +-- !query schema +struct<timestampadd(MICROSECOND, 1001, TIMESTAMP '2022-02-25 01:02:03.123'):timestamp> +-- !query output +2022-02-25 01:02:03.124001 + + +-- !query +select date_add(MILLISECOND, -1, timestamp'2022-02-25 01:02:03.456') +-- !query schema +struct<timestampadd(MILLISECOND, -1, TIMESTAMP '2022-02-25 01:02:03.456'):timestamp> +-- !query output +2022-02-25 01:02:03.455 + + +-- !query +select dateadd(SECOND, 58, timestamp'2022-02-25 01:02:03') +-- !query schema +struct<timestampadd(SECOND, 58, TIMESTAMP '2022-02-25 01:02:03'):timestamp> +-- !query output +2022-02-25 01:03:01 + + +-- !query +select date_add(MINUTE, -100, date'2022-02-25') +-- !query schema +struct<timestampadd(MINUTE, -100, DATE '2022-02-25'):timestamp> +-- !query output +2022-02-24 22:20:00 + + +-- !query +select dateadd(HOUR, -1, timestamp'2022-02-25 01:02:03') +-- !query schema +struct<timestampadd(HOUR, -1, TIMESTAMP '2022-02-25 01:02:03'):timestamp> +-- !query output +2022-02-25 00:02:03 + + +-- !query +select date_add(DAY, 367, date'2022-02-25') Review comment: I think the convention is if the third argument is of type DATE the expression's return type is: DATE if the unit is DAY or larger TIMESTAMP if the unit is smaller than DAY i.e. (HOUR, MINUTE, SECOND, etc...) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
