Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: Support date_format Spark function by simply reusing a Presto function #11953

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions velox/docs/functions/spark/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ 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`.

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
Loading