Skip to content

Commit

Permalink
Support deletion of groups (#702)
Browse files Browse the repository at this point in the history
* Add group_delete and tests

* Additional conditioning on minimal versions

* Increase micro version, update news, rebase
eddelbuettel authored May 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f76f34e commit 2246ec8
Showing 10 changed files with 110 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tiledb
Type: Package
Version: 0.26.0.3
Version: 0.26.0.4
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"))
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -192,6 +192,7 @@ export(tiledb_group)
export(tiledb_group_add_member)
export(tiledb_group_close)
export(tiledb_group_create)
export(tiledb_group_delete)
export(tiledb_group_delete_metadata)
export(tiledb_group_get_all_metadata)
export(tiledb_group_get_config)
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@

* This release of the R package builds against [TileDB 2.23.0-rc0](https://github.com/TileDB-Inc/TileDB/releases/tag/2.23.0-rc0), and has also been tested against earlier releases as well as the development version (#701)

## Improvements

* Group elements can now be deleted (#702)

## Build and Test Systems

* The test files receives a minor refactoring absorbing two files (#698)
32 changes: 28 additions & 4 deletions R/Group.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2022 TileDB Inc.
# Copyright (c) 2022-2024 TileDB Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -59,12 +59,15 @@ tiledb_group <- function(uri, type = c("READ", "WRITE"),
##' Open a TileDB Group
##'
##' @param grp A TileDB Group object as for example returned by \code{tiledb_group()}
##' @param type A character value that must be either \sQuote{READ} or \sQuote{WRITE}
##' @param type A character value that must be either \sQuote{READ}, \sQuote{WRITE}
##' or \sQuote{MODIFY_EXCLUSIVE}
##' @return The TileDB Group object but opened for reading or writing
##' @export
tiledb_group_open <- function(grp, type=c("READ","WRITE")) {
tiledb_group_open <- function(grp, type=c("READ","WRITE","MODIFY_EXCLUSIVE")) {
stopifnot("The 'grp' argument must be a tiledb_group object" = is(grp, "tiledb_group"),
"This function needs TileDB 2.8.*" = .tiledb28())
"This function needs TileDB 2.8.*" = .tiledb28(),
"Using 'MODIFY_EXCLUSIVE' needs TileDB 2.12.* or later" =
type != "MODIFY_EXCLUSIVE" || tiledb_version(TRUE) >= "2.12.0")
type <- match.arg(type)
grp@ptr <- libtiledb_group_open(grp@ptr, type)
grp
@@ -358,3 +361,24 @@ tiledb_group_is_relative <- function(grp, name) {
setMethod("show", signature(object = "tiledb_group"), function(object) {
cat(libtiledb_group_dump(object@ptr, FALSE))
})


#' Deletes all written data from a 'tiledb_group' object
#'
#' The group must be opened in \sQuote{MODIFY_EXCLUSIVE} mode, otherwise the function
#' will error out.
#'
#' @param grp A TileDB Group object as for example returned by \code{tiledb_group()}
#' @param uri Character variable with the URI of the group item to be deleted
#' @param recursive A logical value indicating whether all data iniside the
#' group is to be delet
#' @return Nothing is returned, the function is invoked for the side-effect of
#' group data removal.
#' @export
tiledb_group_delete <- function(grp, uri, recursive = FALSE) {
stopifnot("The 'grp' argument must be a tiledb_group object" = is(grp, "tiledb_group"),
"The 'uri' argument must be a character variable" = inherits(uri, "character"),
"The 'recursive' argument be logical" = is(recursive, "logical"),
"This function needs TileDB 2.14.*" = tiledb_version(TRUE) >= "2.14.0")
libtiledb_group_delete(grp@ptr, uri, isTRUE(recursive))
}
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1132,6 +1132,10 @@ libtiledb_group_is_relative <- function(grp, name) {
.Call(`_tiledb_libtiledb_group_is_relative`, grp, name)
}

libtiledb_group_delete <- function(grp, uri, recursive = FALSE) {
invisible(.Call(`_tiledb_libtiledb_group_delete`, grp, uri, recursive))
}

libtiledb_filestore_schema_create <- function(ctx, uri) {
.Call(`_tiledb_libtiledb_filestore_schema_create`, ctx, uri)
}
19 changes: 18 additions & 1 deletion inst/tinytest/test_group.R
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ expect_true(obj[2] %in% c(file.path(tiledb_group_uri(grp), "chloe"),
expect_true(is.character(obj[3]))
expect_true(obj[3] %in% c("name_is_chloe", ""))

obj <- tiledb_group_member(grp, 1) # group member with no name
obj <- tiledb_group_member(grp, 1) # group member with no name
expect_true(obj[2] %in% c(file.path(tiledb_group_uri(grp), "chloe"),
file.path(tiledb_group_uri(grp), "anny")))
expect_true(obj[3] %in% c("name_is_chloe", ""))
@@ -185,3 +185,20 @@ expect_equal(dim(dir_info), c(4,2))
dir_info <- tiledb_object_walk(uri, "POSTORDER")
expect_equal(dim(dir_info), c(4,2))
expect_error(tiledb_object_walk(uri, "FRODO"))


## delete
uri <- tempfile()
expect_stdout(chk <- tiledb_group_create(uri)) # returns uri
expect_silent(grp <- tiledb_group(uri, "WRITE"))
uri2 <- file.path(uri, "bob")
fromDataFrame(data.frame(key=1:3, val=letters[1:3]), uri2)
grp <- tiledb_group_add_member(grp, uri2, FALSE) # use absolute URL
grp <- tiledb_group_close(grp)

grp <- tiledb_group_open(grp, "MODIFY_EXCLUSIVE")
expect_true(tiledb_group_is_open(grp))
expect_equal(tiledb_group_query_type(grp), "MODIFY_EXCLUSIVE")
tiledb_group_delete(grp, uri)

if (tiledb_version(TRUE) >= "2.16.0") expect_error(grp <- tiledb_group(uri)) # no longer exists
24 changes: 24 additions & 0 deletions man/tiledb_group_delete.Rd

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

5 changes: 3 additions & 2 deletions man/tiledb_group_open.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
@@ -3374,6 +3374,18 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// libtiledb_group_delete
void libtiledb_group_delete(XPtr<tiledb::Group> grp, const std::string& uri, const bool recursive);
RcppExport SEXP _tiledb_libtiledb_group_delete(SEXP grpSEXP, SEXP uriSEXP, SEXP recursiveSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< XPtr<tiledb::Group> >::type grp(grpSEXP);
Rcpp::traits::input_parameter< const std::string& >::type uri(uriSEXP);
Rcpp::traits::input_parameter< const bool >::type recursive(recursiveSEXP);
libtiledb_group_delete(grp, uri, recursive);
return R_NilValue;
END_RCPP
}
// libtiledb_filestore_schema_create
XPtr<tiledb::ArraySchema> libtiledb_filestore_schema_create(XPtr<tiledb::Context> ctx, std::string uri);
RcppExport SEXP _tiledb_libtiledb_filestore_schema_create(SEXP ctxSEXP, SEXP uriSEXP) {
@@ -3807,6 +3819,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_tiledb_libtiledb_group_member", (DL_FUNC) &_tiledb_libtiledb_group_member, 2},
{"_tiledb_libtiledb_group_dump", (DL_FUNC) &_tiledb_libtiledb_group_dump, 2},
{"_tiledb_libtiledb_group_is_relative", (DL_FUNC) &_tiledb_libtiledb_group_is_relative, 2},
{"_tiledb_libtiledb_group_delete", (DL_FUNC) &_tiledb_libtiledb_group_delete, 3},
{"_tiledb_libtiledb_filestore_schema_create", (DL_FUNC) &_tiledb_libtiledb_filestore_schema_create, 2},
{"_tiledb_libtiledb_filestore_uri_import", (DL_FUNC) &_tiledb_libtiledb_filestore_uri_import, 3},
{"_tiledb_libtiledb_filestore_uri_export", (DL_FUNC) &_tiledb_libtiledb_filestore_uri_export, 3},
14 changes: 14 additions & 0 deletions src/libtiledb.cpp
Original file line number Diff line number Diff line change
@@ -5161,6 +5161,20 @@ bool libtiledb_group_is_relative(XPtr<tiledb::Group> grp, const std::string &nam
#endif
}

// See comments in group.h: the group has to be opened in MODIFY_EXCLUSIVE mode
// The function throws (creating an R error) is that condition is not met
// [[Rcpp::export]]
void libtiledb_group_delete(XPtr<tiledb::Group> grp,
const std::string& uri,
const bool recursive = false) {
check_xptr_tag<tiledb::Group>(grp);
#if TILEDB_VERSION >= TileDB_Version(2,14,0)
grp->delete_group(uri, recursive);
#else
Rcpp::message(Rcpp::wrap("This function is only available with TileDB Core 2.14.0 or later"));
#endif
}



/**

0 comments on commit 2246ec8

Please sign in to comment.