Skip to content

Commit 52dd5cd

Browse files
committed
Add prefix / suffix for function names
1 parent 7aad0b1 commit 52dd5cd

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

singlestoredb/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@
407407
environ=['SINGLESTOREDB_EXT_FUNC_LOG_LEVEL'],
408408
)
409409

410+
register_option(
411+
'external_function.name_prefix', 'string', check_str, '',
412+
'Prefix to add to external function names.',
413+
environ=['SINGLESTOREDB_EXT_FUNC_NAME_PREFIX'],
414+
)
415+
416+
register_option(
417+
'external_function.name_suffix', 'string', check_str, '',
418+
'Suffix to add to external function names.',
419+
environ=['SINGLESTOREDB_EXT_FUNC_NAME_SUFFIX'],
420+
)
421+
410422
register_option(
411423
'external_function.connection', 'string', check_str,
412424
os.environ.get('SINGLESTOREDB_URL') or None,

singlestoredb/functions/ext/asgi.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ def __init__(
489489
link_name: Optional[str] = get_option('external_function.link_name'),
490490
link_config: Optional[Dict[str, Any]] = None,
491491
link_credentials: Optional[Dict[str, Any]] = None,
492+
name_prefix: str = get_option('external_function.name_prefix'),
493+
name_suffix: str = get_option('external_function.name_suffix'),
492494
) -> None:
493495
if link_name and (link_config or link_credentials):
494496
raise ValueError(
@@ -545,6 +547,7 @@ def __init__(
545547
if not hasattr(x, '_singlestoredb_attrs'):
546548
continue
547549
name = x._singlestoredb_attrs.get('name', x.__name__)
550+
name = f'{name_prefix}{name}{name_suffix}'
548551
external_functions[x.__name__] = x
549552
func, info = make_func(name, x)
550553
endpoints[name.encode('utf-8')] = func, info
@@ -560,6 +563,7 @@ def __init__(
560563
# Add endpoint for each exported function
561564
for name, alias in get_func_names(func_names):
562565
item = getattr(pkg, name)
566+
alias = f'{name_prefix}{name}{name_suffix}'
563567
external_functions[name] = item
564568
func, info = make_func(alias, item)
565569
endpoints[alias.encode('utf-8')] = func, info
@@ -572,12 +576,14 @@ def __init__(
572576
if not hasattr(x, '_singlestoredb_attrs'):
573577
continue
574578
name = x._singlestoredb_attrs.get('name', x.__name__)
579+
name = f'{name_prefix}{name}{name_suffix}'
575580
external_functions[x.__name__] = x
576581
func, info = make_func(name, x)
577582
endpoints[name.encode('utf-8')] = func, info
578583

579584
else:
580585
alias = funcs.__name__
586+
alias = f'{name_prefix}{alias}{name_suffix}'
581587
external_functions[funcs.__name__] = funcs
582588
func, info = make_func(alias, funcs)
583589
endpoints[alias.encode('utf-8')] = func, info
@@ -1188,6 +1194,22 @@ def main(argv: Optional[List[str]] = None) -> None:
11881194
),
11891195
help='logging level',
11901196
)
1197+
parser.add_argument(
1198+
'--name-prefix', metavar='name_prefix',
1199+
default=defaults.get(
1200+
'name_prefix',
1201+
get_option('external_function.name_prefix'),
1202+
),
1203+
help='Prefix to add to function names',
1204+
)
1205+
parser.add_argument(
1206+
'--name-suffix', metavar='name_suffix',
1207+
default=defaults.get(
1208+
'name_suffix',
1209+
get_option('external_function.name_suffix'),
1210+
),
1211+
help='Suffix to add to function names',
1212+
)
11911213
parser.add_argument(
11921214
'functions', metavar='module.or.func.path', nargs='*',
11931215
help='functions or modules to export in UDF server',
@@ -1280,6 +1302,8 @@ def main(argv: Optional[List[str]] = None) -> None:
12801302
link_config=json.loads(args.link_config) or None,
12811303
link_credentials=json.loads(args.link_credentials) or None,
12821304
app_mode='remote',
1305+
name_prefix=args.name_prefix,
1306+
name_suffix=args.name_suffix,
12831307
)
12841308

12851309
funcs = app.get_create_functions(replace=args.replace_existing)

0 commit comments

Comments
 (0)