Skip to content

Commit

Permalink
UDF: Add deregister method. (#591)
Browse files Browse the repository at this point in the history
- Adds udf.deregister method.
-  Refactors udf.delete method to work with URI.
  • Loading branch information
JohnMoutafis authored Jul 8, 2024
1 parent a9301ff commit 7e5d9e3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/tiledb/cloud/_common/testonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def register_udf(func: Callable, func_name: Optional[str] = None) -> Iterator[st
try:
yield f"{ns}/{func_name}"
finally:
udf.delete(func_name, ns)
udf.delete(uri=f"tiledb://{ns}/{func_name}")


def random_name(name: str) -> str:
Expand Down
41 changes: 37 additions & 4 deletions src/tiledb/cloud/udf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import uuid
import warnings
from logging import warning
from typing import Any, Callable, Iterable, Optional, Union

import cloudpickle
Expand Down Expand Up @@ -550,14 +551,32 @@ def unshare(name=None, namespace=None, async_req=False):
"""


def delete(name, namespace, async_req=False):
def delete(
uri: str, namespace: Optional[str] = None, *, async_req: bool = False
) -> None:
"""
Deletes a registered udf
:param name: name of udf
:param namespace: namespace the udf belongs to
:param async_req: return future instead of results for async support
:param uri: TileDB URI of the udf, defaults to None.
:param namespace: namespace the udf belongs to, defaults to None.
DEPRECATION WARNING: Will be deprecate from version 0.12.17
:param async_req: Return future instead of results for async support
:return: deleted udf details
"""
try:
namespace, name = utils.split_uri(uri)
except Exception as exc:
if str(exc).startswith("Incorrect"):
warning(
DeprecationWarning(
"From version 0.12.17 the method will accept"
"only `tiledb://<namespace>/<name>` URIs"
),
)
name = uri
else:
raise exc

try:
api_instance = client.build(rest_api.UdfApi)

Expand All @@ -570,6 +589,20 @@ def delete(name, namespace, async_req=False):
raise tiledb_cloud_error.check_exc(exc) from None


def deregister(uri: str, *, async_req: bool = False):
"""
De-registers a registered udf, by de-registering the array that it
is registered on.
This does not physically delete the array, it will remain in your bucket.
All access to the array and cloud metadata will be removed.
:param uri: TileDB URI of the array.
:param async_req: Return future instead of results for async support
:return success or error
"""
return array.deregister_array(uri=uri, async_req=async_req)


class _StoredParamJSONer(tiledb_json.Encoder):
"""Turns parameters passed to the existing UDF APIs into TileDB JSON.
Expand Down

0 comments on commit 7e5d9e3

Please sign in to comment.