From bea4674f9e3dc073d3528cca4152b02d06a18f88 Mon Sep 17 00:00:00 2001 From: Kaushik Kampli Date: Fri, 13 Jun 2025 20:37:52 +0530 Subject: [PATCH 1/4] return create functions in resp --- singlestoredb/functions/ext/asgi.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/singlestoredb/functions/ext/asgi.py b/singlestoredb/functions/ext/asgi.py index c8ff8f4f5..fdbab80de 100755 --- a/singlestoredb/functions/ext/asgi.py +++ b/singlestoredb/functions/ext/asgi.py @@ -964,6 +964,13 @@ def get_function_info( functions = {} no_default = object() + # Generate CREATE FUNCTION SQL for each function using get_create_functions + create_sqls = self.get_create_functions(replace=True) + sql_map = {} + for key, (_, info), sql in zip(self.endpoints.keys(), self.endpoints.values(), create_sqls): + sig = info['signature'] + sql_map[sig['name']] = sql + for key, (_, info) in self.endpoints.items(): if not func_name or key == func_name: sig = info['signature'] @@ -1002,7 +1009,10 @@ def get_function_info( returns[-1]['default'] = a['default'] functions[sig['name']] = dict( - args=args, returns=returns, function_type=info['function_type'], + args=args, + returns=returns, + function_type=info['function_type'], + sqlStatements=[sql_map[sig['name']]] if sig['name'] in sql_map else [], ) return functions From 3706593c924535a2cda726ee1b43e04392f6c063 Mon Sep 17 00:00:00 2001 From: Kaushik Kampli Date: Fri, 13 Jun 2025 20:37:52 +0530 Subject: [PATCH 2/4] return create functions in resp --- singlestoredb/functions/ext/asgi.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/singlestoredb/functions/ext/asgi.py b/singlestoredb/functions/ext/asgi.py index c8ff8f4f5..9d9f2bf18 100755 --- a/singlestoredb/functions/ext/asgi.py +++ b/singlestoredb/functions/ext/asgi.py @@ -964,6 +964,13 @@ def get_function_info( functions = {} no_default = object() + # Generate CREATE FUNCTION SQL for each function using get_create_functions + create_sqls = self.get_create_functions(replace=True) + sql_map = {} + for key, (_, info), sql in zip(self.endpoints.keys(), self.endpoints.values(), create_sqls): + sig = info['signature'] + sql_map[sig['name']] = sql + for key, (_, info) in self.endpoints.items(): if not func_name or key == func_name: sig = info['signature'] @@ -1002,7 +1009,10 @@ def get_function_info( returns[-1]['default'] = a['default'] functions[sig['name']] = dict( - args=args, returns=returns, function_type=info['function_type'], + args=args, + returns=returns, + function_type=info['function_type'], + sql_statement=sql_map[sig['name']] if sig['name'] in sql_map else None, ) return functions From 58bb7e592ae28d92e32061de42eefe770e189f85 Mon Sep 17 00:00:00 2001 From: Kaushik Kampli Date: Wed, 18 Jun 2025 11:35:51 +0530 Subject: [PATCH 3/4] register on interactive --- singlestoredb/apps/_python_udfs.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/singlestoredb/apps/_python_udfs.py b/singlestoredb/apps/_python_udfs.py index bcbc7a61c..aca702f67 100644 --- a/singlestoredb/apps/_python_udfs.py +++ b/singlestoredb/apps/_python_udfs.py @@ -55,8 +55,9 @@ async def run_udf_app( ) _running_server = AwaitableUvicornServer(config) - # Register the functions - app.register_functions(replace=replace_existing) + # Register the functions only if the app is running interactively. + if app_config.running_interactively: + app.register_functions(replace=replace_existing) asyncio.create_task(_running_server.serve()) await _running_server.wait_for_startup() From a01f9ae8910acca6ffa2eab54510758909c3e762 Mon Sep 17 00:00:00 2001 From: Kaushik Kampli Date: Tue, 24 Jun 2025 21:56:47 +0530 Subject: [PATCH 4/4] remove replace_existing --- singlestoredb/apps/_python_udfs.py | 3 +-- singlestoredb/functions/ext/asgi.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/singlestoredb/apps/_python_udfs.py b/singlestoredb/apps/_python_udfs.py index aca702f67..d7bca6d6b 100644 --- a/singlestoredb/apps/_python_udfs.py +++ b/singlestoredb/apps/_python_udfs.py @@ -15,7 +15,6 @@ async def run_udf_app( - replace_existing: bool, log_level: str = 'error', kill_existing_app_server: bool = True, ) -> UdfConnectionInfo: @@ -57,7 +56,7 @@ async def run_udf_app( # Register the functions only if the app is running interactively. if app_config.running_interactively: - app.register_functions(replace=replace_existing) + app.register_functions(replace=True) asyncio.create_task(_running_server.serve()) await _running_server.wait_for_startup() diff --git a/singlestoredb/functions/ext/asgi.py b/singlestoredb/functions/ext/asgi.py index f5a6eb302..97997ffc9 100755 --- a/singlestoredb/functions/ext/asgi.py +++ b/singlestoredb/functions/ext/asgi.py @@ -967,7 +967,7 @@ def get_function_info( # Generate CREATE FUNCTION SQL for each function using get_create_functions create_sqls = self.get_create_functions(replace=True) sql_map = {} - for key, (_, info), sql in zip(self.endpoints.keys(), self.endpoints.values(), create_sqls): + for (_, info), sql in zip(self.endpoints.values(), create_sqls): sig = info['signature'] sql_map[sig['name']] = sql @@ -1013,7 +1013,7 @@ def get_function_info( args=args, returns=returns, function_type=info['function_type'], - sql_statement= sql, + sql_statement=sql, ) return functions