Skip to content

Commit 2cddb46

Browse files
charlesdong1991dianfu
authored andcommitted
[FLINK-38319][python] Allow TO_TIMESTAMP_LTZ to accept expressions other than literal in PyFlink (#26987)
1 parent ee369f1 commit 2cddb46

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

flink-python/pyflink/table/expressions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,15 @@ def to_timestamp_ltz(*args) -> Expression:
355355
"UTC")) # string with format and timezone
356356
"""
357357
if len(args) == 1:
358-
return _unary_op("toTimestampLtz", lit(args[0]))
358+
return _unary_op("toTimestampLtz", args[0])
359359

360360
# For two arguments case (numeric + precision or string + format)
361361
elif len(args) == 2:
362-
return _binary_op("toTimestampLtz", lit(args[0]), lit(args[1]))
362+
return _binary_op("toTimestampLtz", args[0], args[1])
363363

364364
# For three arguments case (string + format + timezone)
365365
else:
366-
return _ternary_op("toTimestampLtz", lit(args[0]), lit(args[1]), lit(args[2]))
366+
return _ternary_op("toTimestampLtz", args[0], args[1], args[2])
367367

368368

369369
@PublicEvolving()

flink-python/pyflink/table/tests/test_expression.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ def test_expressions(self):
295295
self.assertEqual("TO_TIMESTAMP_LTZ('2023-01-01 00:00:00', 'yyyy-MM-dd HH:mm:ss', 'UTC')",
296296
str(to_timestamp_ltz("2023-01-01 00:00:00", "yyyy-MM-dd HH:mm:ss", "UTC")))
297297
self.assertEqual("TO_TIMESTAMP_LTZ(123, 0)", str(to_timestamp_ltz(123, 0)))
298+
self.assertEqual("TO_TIMESTAMP_LTZ(a)", str(to_timestamp_ltz(expr1)))
299+
self.assertEqual("TO_TIMESTAMP_LTZ(a, 0)", str(to_timestamp_ltz(expr1, 0)))
300+
self.assertEqual("TO_TIMESTAMP_LTZ(a, 'MM/dd/yyyy HH:mm:ss')",
301+
str(to_timestamp_ltz(expr1, "MM/dd/yyyy HH:mm:ss")))
302+
self.assertEqual("TO_TIMESTAMP_LTZ(a, 'MM/dd/yyyy HH:mm:ss', 'UTC')",
303+
str(to_timestamp_ltz(expr1, "MM/dd/yyyy HH:mm:ss", "UTC")))
298304
self.assertEqual("toTimestamp('1970-01-01 08:01:40')",
299305
str(to_timestamp('1970-01-01 08:01:40')))
300306
self.assertEqual("toTimestamp('1970-01-01 08:01:40', 'yyyy-MM-dd HH:mm:ss')",

0 commit comments

Comments
 (0)