Skip to content

Commit 4dc4ead

Browse files
committed
Add support for table / dataframe return values in ext functions
1 parent 8875d66 commit 4dc4ead

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

singlestoredb/functions/ext/asgi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ async def do_func( # type: ignore
192192

193193
out_ids, out = [], []
194194
res = func(*[x[0] for x in cols])
195+
rtype = str(type(res)).lower()
196+
197+
# Map tables / dataframes to a list of columns
198+
if 'dataframe' in rtype:
199+
res = [res[x] for x in res.columns]
200+
elif 'table' in rtype:
201+
res = res.columns
202+
195203
for vec in res:
196204
# C extension only supports Python objects as strings
197205
if data_format == 'numpy' and str(vec.dtype)[:2] in ['<U', '<S']:
@@ -239,9 +247,14 @@ async def do_func( # type: ignore
239247
out = func(*cols)
240248
assert isinstance(out, tuple)
241249
return row_ids, [out]
250+
242251
out = func(*[x[0] for x in cols])
252+
253+
# Multiple return values
243254
if isinstance(out, tuple):
244255
return row_ids, [(x, None) for x in out]
256+
257+
# Single return value
245258
return row_ids, [(out, None)]
246259

247260
do_func.__name__ = name

0 commit comments

Comments
 (0)