Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility fix: delete_fragments #1966

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tiledb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
FragmentsInfo,
copy_fragments_to_existing_array,
create_array_from_fragments,
delete_fragments,
)
from .group import Group
from .highlevel import (
Expand Down
22 changes: 0 additions & 22 deletions tiledb/fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,28 +341,6 @@ def FragmentsInfo(array_uri, ctx=None):
)


def delete_fragments(
uri, timestamp_range, config=None, ctx=None, verbose=False, dry_run=False
):
"""
Delete fragments from an array located at uri that falls within a given
timestamp_range.

:param str uri: URI for the TileDB array (any supported TileDB URI)
:param (int, int) timestamp_range: (default None) If not None, vacuum the
array using the given range (inclusive)
:param config: Override the context configuration. Defaults to ctx.config()
:param ctx: (optional) TileDB Ctx
:param verbose: (optional) Print fragments being deleted (default: False)
:param dry_run: (optional) Preview fragments to be deleted without
running (default: False)
"""
raise tiledb.TileDBError(
"tiledb.delete_fragments is deprecated; you must use Array.delete_fragments. "
"This message will be removed in 0.21.0."
)


def create_array_from_fragments(
src_uri,
dst_uri,
Expand Down
54 changes: 34 additions & 20 deletions tiledb/libtiledb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ from json import loads as json_loads
from ._generated_version import version_tuple as tiledbpy_version
from .array_schema import ArraySchema
from .enumeration import Enumeration
from .cc import TileDBError
from .cc import TileDBError
from .ctx import Config, Ctx, default_ctx
from .vfs import VFS

Expand Down Expand Up @@ -1263,8 +1263,7 @@ cdef class Array(object):
_raise_ctx_err(ctx_ptr, rc)
return Enumeration.from_capsule(self.ctx, PyCapsule_New(enum_ptr, "enum", NULL))

@staticmethod
def delete_fragments(uri, timestamp_start, timestamp_end, ctx=None):
def delete_fragments(self_or_uri, timestamp_start, timestamp_end, ctx=None):
"""
Delete a range of fragments from timestamp_start to timestamp_end.
The array needs to be opened in 'm' mode as shown in the example below.
Expand Down Expand Up @@ -1295,28 +1294,43 @@ cdef class Array(object):
array([0., 0., 0., 0.])

"""
# If uri is an instance of Array (user calls the old instance method), issue a warning
if isinstance(uri, Array):
cdef tiledb_ctx_t* ctx_ptr
cdef tiledb_array_t* array_ptr
cdef tiledb_query_t* query_ptr
cdef bytes buri
cdef int rc = TILEDB_OK

if isinstance(self_or_uri, str):
uri = self_or_uri
if not ctx:
ctx = default_ctx()

ctx_ptr = safe_ctx_ptr(ctx)
buri = uri.encode('UTF-8')

rc = tiledb_array_delete_fragments_v2(
ctx_ptr,
buri,
timestamp_start,
timestamp_end
)
else:
array_instance = self_or_uri
warnings.warn(
"The `tiledb.Array.delete_fragments` instance method is deprecated. Use the static method with the same name instead.",
DeprecationWarning,
)
uri = uri.uri

if not ctx:
ctx = default_ctx()

cdef tiledb_ctx_t* ctx_ptr = safe_ctx_ptr(ctx)
cdef bytes buri = uri.encode('UTF-8')
ctx_ptr = safe_ctx_ptr(array_instance.ctx)
array_ptr = <tiledb_array_t*>array_instance.ptr
buri = array_instance.uri.encode('UTF-8')

cdef int rc = TILEDB_OK

rc = tiledb_array_delete_fragments_v2(
ctx_ptr,
buri,
timestamp_start,
timestamp_end
)
rc = tiledb_array_delete_fragments(
ctx_ptr,
array_ptr,
buri,
timestamp_start,
timestamp_end
)
if rc != TILEDB_OK:
_raise_ctx_err(ctx_ptr, rc)

Expand Down
Loading