From 1fba317e2c71aac359aab528c0aad5e36add74ab Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Tue, 23 Apr 2024 18:32:25 +0300 Subject: [PATCH] Migrate use of two deprecated APIs. --- tiledb/libtiledb.pxd | 9 +++++-- tiledb/libtiledb.pyx | 57 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/tiledb/libtiledb.pxd b/tiledb/libtiledb.pxd index c15b4941cc..3b88ecf121 100644 --- a/tiledb/libtiledb.pxd +++ b/tiledb/libtiledb.pxd @@ -651,9 +651,8 @@ cdef extern from "tiledb/tiledb.h": uint32_t key_length, tiledb_config_t* config) nogil - int tiledb_array_delete_array( + int tiledb_array_delete( tiledb_ctx_t* ctx, - tiledb_array_t* array, const char* uri) nogil # Query @@ -879,6 +878,12 @@ cdef extern from "tiledb/tiledb.h": uint64_t timestamp_start, uint64_t timestamp_end) + int tiledb_array_delete_fragments_v2( + tiledb_ctx_t* ctx, + const char* uri, + uint64_t timestamp_start, + uint64_t timestamp_end) + int tiledb_array_get_schema( tiledb_ctx_t* ctx, tiledb_array_t* array, diff --git a/tiledb/libtiledb.pyx b/tiledb/libtiledb.pyx index 0781a03b5f..1250649ec7 100644 --- a/tiledb/libtiledb.pyx +++ b/tiledb/libtiledb.pyx @@ -1278,6 +1278,10 @@ cdef class Array(object): array([0., 0., 0., 0.]) """ + warnings.warn( + "The `tiledb.Array.delete_fragments` instance method is deprecated. Use the static method with the same name instead.", + DeprecationWarning, + ) cdef tiledb_ctx_t* ctx_ptr = safe_ctx_ptr(self.ctx) cdef tiledb_array_t* array_ptr = self.ptr cdef tiledb_query_t* query_ptr = NULL @@ -1295,6 +1299,55 @@ cdef class Array(object): if rc != TILEDB_OK: _raise_ctx_err(ctx_ptr, rc) + @staticmethod + def delete_fragments(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. + + :param timestamp_start: the first fragment to delete in the range + :type timestamp_start: int + :param timestamp_end: the last fragment to delete in the range + :type timestamp_end: int + + **Example:** + + >>> import tiledb, tempfile, numpy as np + >>> path = tempfile.mkdtemp() + + >>> with tiledb.from_numpy(path, np.zeros(4), timestamp=1) as A: + ... pass + >>> with tiledb.open(path, 'w', timestamp=2) as A: + ... A[:] = np.ones(4, dtype=np.int64) + + >>> with tiledb.open(path, 'r') as A: + ... A[:] + array([1., 1., 1., 1.]) + + >>> tiledb.Array.delete_fragments(path, 2, 2) + + >>> with tiledb.open(path, 'r') as A: + ... A[:] + array([0., 0., 0., 0.]) + + """ + if not ctx: + ctx = default_ctx() + + cdef tiledb_ctx_t* ctx_ptr = safe_ctx_ptr(ctx) + cdef bytes buri = uri.encode('UTF-8') + + cdef int rc = TILEDB_OK + + rc = tiledb_array_delete_fragments_v2( + ctx_ptr, + buri, + timestamp_start, + timestamp_end + ) + if rc != TILEDB_OK: + _raise_ctx_err(ctx_ptr, rc) + @staticmethod def delete_array(uri, ctx=None): """ @@ -1324,12 +1377,10 @@ cdef class Array(object): cdef tiledb_ctx_t* ctx_ptr = safe_ctx_ptr(ctx) cdef bytes buri = uri.encode('UTF-8') - cdef ArrayPtr preload_ptr = preload_array(uri, 'm', None, None) - cdef tiledb_array_t* array_ptr = preload_ptr.ptr cdef int rc = TILEDB_OK - rc = tiledb_array_delete_array(ctx_ptr, array_ptr, buri) + rc = tiledb_array_delete(ctx_ptr, buri) if rc != TILEDB_OK: _raise_ctx_err(ctx_ptr, rc)