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

Support fragment deletion by uri vector #734

Merged
merged 2 commits into from
Jul 19, 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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tiledb
Type: Package
Version: 0.28.2.1
Version: 0.28.2.2
Title: Modern Database Engine for Complex Data Based on Multi-Dimensional Arrays
Authors@R: c(person("TileDB, Inc.", role = c("aut", "cph")),
person("Dirk", "Eddelbuettel", email = "dirk@tiledb.com", role = "cre"))
Expand All @@ -27,5 +27,5 @@ LinkingTo: Rcpp, RcppInt64, nanoarrow
Suggests: tinytest, simplermarkdown, curl, bit64, Matrix, palmerpenguins, nycflights13, data.table, tibble, arrow
VignetteBuilder: simplermarkdown
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Encoding: UTF-8
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export(tiledb_array_apply_aggregate)
export(tiledb_array_close)
export(tiledb_array_create)
export(tiledb_array_delete_fragments)
export(tiledb_array_delete_fragments_list)
export(tiledb_array_get_non_empty_domain_from_index)
export(tiledb_array_get_non_empty_domain_from_name)
export(tiledb_array_has_enumeration)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

* The vendored [nanoarrow](https://github.com/apache/arrow-nanoarrow) has been updated to its release [0.5.0](https://github.com/apache/arrow-nanoarrow/releases/tag/apache-arrow-nanoarrow-0.5.0) (#733)

* Fragments can now be removed by supplying a vector of fragment URIs (#734)

## Build and Test Systems

* The nighly valgrind matrix now includes release 2.25.0 (#729)
Expand Down
18 changes: 18 additions & 0 deletions R/Array.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@ tiledb_array_delete_fragments <- function(arr, ts_start, ts_end, ctx = tiledb_ge
invisible(TRUE)
}

##' Delete fragments written given by their URIs
##'
##' @param arr A TileDB Array object as for example returned by \code{tiledb_array()}
##' @param fragments A character vector with fragment URIs
##' @param ctx A tiledb_ctx object (optional)
##' @return A boolean indicating success
##' @export
tiledb_array_delete_fragments_list <- function(arr, fragments, ctx = tiledb_get_context()) {
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr),
"The 'fragments' argument must be a character vector" = is.character(fragments))
if (tiledb_version(TRUE) >= "2.18.0") {
libtiledb_array_delete_fragments_list(ctx@ptr, arr@ptr, fragments)
} else {
message("This function is only available with TileDB 2.18.0 or later")
}
invisible(TRUE)
}

##' Check for Enumeration (aka Factor aka Dictionary)
##'
##' @param arr A TileDB Array object
Expand Down
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ libtiledb_array_delete_fragments <- function(ctx, array, tstamp_start, tstamp_en
invisible(.Call(`_tiledb_libtiledb_array_delete_fragments`, ctx, array, tstamp_start, tstamp_end))
}

libtiledb_array_delete_fragments_list <- function(ctx, array, fragments) {
invisible(.Call(`_tiledb_libtiledb_array_delete_fragments_list`, ctx, array, fragments))
}

libtiledb_array_has_enumeration <- function(ctx, arr, name) {
.Call(`_tiledb_libtiledb_array_has_enumeration`, ctx, arr, name)
}
Expand Down
57 changes: 57 additions & 0 deletions inst/tinytest/test_fragmentinfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,60 @@ expect_true(nchar(tiledb_fragment_info_get_to_vacuum_uri(fraginf, 0)) > 20)
expect_true(nchar(tiledb_fragment_info_get_to_vacuum_uri(fraginf, 1)) > 20)
expect_false(tiledb_fragment_info_has_consolidated_metadata(fraginf, 0))
expect_equal(tiledb_fragment_info_get_unconsolidated_metadata_num(fraginf), 1)



## fragment info deletion tests (for TileDB 2.18.0 or later)

if (tiledb_version(TRUE) < "2.18.0") exit_file("Remainder needs 2.18.* or later")


uri <- tempfile()
if (dir.exists(uri)) unlink(uri, TRUE)

makeSimpleArray <- function(uri) {
## Create a simple two-column data.frame and write chunks of it
D <- data.frame(key = seq(1, 26), val = letters)
fromDataFrame(D[1:2,], uri, mode = "ingest", timestamps = as.POSIXct(1))
fromDataFrame(D[3:4,], uri, mode = "append", timestamps = as.POSIXct(2))
fromDataFrame(D[5:6,], uri, mode = "append", timestamps = as.POSIXct(3))
fromDataFrame(D[7:7,], uri, mode = "append", timestamps = as.POSIXct(4))
tiledb_array(uri)

}
arr <- makeSimpleArray(uri)

### check we have four fragments
expect_silent(fi <- tiledb_fragment_info(uri))
expect_equal(tiledb_fragment_info_get_num(fi), 4)


## delete from 1 to 2 leaving two
expect_silent(tiledb_array_delete_fragments(arr, as.POSIXct(1), as.POSIXct(2)))
expect_silent(fi <- tiledb_fragment_info(uri))
expect_equal(tiledb_fragment_info_get_num(fi), 2)

## delete at 4 leaving one
expect_silent(tiledb_array_delete_fragments(arr, as.POSIXct(4), as.POSIXct(4)))
expect_silent(fi <- tiledb_fragment_info(uri))
expect_equal(tiledb_fragment_info_get_num(fi), 1)

if (dir.exists(uri)) unlink(uri, TRUE)
arr <- makeSimpleArray(uri)

expect_silent(fi <- tiledb_fragment_info(uri))
expect_equal(tiledb_fragment_info_get_num(fi), 4)
expect_silent(fi <- tiledb_fragment_info(uri))
## no function to fetch the vector at once so build it
uris <- sapply(1:4, \(i) tiledb:::libtiledb_fragment_info_uri(fi@ptr, i-1))
expect_equal(length(uris), 4)

## delete from 1 to 2 leaving two
expect_silent(tiledb_array_delete_fragments_list(arr, uris[1:2]))
expect_silent(fi <- tiledb_fragment_info(uri))
expect_equal(tiledb_fragment_info_get_num(fi), 2)

## delete at 4 leaving one
expect_silent(tiledb_array_delete_fragments_list(arr, uris[4]))
expect_silent(fi <- tiledb_fragment_info(uri))
expect_equal(tiledb_fragment_info_get_num(fi), 1)
21 changes: 21 additions & 0 deletions man/tiledb_array_delete_fragments_list.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,18 @@ BEGIN_RCPP
return R_NilValue;
END_RCPP
}
// libtiledb_array_delete_fragments_list
void libtiledb_array_delete_fragments_list(XPtr<tiledb::Context> ctx, XPtr<tiledb::Array> array, std::vector<std::string> fragments);
RcppExport SEXP _tiledb_libtiledb_array_delete_fragments_list(SEXP ctxSEXP, SEXP arraySEXP, SEXP fragmentsSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< XPtr<tiledb::Context> >::type ctx(ctxSEXP);
Rcpp::traits::input_parameter< XPtr<tiledb::Array> >::type array(arraySEXP);
Rcpp::traits::input_parameter< std::vector<std::string> >::type fragments(fragmentsSEXP);
libtiledb_array_delete_fragments_list(ctx, array, fragments);
return R_NilValue;
END_RCPP
}
// libtiledb_array_has_enumeration
bool libtiledb_array_has_enumeration(XPtr<tiledb::Context> ctx, XPtr<tiledb::Array> arr, const std::string name);
RcppExport SEXP _tiledb_libtiledb_array_has_enumeration(SEXP ctxSEXP, SEXP arrSEXP, SEXP nameSEXP) {
Expand Down Expand Up @@ -3707,6 +3719,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_tiledb_libtiledb_array_set_open_timestamp_end", (DL_FUNC) &_tiledb_libtiledb_array_set_open_timestamp_end, 2},
{"_tiledb_libtiledb_array_open_timestamp_end", (DL_FUNC) &_tiledb_libtiledb_array_open_timestamp_end, 1},
{"_tiledb_libtiledb_array_delete_fragments", (DL_FUNC) &_tiledb_libtiledb_array_delete_fragments, 4},
{"_tiledb_libtiledb_array_delete_fragments_list", (DL_FUNC) &_tiledb_libtiledb_array_delete_fragments_list, 3},
{"_tiledb_libtiledb_array_has_enumeration", (DL_FUNC) &_tiledb_libtiledb_array_has_enumeration, 3},
{"_tiledb_libtiledb_array_get_enumeration", (DL_FUNC) &_tiledb_libtiledb_array_get_enumeration, 3},
{"_tiledb_libtiledb_array_has_enumeration_vector", (DL_FUNC) &_tiledb_libtiledb_array_has_enumeration_vector, 2},
Expand Down
16 changes: 16 additions & 0 deletions src/libtiledb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2778,6 +2778,22 @@ void libtiledb_array_delete_fragments(XPtr<tiledb::Context> ctx, XPtr<tiledb::Ar
#endif
}

// [[Rcpp::export]]
void libtiledb_array_delete_fragments_list(XPtr<tiledb::Context> ctx, XPtr<tiledb::Array> array,
std::vector<std::string> fragments) {
check_xptr_tag<tiledb::Context>(ctx);
check_xptr_tag<tiledb::Array>(array);
const std::string uri = array->uri();
size_t n = fragments.size();
std::vector<const char*> frags(n);
for (size_t i = 0; i < n; i++) {
frags[i] = fragments[i].c_str();
}
#if TILEDB_VERSION >= TileDB_Version(2,18,0)
tiledb::Array::delete_fragments_list(*ctx.get(), uri, &frags[0], n);
#endif
}

// [[Rcpp::export]]
bool libtiledb_array_has_enumeration(XPtr<tiledb::Context> ctx,
XPtr<tiledb::Array> arr,
Expand Down