diff --git a/velox/docs/functions/spark/datetime.rst b/velox/docs/functions/spark/datetime.rst index 254756aaa108..650056aee28b 100644 --- a/velox/docs/functions/spark/datetime.rst +++ b/velox/docs/functions/spark/datetime.rst @@ -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 + `_. + + 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. diff --git a/velox/functions/sparksql/registration/RegisterDatetime.cpp b/velox/functions/sparksql/registration/RegisterDatetime.cpp index 334a021457b0..e93daa887b04 100644 --- a/velox/functions/sparksql/registration/RegisterDatetime.cpp +++ b/velox/functions/sparksql/registration/RegisterDatetime.cpp @@ -52,6 +52,8 @@ void registerDatetimeFunctions(const std::string& prefix) { registerFunction({prefix + "date_add"}); registerFunction({prefix + "date_add"}); registerFunction({prefix + "date_add"}); + registerFunction( + {prefix + "date_format"}); registerFunction( {prefix + "date_from_unix_date"}); registerFunction({prefix + "date_sub"});