From 6fe5511acb184ad892f001dcd373a264534b3d9f Mon Sep 17 00:00:00 2001 From: yiyutian1 Date: Sun, 29 Dec 2024 23:35:27 -0800 Subject: [PATCH] [FLINK-36941] Address Comments --- docs/data/sql_functions.yml | 2 +- docs/data/sql_functions_zh.yml | 2 +- flink-python/pyflink/table/expressions.py | 2 ++ flink-python/pyflink/table/tests/test_expression.py | 4 ++++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/data/sql_functions.yml b/docs/data/sql_functions.yml index 41453893057ec..4be89daf53dc5 100644 --- a/docs/data/sql_functions.yml +++ b/docs/data/sql_functions.yml @@ -483,7 +483,7 @@ temporal: description: Returns TRUE if two time intervals defined by (timepoint1, temporal1) and (timepoint2, temporal2) overlap. The temporal values could be either a time point or a time interval. E.g., (TIME '2:55:00', INTERVAL '1' HOUR) OVERLAPS (TIME '3:30:00', INTERVAL '2' HOUR) returns TRUE; (TIME '9:00:00', TIME '10:00:00') OVERLAPS (TIME '10:15:00', INTERVAL '3' HOUR) returns FALSE. - sql: DATE_FORMAT(timestamp, string) table: dateFormat(TIMESTAMP, STRING) - description: Converts timestamp to a value of string in the format specified by the date format string. The format string is compatible with Java's DateTimeFormatter. + description: Converts timestamp to a string in the format specified by the date format string. The format string is compatible with Java's DateTimeFormatter. - sql: DATE_FORMAT(string, string) table: dateFormat(STRING, STRING) description: Re-format a timestamp string to another string, using a custom format. The format string is compatible with Java's SimpleDateFormat. diff --git a/docs/data/sql_functions_zh.yml b/docs/data/sql_functions_zh.yml index 39fa3b72a595d..c0a1290412896 100644 --- a/docs/data/sql_functions_zh.yml +++ b/docs/data/sql_functions_zh.yml @@ -601,7 +601,7 @@ temporal: `(TIME '9:00:00', TIME '10:00:00') OVERLAPS (TIME '10:15:00', INTERVAL '3' HOUR)` 返回 FALSE。 - sql: DATE_FORMAT(timestamp, string) table: dateFormat(TIMESTAMP, STRING) - description: Converts timestamp to a value of string in the format specified by the date format string. The format string is compatible with Java's DateTimeFormatter. + description: Converts timestamp to a string in the format specified by the date format string. The format string is compatible with Java's DateTimeFormatter. - sql: DATE_FORMAT(string, string) table: dateFormat(STRING, STRING) description: Re-format a timestamp string to another string, using a custom format. The format string is compatible with Java's SimpleDateFormat. diff --git a/flink-python/pyflink/table/expressions.py b/flink-python/pyflink/table/expressions.py index 6deab334e9514..8ea465dfee5ab 100644 --- a/flink-python/pyflink/table/expressions.py +++ b/flink-python/pyflink/table/expressions.py @@ -354,8 +354,10 @@ def date_format(timestamp, format) -> Expression: Supported functions: 1. date_format(TIMESTAMP, STRING) -> STRING Converts timestamp to a string, using a format string. + The format string is compatible with Java's DateTimeFormatter. 2. date_format(STRING, STRING) -> STRING Converts timestamp string, using a format string. + The format string is compatible with Java's SimpleDateFormat. Example: :: diff --git a/flink-python/pyflink/table/tests/test_expression.py b/flink-python/pyflink/table/tests/test_expression.py index 5937735e19f6d..4b01e94a8e58c 100644 --- a/flink-python/pyflink/table/tests/test_expression.py +++ b/flink-python/pyflink/table/tests/test_expression.py @@ -278,6 +278,10 @@ def test_expressions(self): self.assertEqual("dateFormat(toTimestamp('1970-01-01 08:01:40'), 'yyyy-MM-dd HH:mm:ss')", str(date_format(to_timestamp('1970-01-01 08:01:40'), "yyyy-MM-dd HH:mm:ss"))) + self.assertEqual("DATE_FORMAT(TO_TIMESTAMP('1970-01-01 08:01:40.123456+02:00'), " + "'yyyy-MM-dd HH:mm:ss.SSSSSS z')", + str(date_format(to_timestamp('1970-01-01 08:01:40.123456+02:00'), + 'yyyy-MM-dd HH:mm:ss.SSSSSS z'))) self.assertEqual("dateFormat('1970-01-01 08:01:40', 'yyyy-MM-dd HH:mm:ss')", str(date_format("1970-01-01 08:01:40", "yyyy-MM-dd HH:mm:ss"))) self.assertEqual("timestampDiff(DAY, cast('2016-06-15', DATE), cast('2016-06-18', DATE))",