Skip to content

Commit b40fb15

Browse files
kesmit13psachdeva-ss
authored andcommitted
Add prefix / suffix for function names
1 parent 1d61e10 commit b40fb15

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
@@ -506,6 +506,8 @@ def __init__(
506506
link_name: Optional[str] = get_option('external_function.link_name'),
507507
link_config: Optional[Dict[str, Any]] = None,
508508
link_credentials: Optional[Dict[str, Any]] = None,
509+
name_prefix: str = get_option('external_function.name_prefix'),
510+
name_suffix: str = get_option('external_function.name_suffix'),
509511
) -> None:
510512
if link_name and (link_config or link_credentials):
511513
raise ValueError(
@@ -562,6 +564,7 @@ def __init__(
562564
if not hasattr(x, '_singlestoredb_attrs'):
563565
continue
564566
name = x._singlestoredb_attrs.get('name', x.__name__)
567+
name = f'{name_prefix}{name}{name_suffix}'
565568
external_functions[x.__name__] = x
566569
func, info = make_func(name, x)
567570
endpoints[name.encode('utf-8')] = func, info
@@ -577,6 +580,7 @@ def __init__(
577580
# Add endpoint for each exported function
578581
for name, alias in get_func_names(func_names):
579582
item = getattr(pkg, name)
583+
alias = f'{name_prefix}{name}{name_suffix}'
580584
external_functions[name] = item
581585
func, info = make_func(alias, item)
582586
endpoints[alias.encode('utf-8')] = func, info
@@ -589,12 +593,14 @@ def __init__(
589593
if not hasattr(x, '_singlestoredb_attrs'):
590594
continue
591595
name = x._singlestoredb_attrs.get('name', x.__name__)
596+
name = f'{name_prefix}{name}{name_suffix}'
592597
external_functions[x.__name__] = x
593598
func, info = make_func(name, x)
594599
endpoints[name.encode('utf-8')] = func, info
595600

596601
else:
597602
alias = funcs.__name__
603+
alias = f'{name_prefix}{alias}{name_suffix}'
598604
external_functions[funcs.__name__] = funcs
599605
func, info = make_func(alias, funcs)
600606
endpoints[alias.encode('utf-8')] = func, info
@@ -1205,6 +1211,22 @@ def main(argv: Optional[List[str]] = None) -> None:
12051211
),
12061212
help='logging level',
12071213
)
1214+
parser.add_argument(
1215+
'--name-prefix', metavar='name_prefix',
1216+
default=defaults.get(
1217+
'name_prefix',
1218+
get_option('external_function.name_prefix'),
1219+
),
1220+
help='Prefix to add to function names',
1221+
)
1222+
parser.add_argument(
1223+
'--name-suffix', metavar='name_suffix',
1224+
default=defaults.get(
1225+
'name_suffix',
1226+
get_option('external_function.name_suffix'),
1227+
),
1228+
help='Suffix to add to function names',
1229+
)
12081230
parser.add_argument(
12091231
'functions', metavar='module.or.func.path', nargs='*',
12101232
help='functions or modules to export in UDF server',
@@ -1297,6 +1319,8 @@ def main(argv: Optional[List[str]] = None) -> None:
12971319
link_config=json.loads(args.link_config) or None,
12981320
link_credentials=json.loads(args.link_credentials) or None,
12991321
app_mode='remote',
1322+
name_prefix=args.name_prefix,
1323+
name_suffix=args.name_suffix,
13001324
)
13011325

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

0 commit comments

Comments
 (0)