Skip to content

Commit

Permalink
feat: Register Spark date_format function (facebookincubator#11953)
Browse files Browse the repository at this point in the history
Summary:
This PR registers the existing `FormatDateTimeFunction` for Spark SQL to use.

Pull Request resolved: facebookincubator#11953

Reviewed By: kevinwilfong

Differential Revision: D67996579

Pulled By: Yuhta

fbshipit-source-id: 0aacc83c8763b9e43d355b97d49cc99227d3baba
  • Loading branch information
PHILO-HE authored and facebook-github-bot committed Jan 10, 2025
1 parent 923dcc8 commit ec2740f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions velox/docs/functions/spark/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ These functions support TIMESTAMP and DATE input types.
deducted from ``start_date``.
Supported types for ``num_days`` are: TINYINT, SMALLINT, INTEGER.

.. spark:function:: date_format(timestamp, dateFormat) -> string
Converts ``timestamp`` to a string in the format specified by ``dateFormat``.
The format follows Spark's
`Datetime patterns
<https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html>`_.

SELECT date_format('2020-01-29', 'yyyy'); -- '2020'
SELECT date_format('2024-05-30 08:00:00', 'yyyy-MM-dd'); -- '2024-05-30'

.. spark:function:: date_from_unix_date(integer) -> date
Creates date from the number of days since 1970-01-01 in either direction. Returns null when input is null.
Expand Down
2 changes: 2 additions & 0 deletions velox/functions/sparksql/registration/RegisterDatetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ void registerDatetimeFunctions(const std::string& prefix) {
registerFunction<DateAddFunction, Date, Date, int8_t>({prefix + "date_add"});
registerFunction<DateAddFunction, Date, Date, int16_t>({prefix + "date_add"});
registerFunction<DateAddFunction, Date, Date, int32_t>({prefix + "date_add"});
registerFunction<FormatDateTimeFunction, Varchar, Timestamp, Varchar>(
{prefix + "date_format"});
registerFunction<DateFromUnixDateFunction, Date, int32_t>(
{prefix + "date_from_unix_date"});
registerFunction<DateSubFunction, Date, Date, int8_t>({prefix + "date_sub"});
Expand Down

0 comments on commit ec2740f

Please sign in to comment.