From 065f5f9625030f12daa66aa096510e401bcd8e9a Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Tue, 24 Dec 2024 17:13:56 +0800 Subject: [PATCH 1/4] Initial --- velox/functions/sparksql/registration/RegisterDatetime.cpp | 2 ++ 1 file changed, 2 insertions(+) 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"}); From 0fffe27c958c1b2ad41e74a8ed87a6604ed3646c Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Wed, 25 Dec 2024 10:46:34 +0800 Subject: [PATCH 2/4] Add doc --- velox/docs/functions/spark/datetime.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/velox/docs/functions/spark/datetime.rst b/velox/docs/functions/spark/datetime.rst index 254756aaa108..53ad6483281c 100644 --- a/velox/docs/functions/spark/datetime.rst +++ b/velox/docs/functions/spark/datetime.rst @@ -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. From 06a3b7e3267240facb9d2772d39f3204e0df46d0 Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Fri, 27 Dec 2024 14:12:48 +0800 Subject: [PATCH 3/4] Update doc --- velox/docs/functions/spark/datetime.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/velox/docs/functions/spark/datetime.rst b/velox/docs/functions/spark/datetime.rst index 53ad6483281c..df371441b878 100644 --- a/velox/docs/functions/spark/datetime.rst +++ b/velox/docs/functions/spark/datetime.rst @@ -37,6 +37,9 @@ These functions support TIMESTAMP and DATE input types. .. 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' From e543f543319ac0a1386ee61a8ab1c26b6a6d3459 Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Fri, 27 Dec 2024 15:36:05 +0800 Subject: [PATCH 4/4] Fix comment --- velox/docs/functions/spark/datetime.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/velox/docs/functions/spark/datetime.rst b/velox/docs/functions/spark/datetime.rst index df371441b878..650056aee28b 100644 --- a/velox/docs/functions/spark/datetime.rst +++ b/velox/docs/functions/spark/datetime.rst @@ -36,7 +36,7 @@ These functions support TIMESTAMP and DATE input types. .. spark:function:: date_format(timestamp, dateFormat) -> string - Converts `timestamp` to a string in the format specified by `dateFormat`. + Converts ``timestamp`` to a string in the format specified by ``dateFormat``. The format follows Spark's `Datetime patterns `_.