bgeng777 commented on code in PR #27438:
URL: https://github.com/apache/flink/pull/27438#discussion_r2757018777


##########
flink-python/pyflink/table/tests/test_async_scalar_function.py:
##########
@@ -0,0 +1,285 @@
+################################################################################
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+################################################################################
+import asyncio
+import uuid
+
+from pyflink.table import DataTypes
+from pyflink.table.udf import AsyncScalarFunction, udf, FunctionContext
+from pyflink.testing import source_sink_utils
+from pyflink.testing.test_case_utils import PyFlinkStreamTableTestCase, 
run_with_config
+
+
+def generate_random_table_name():
+    return "Table{0}".format(str(uuid.uuid1()).replace("-", "_"))
+
+
+class AsyncScalarFunctionTests(PyFlinkStreamTableTestCase):
+    """
+    Integration tests for Python Async Scalar Function.
+    """
+
+    def test_basic_async_scalar_function(self):
+
+        class AsyncFunctionWithLifecycle(AsyncScalarFunction):
+            def open(self, function_context: FunctionContext):
+                self.prefix = "opened_"
+
+            async def eval(self, value):
+                await asyncio.sleep(0.001)
+                return self.prefix + value
+
+            def close(self):
+                pass
+
+        async_func = udf(
+            AsyncFunctionWithLifecycle(),
+            input_types=[DataTypes.STRING()],
+            result_type=DataTypes.STRING()
+        )
+
+        sink_table = generate_random_table_name()
+        self.t_env.execute_sql(f"""
+            CREATE TABLE {sink_table}(a STRING, b STRING)
+            WITH ('connector'='test-sink')
+        """)
+
+        t = self.t_env.from_elements([("test1",), ("test2",)], ['a'])
+        t.select(t.a, 
async_func(t.a).alias('b')).execute_insert(sink_table).wait()
+
+        actual = source_sink_utils.results()
+        self.assert_equals(actual, [
+            "+I[test1, opened_test1]",
+            "+I[test2, opened_test2]"
+        ])
+
+    def test_raise_exception_in_async_eval(self):
+        """Test async scalar function that raises exception during 
evaluation."""
+
+        class ExceptionAsyncFunction(AsyncScalarFunction):
+            async def eval(self, value: str) -> str:
+                raise ValueError("Test exception in async eval")
+
+        async_func = udf(
+            ExceptionAsyncFunction(),
+            input_types=[DataTypes.STRING()],
+            result_type=DataTypes.STRING()
+        )
+
+        sink_table = generate_random_table_name()
+        self.t_env.execute_sql(f"""
+            CREATE TABLE {sink_table}(a STRING, b STRING)
+            WITH ('connector'='test-sink')
+        """)
+
+        t = self.t_env.from_elements([("test1",)], ['a'])
+
+        with self.assertRaises(Exception) as context:
+            t.select(t.a, 
async_func(t.a).alias('b')).execute_insert(sink_table).wait()
+
+        # Verify exception message is propagated
+        self.assertIn("Test exception in async eval", str(context.exception))
+
+    def test_async_function_with_retry_logic(self):
+        """Test async scalar function with custom retry logic."""

Review Comment:
   I found `table.exec.async-scalar.retry-strategy`'s default value is 
`FIXED_DELAY`. I may get this mixed up with datastream api. Ignore the previous 
comment. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to