Skip to content

Commit 21d7a03

Browse files
authored
[FLINK-37457][python] Support asArgument in Python Table API
1 parent 3dde255 commit 21d7a03

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

flink-python/docs/reference/pyflink.table/expressions.rst

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ arithmetic functions
140140
Expression.collect
141141
Expression.array_agg
142142
Expression.alias
143+
Expression.as_argument
143144
Expression.cast
144145
Expression.try_cast
145146
Expression.asc

flink-python/pyflink/table/expression.py

+25
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,31 @@ def alias(self, name: str, *extra_names: str) -> 'Expression[T]':
859859
gateway = get_gateway()
860860
return _ternary_op("as")(self, name, to_jarray(gateway.jvm.String, extra_names))
861861

862+
def as_argument(self, name: str) -> 'Expression':
863+
"""
864+
Converts this expression into a named argument.
865+
866+
If the function declares a static signature (usually indicated by the "=>" assignment
867+
operator), the framework is able to reorder named arguments and consider optional arguments
868+
accordingly, before passing them into the function call.
869+
870+
.. note::
871+
Not every function supports named arguments. Named arguments are not available for
872+
signatures that are overloaded, use varargs, or any other kind of input type strategy.
873+
874+
Example:
875+
::
876+
877+
>>> table.select(
878+
... call(
879+
... "MyFunction",
880+
... col("my_column").as_argument("input"),
881+
... lit(42).as_argument("threshold")
882+
... )
883+
... )
884+
"""
885+
return _binary_op("asArgument")(self, name)
886+
862887
def cast(self, data_type: DataType) -> 'Expression':
863888
"""
864889
Returns a new value being cast to type type.

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

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def test_expression(self):
132132
self.assertEqual('PERCENTILE(a, array(0.1, 0.5))', str(expr1.percentile(array(0.1, 0.5))))
133133
self.assertEqual('PERCENTILE(a, array(0.1, 0.5), b)',
134134
str(expr1.percentile(array(0.1, 0.5), expr2)))
135+
self.assertEqual("ASSIGNMENT('a2', a)", str(expr1.as_argument('a2')))
136+
self.assertEqual("ASSIGNMENT('a', 10)", str(expr5.as_argument('a')))
135137

136138
# string functions
137139
self.assertEqual('substring(a, b)', str(expr1.substring(expr2)))

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

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def excluded_methods(cls):
5858
'times',
5959
'mod',
6060
'power',
61-
'asArgument',
6261
}
6362

6463
@classmethod

0 commit comments

Comments
 (0)