Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ case class ToUnixTimestamp(
* Converts time string with given pattern to Unix time stamp (in seconds), returns null if fail.
* See [https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html].
* Note that hive Language Manual says it returns 0 if fail, but in fact it returns null.
* If the second parameter is missing, use "yyyy-MM-dd HH:mm:ss".
* If the second parameter is missing, use "uuuu-MM-dd HH:mm:ss".
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* If no parameters provided, the first parameter will be current_timestamp.
* If the first parameter is a Date or Timestamp instead of String, we will ignore the
* second parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Iso8601TimestampFormatter(
}

/**
* The formatter parses/formats timestamps according to the pattern `yyyy-MM-dd HH:mm:ss.[..fff..]`
* The formatter parses/formats timestamps according to the pattern `uuuu-MM-dd HH:mm:ss.[..fff..]`
Copy link
Member Author

@MaxGekk MaxGekk Sep 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ISO_LOCAL_DATE (

) supports negative years, and in this mean it is equal to uuuu

* where `[..fff..]` is a fraction of second up to microsecond resolution. The formatter does not
* output trailing zeros in the fraction. For example, the timestamp `2019-03-05 15:00:01.123400` is
* formatted as the string `2019-03-05 15:00:01.1234`.
Expand Down
4 changes: 2 additions & 2 deletions sql/core/src/main/scala/org/apache/spark/sql/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2634,8 +2634,8 @@ object functions {
* See [[java.time.format.DateTimeFormatter]] for valid date and time format patterns
*
* @param dateExpr A date, timestamp or string. If a string, the data must be in a format that
* can be cast to a timestamp, such as `yyyy-MM-dd` or `yyyy-MM-dd HH:mm:ss.SSSS`
* @param format A pattern `dd.MM.yyyy` would return a string like `18.03.1993`
* can be cast to a timestamp, such as `uuuu-MM-dd` or `uuuu-MM-dd HH:mm:ss.SSSS`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses TimestampFormatter which can output negative years using the uuuu pattern.

* @param format A pattern `dd.MM.uuuu` would return a string like `18.03.1993`
* @return A string, or null if `dateExpr` was a string that could not be cast to a timestamp
* @note Use specialized functions like [[year]] whenever possible as they benefit from a
* specialized implementation.
Expand Down