diff --git a/DESCRIPTION b/DESCRIPTION index 4a090f7624..094b720e6e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tiledb Type: Package -Version: 0.33.1 +Version: 0.33.1.1 Title: Modern Database Engine for Complex Data Based on Multi-Dimensional Arrays Authors@R: c( person("TileDB, Inc.", role = c("aut", "cph")), diff --git a/NAMESPACE b/NAMESPACE index 29f1cb29ba..112555b22f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -240,6 +240,14 @@ export(tiledb_object_mv) export(tiledb_object_rm) export(tiledb_object_type) export(tiledb_object_walk) +export(tiledb_profile) +export(tiledb_profile_dir) +export(tiledb_profile_get_param) +export(tiledb_profile_load) +export(tiledb_profile_name) +export(tiledb_profile_remove) +export(tiledb_profile_save) +export(tiledb_profile_set_param) export(tiledb_put_metadata) export(tiledb_query) export(tiledb_query_add_range) @@ -342,6 +350,7 @@ exportClasses(tiledb_filter_list) exportClasses(tiledb_fragment_info) exportClasses(tiledb_group) exportClasses(tiledb_ndrectangle) +exportClasses(tiledb_profile) exportClasses(tiledb_query) exportClasses(tiledb_query_condition) exportClasses(tiledb_subarray) diff --git a/NEWS.md b/NEWS.md index f487cd9ad9..1f022521cd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # tiledb (development version) +## Improvements + +* Add support for creating, loading, saving, and removing Profiles ([#856](https://github.com/TileDB-Inc/TileDB-R/pull/856)) + # tiledb 0.33.1 * This release of the R package builds against [TileDB 2.29.1](https://github.com/TileDB-Inc/TileDB/releases/tag/2.29.1), and has also been tested against earlier releases as well as the development version diff --git a/R/Profile.R b/R/Profile.R new file mode 100644 index 0000000000..b1539b9600 --- /dev/null +++ b/R/Profile.R @@ -0,0 +1,124 @@ +# +# Copyright (c) TileDB Inc. under the MIT License +# + +#' An S4 class for a TileDB Profile object +#' +#' @slot ptr An external pointer to the underlying implementation +#' @exportClass tiledb_profile +setClass("tiledb_profile", + slots = list(ptr = "externalptr") +) + +#' Raw display of a profile object +#' +#' This method uses the display method provided by the underlying library. +#' +#' @param object A profile object +#' @export +setMethod( + "raw_dump", + signature(object = "tiledb_profile"), + definition = function(object) libtiledb_profile_dump(object@ptr) +) + +#' Create a 'tiledb_profile' object +#' +#' @param name (optional) Name for the profile +#' @param dir (optional) Directory to create the profile in +#' @return A new 'tiledb_profile' object +#' @export +tiledb_profile <- function(name = NULL, dir = NULL) { + stopifnot(`The 'name' for the profile must be null or a character type` = is.null(name) || is.character(name)) + stopifnot(`The 'dir' for the profile must be null or a character type` = is.null(name) || is.character(name)) + ptr <- libtiledb_profile_new(name, dir) + profile <- new("tiledb_profile", ptr = ptr) + return(profile) +} + +#' Load a saved 'tiledb_profile' object +#' +#' @param name (optional) Name of the profile to load +#' @param dir (optional) Directory where the profile to load is saved +#' @return The loaded 'tiledb_profile' object +#' @export +tiledb_profile_load <- function(name = NULL, dir = NULL) { + stopifnot(`The 'name' for the profile must be null or a character type` = is.null(name) || is.character(name)) + stopifnot(`The 'dir' for the profile must be null or a character type` = is.null(name) || is.character(name)) + ptr <- libtiledb_profile_load(name, dir) + profile <- new("tiledb_profile", ptr = ptr) + return(profile) +} + +#' Remove a saved 'tiledb_profile' +#' +#' @param name (optional) Name of the profile to remove +#' @param dir (optional) Directory where the profile to remove is saved +#' @export +tiledb_profile_remove <- function(name = NULL, dir = NULL) { + stopifnot(`The 'name' for the profile must be null or a character type` = is.null(name) || is.character(name)) + stopifnot(`The 'dir' for the profile must be null or a character type` = is.null(name) || is.character(name)) + libtiledb_profile_remove(name, dir) + return(invisible(NULL)) +} + +#' Get the name of a 'tiledb_profile' object +#' +#' @param profile A TileDB profile object +#' @return The name of the 'tiledb_profile' object +#' @export +tiledb_profile_name <- function(profile) { + stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) + name <- libtiledb_profile_name(profile@ptr) + return(name) +} + +#' Get the directory of a 'tiledb_profile' object +#' +#' @param profile A TileDB profile object +#' @return The directory of the 'tiledb_profile' object +#' @export +tiledb_profile_dir <- function(profile) { + stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) + dir <- libtiledb_profile_dir(profile@ptr) + return(dir) +} + +#' Set a parameter on the 'tiledb_profile' object +#' +#' @param profile A TileDB profile object +#' @param param The key for the new parameter +#' @param value The value for the new parameter +#' @export +tiledb_profile_set_param <- function(profile, param, value) { + stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) + stopifnot(`The 'param' arugment must have character type` = is.character(param)) + stopifnot(`The 'value' arugment must have character type` = is.character(value)) + libtiledb_profile_set_param(profile@ptr, param, value) + return(invisible(NULL)) +} + +#' Get the value of a parameter set on the 'tiledb_profile' object +#' +#' @param profile A TileDB profile object +#' @param param The key for the parameter to fetch +#' @return The value of the requested parameter or NULL if no such parameter exists +#' @export +tiledb_profile_get_param <- function(profile, param) { + stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) + stopifnot(`The 'param' arugment must have character type` = is.character(param)) + value <- libtiledb_profile_get_param(profile@ptr, param) + return(value) +} + +#' Save the 'tiledb_profile' object +#' +#' This will save the 'tiledb_profile' with the name and directory set at creation. +#' +#' @param profile The 'tiledb_profile' object to save +#' @export +tiledb_profile_save <- function(profile) { + stopifnot(`The 'profile' argument must be a tiledb_profile object` = is(profile, "tiledb_profile")) + libtiledb_profile_save(profile@ptr) + return(invisible(NULL)) +} diff --git a/R/RcppExports.R b/R/RcppExports.R index dc816c62a4..57941ae0c8 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -1233,6 +1233,42 @@ libtiledb_current_domain_is_empty <- function(cd) { .Call(`_tiledb_libtiledb_current_domain_is_empty`, cd) } +libtiledb_profile_new <- function(name = NULL, dir = NULL) { + .Call(`_tiledb_libtiledb_profile_new`, name, dir) +} + +libtiledb_profile_load <- function(name = NULL, dir = NULL) { + .Call(`_tiledb_libtiledb_profile_load`, name, dir) +} + +libtiledb_profile_remove <- function(name = NULL, dir = NULL) { + invisible(.Call(`_tiledb_libtiledb_profile_remove`, name, dir)) +} + +libtiledb_profile_name <- function(profile) { + .Call(`_tiledb_libtiledb_profile_name`, profile) +} + +libtiledb_profile_dir <- function(profile) { + .Call(`_tiledb_libtiledb_profile_dir`, profile) +} + +libtiledb_profile_set_param <- function(profile, param, value) { + invisible(.Call(`_tiledb_libtiledb_profile_set_param`, profile, param, value)) +} + +libtiledb_profile_get_param <- function(profile, param) { + .Call(`_tiledb_libtiledb_profile_get_param`, profile, param) +} + +libtiledb_profile_save <- function(profile) { + invisible(.Call(`_tiledb_libtiledb_profile_save`, profile)) +} + +libtiledb_profile_dump <- function(profile) { + .Call(`_tiledb_libtiledb_profile_dump`, profile) +} + vecbuf_to_shmem <- function(dir, name, buf, sz, numvar) { invisible(.Call(`_tiledb_vecbuf_to_shmem`, dir, name, buf, sz, numvar)) } diff --git a/inst/tinytest/test_config_profile.R b/inst/tinytest/test_config_profile.R new file mode 100644 index 0000000000..7f35e8eadc --- /dev/null +++ b/inst/tinytest/test_config_profile.R @@ -0,0 +1,36 @@ +library(tinytest) +library(tiledb) + +# Use base directory to prevent over-writing user profiles. +name <- "test_profile" +dir <- file.path(tempdir(), "tiledb_config_profile/") + +# Create profile +profile <- tiledb_profile(name, dir) + +# Set some parameters +token <- "12345" +server_address <- "https://profile_address.com" +tiledb_profile_set_param(profile, "rest.token", token) +tiledb_profile_set_param(profile, "rest.server_address", server_address) + +# Save the profile +tiledb_profile_save(profile) + + +# Create a config and set the profile directory +config <- tiledb_config(c(profile_name = name, profile_dir = dir)) +config_profile_name <- config["profile_name"] +config_profile_dir <- config["profile_dir"] +config_rest_token <- config["rest.token"] +config_rest_server_address <- config["rest.server_address"] + +# Test that the config parameters are set correctly +expect_equal(config["profile_name"], c(profile_name = name)) +expect_equal(config["profile_dir"], c(profile_dir = dir)) +expect_equal(config["rest.token"], c(rest.token = token)) +expect_equal(config["rest.server_address"], c(rest.server_address = server_address)) + + +# Remove the profile +tiledb_profile_remove(name, dir) diff --git a/inst/tinytest/test_profile.R b/inst/tinytest/test_profile.R new file mode 100644 index 0000000000..43c876ff5d --- /dev/null +++ b/inst/tinytest/test_profile.R @@ -0,0 +1,100 @@ +library(tinytest) +library(tiledb) + +# Use base directory to prevent over-writing user profiles. +base_dir <- tempdir() +dir1 <- file.path(base_dir, "tiledb_profile") + + +# 1. Test creating profiles. +profile1 <- tiledb_profile() +profile2 <- tiledb_profile("profile2") +profile3 <- tiledb_profile(dir=dir1) +profile4 <- tiledb_profile("profile4", dir1) + +expect_equal(tiledb_profile_name(profile1), "default") +expect_equal(tiledb_profile_name(profile2), "profile2") +expect_equal(tiledb_profile_name(profile3), "default") +expect_equal(tiledb_profile_name(profile4), "profile4") + +# Skipping checks for default directory since it is platform dependent. +# Normalize paths on Windows to UNIX-style +expected_dir <- normalizePath( + path = dir1, + winslash = "/", + mustWork = FALSE +) +actual_dir_profile3 <- normalizePath( + path = tiledb_profile_dir(profile3), + winslash = "/", + mustWork = FALSE +) +expect_identical( + # trim trailing slashes + current = sub(pattern = "/+$", replacement = "", x = actual_dir_profile3), + target = expected_dir +) +actual_dir_profile4 <- normalizePath( + path = tiledb_profile_dir(profile4), + winslash = "/", + mustWork = FALSE +) +expect_identical( + current = sub(pattern = "/+$", replacement = "", x = actual_dir_profile4), + target = expected_dir +) + + +# 2. Test setting/getting profile parameters. +key1 <- "username" +key2 <- "server_address" +key3 <- "rest.token" +expected_value1 <- "my_username" +expected_value2 <- "https://my.address" +expected_value3 <- "123456" + +tiledb_profile_set_param(profile4, key1, expected_value1) +tiledb_profile_set_param(profile4, key2, expected_value2) +tiledb_profile_set_param(profile4, key3, expected_value3) + +actual_value1 <- tiledb_profile_get_param(profile4, key1) +actual_value2 <- tiledb_profile_get_param(profile4, key2) +actual_value3 <- tiledb_profile_get_param(profile4, key3) +actual_non_value <- tiledb_profile_get_param(profile4, "not_a_parameter") + +expect_equal(actual_value1, expected_value1) +expect_equal(actual_value2, expected_value2) +expect_equal(actual_value3, expected_value3) +expect_true(is.null(actual_non_value)) + +# 3. Test save, load, and remove. +# IMPORTANT: Do not save a profile to a location that might over-write an actual profile. +tiledb_profile_save(profile3) +tiledb_profile_save(profile4) + +# -- Check can load profile3 +profile_loaded <- tiledb_profile_load(dir=dir1) + +# -- Remove profile2. Check can no longer load. +tiledb_profile_remove(dir=dir1) +expect_error(tiledb_profile_load(dir=dir1)) + +# -- Check loaded profile4 +profile_loaded <- tiledb_profile_load("profile4", dir1) +expect_equal(tiledb_profile_name(profile_loaded), "profile4") +expect_equal(tiledb_profile_name(profile_loaded), "profile4") +loaded_value1 <- tiledb_profile_get_param(profile_loaded, key1) +loaded_value2 <- tiledb_profile_get_param(profile_loaded, key2) +loaded_value3 <- tiledb_profile_get_param(profile_loaded, key3) +loaded_non_value <- tiledb_profile_get_param(profile_loaded, "not_a_parameter") +expect_equal(loaded_value1, expected_value1) +expect_equal(loaded_value2, expected_value2) +expect_equal(loaded_value3, expected_value3) +expect_true(is.null(loaded_non_value)) + +# -- Remove profile4 +tiledb_profile_remove("profile4", dir1) + +# -- Check cannot load profile2 or profile4. +expect_error(tiledb_profile_load(dir=dir1)) +expect_error(tiledb_profile_load("profile4", dir1)) diff --git a/man/raw_dump-tiledb_profile-method.Rd b/man/raw_dump-tiledb_profile-method.Rd new file mode 100644 index 0000000000..b2dede88cc --- /dev/null +++ b/man/raw_dump-tiledb_profile-method.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Profile.R +\name{raw_dump,tiledb_profile-method} +\alias{raw_dump,tiledb_profile-method} +\title{Raw display of a profile object} +\usage{ +\S4method{raw_dump}{tiledb_profile}(object) +} +\arguments{ +\item{object}{A profile object} +} +\description{ +This method uses the display method provided by the underlying library. +} diff --git a/man/tiledb_profile-class.Rd b/man/tiledb_profile-class.Rd new file mode 100644 index 0000000000..c9ba7ed7fd --- /dev/null +++ b/man/tiledb_profile-class.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Profile.R +\docType{class} +\name{tiledb_profile-class} +\alias{tiledb_profile-class} +\title{An S4 class for a TileDB Profile object} +\description{ +An S4 class for a TileDB Profile object +} +\section{Slots}{ + +\describe{ +\item{\code{ptr}}{An external pointer to the underlying implementation} +}} + diff --git a/man/tiledb_profile.Rd b/man/tiledb_profile.Rd new file mode 100644 index 0000000000..0421cc1143 --- /dev/null +++ b/man/tiledb_profile.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Profile.R +\name{tiledb_profile} +\alias{tiledb_profile} +\title{Create a 'tiledb_profile' object} +\usage{ +tiledb_profile(name = NULL, dir = NULL) +} +\arguments{ +\item{name}{(optional) Name for the profile} + +\item{dir}{(optional) Directory to create the profile in} +} +\value{ +A new 'tiledb_profile' object +} +\description{ +Create a 'tiledb_profile' object +} diff --git a/man/tiledb_profile_dir.Rd b/man/tiledb_profile_dir.Rd new file mode 100644 index 0000000000..d97eea44d7 --- /dev/null +++ b/man/tiledb_profile_dir.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Profile.R +\name{tiledb_profile_dir} +\alias{tiledb_profile_dir} +\title{Get the directory of a 'tiledb_profile' object} +\usage{ +tiledb_profile_dir(profile) +} +\arguments{ +\item{profile}{A TileDB profile object} +} +\value{ +The directory of the 'tiledb_profile' object +} +\description{ +Get the directory of a 'tiledb_profile' object +} diff --git a/man/tiledb_profile_get_param.Rd b/man/tiledb_profile_get_param.Rd new file mode 100644 index 0000000000..ad7a2d1c20 --- /dev/null +++ b/man/tiledb_profile_get_param.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Profile.R +\name{tiledb_profile_get_param} +\alias{tiledb_profile_get_param} +\title{Get the value of a parameter set on the 'tiledb_profile' object} +\usage{ +tiledb_profile_get_param(profile, param) +} +\arguments{ +\item{profile}{A TileDB profile object} + +\item{param}{The key for the parameter to fetch} +} +\value{ +The value of the requested parameter or NULL if no such parameter exists +} +\description{ +Get the value of a parameter set on the 'tiledb_profile' object +} diff --git a/man/tiledb_profile_load.Rd b/man/tiledb_profile_load.Rd new file mode 100644 index 0000000000..8b472eb2cb --- /dev/null +++ b/man/tiledb_profile_load.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Profile.R +\name{tiledb_profile_load} +\alias{tiledb_profile_load} +\title{Load a saved 'tiledb_profile' object} +\usage{ +tiledb_profile_load(name = NULL, dir = NULL) +} +\arguments{ +\item{name}{(optional) Name of the profile to load} + +\item{dir}{(optional) Directory where the profile to load is saved} +} +\value{ +The loaded 'tiledb_profile' object +} +\description{ +Load a saved 'tiledb_profile' object +} diff --git a/man/tiledb_profile_name.Rd b/man/tiledb_profile_name.Rd new file mode 100644 index 0000000000..7659b3af99 --- /dev/null +++ b/man/tiledb_profile_name.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Profile.R +\name{tiledb_profile_name} +\alias{tiledb_profile_name} +\title{Get the name of a 'tiledb_profile' object} +\usage{ +tiledb_profile_name(profile) +} +\arguments{ +\item{profile}{A TileDB profile object} +} +\value{ +The name of the 'tiledb_profile' object +} +\description{ +Get the name of a 'tiledb_profile' object +} diff --git a/man/tiledb_profile_remove.Rd b/man/tiledb_profile_remove.Rd new file mode 100644 index 0000000000..0fde303448 --- /dev/null +++ b/man/tiledb_profile_remove.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Profile.R +\name{tiledb_profile_remove} +\alias{tiledb_profile_remove} +\title{Remove a saved 'tiledb_profile'} +\usage{ +tiledb_profile_remove(name = NULL, dir = NULL) +} +\arguments{ +\item{name}{(optional) Name of the profile to remove} + +\item{dir}{(optional) Directory where the profile to remove is saved} +} +\description{ +Remove a saved 'tiledb_profile' +} diff --git a/man/tiledb_profile_save.Rd b/man/tiledb_profile_save.Rd new file mode 100644 index 0000000000..24c174f837 --- /dev/null +++ b/man/tiledb_profile_save.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Profile.R +\name{tiledb_profile_save} +\alias{tiledb_profile_save} +\title{Save the 'tiledb_profile' object} +\usage{ +tiledb_profile_save(profile) +} +\arguments{ +\item{profile}{The 'tiledb_profile' object to save} +} +\description{ +This will save the 'tiledb_profile' with the name and directory set at creation. +} diff --git a/man/tiledb_profile_set_param.Rd b/man/tiledb_profile_set_param.Rd new file mode 100644 index 0000000000..54a9eb2829 --- /dev/null +++ b/man/tiledb_profile_set_param.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Profile.R +\name{tiledb_profile_set_param} +\alias{tiledb_profile_set_param} +\title{Set a parameter on the 'tiledb_profile' object} +\usage{ +tiledb_profile_set_param(profile, param, value) +} +\arguments{ +\item{profile}{A TileDB profile object} + +\item{param}{The key for the new parameter} + +\item{value}{The value for the new parameter} +} +\description{ +Set a parameter on the 'tiledb_profile' object +} diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 35d1051e40..a72c4303e2 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -101,6 +101,10 @@ reference: - matches("createBatched") - matches("fetchBatched") - matches("statusBatched") +- title: Profile + contents: + - starts_with("tiledb_profile") + - ends_with("tiledb_profile-method") - title: Group contents: - starts_with("tiledb_group") diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 9a838b9d0c..64dd06ac00 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -3678,6 +3678,108 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// libtiledb_profile_new +XPtr libtiledb_profile_new(Nullable name, Nullable dir); +RcppExport SEXP _tiledb_libtiledb_profile_new(SEXP nameSEXP, SEXP dirSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< Nullable >::type name(nameSEXP); + Rcpp::traits::input_parameter< Nullable >::type dir(dirSEXP); + rcpp_result_gen = Rcpp::wrap(libtiledb_profile_new(name, dir)); + return rcpp_result_gen; +END_RCPP +} +// libtiledb_profile_load +XPtr libtiledb_profile_load(Nullable name, Nullable dir); +RcppExport SEXP _tiledb_libtiledb_profile_load(SEXP nameSEXP, SEXP dirSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< Nullable >::type name(nameSEXP); + Rcpp::traits::input_parameter< Nullable >::type dir(dirSEXP); + rcpp_result_gen = Rcpp::wrap(libtiledb_profile_load(name, dir)); + return rcpp_result_gen; +END_RCPP +} +// libtiledb_profile_remove +void libtiledb_profile_remove(Nullable name, Nullable dir); +RcppExport SEXP _tiledb_libtiledb_profile_remove(SEXP nameSEXP, SEXP dirSEXP) { +BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< Nullable >::type name(nameSEXP); + Rcpp::traits::input_parameter< Nullable >::type dir(dirSEXP); + libtiledb_profile_remove(name, dir); + return R_NilValue; +END_RCPP +} +// libtiledb_profile_name +std::string libtiledb_profile_name(XPtr profile); +RcppExport SEXP _tiledb_libtiledb_profile_name(SEXP profileSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< XPtr >::type profile(profileSEXP); + rcpp_result_gen = Rcpp::wrap(libtiledb_profile_name(profile)); + return rcpp_result_gen; +END_RCPP +} +// libtiledb_profile_dir +std::string libtiledb_profile_dir(XPtr profile); +RcppExport SEXP _tiledb_libtiledb_profile_dir(SEXP profileSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< XPtr >::type profile(profileSEXP); + rcpp_result_gen = Rcpp::wrap(libtiledb_profile_dir(profile)); + return rcpp_result_gen; +END_RCPP +} +// libtiledb_profile_set_param +void libtiledb_profile_set_param(XPtr profile, const std::string& param, const std::string& value); +RcppExport SEXP _tiledb_libtiledb_profile_set_param(SEXP profileSEXP, SEXP paramSEXP, SEXP valueSEXP) { +BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< XPtr >::type profile(profileSEXP); + Rcpp::traits::input_parameter< const std::string& >::type param(paramSEXP); + Rcpp::traits::input_parameter< const std::string& >::type value(valueSEXP); + libtiledb_profile_set_param(profile, param, value); + return R_NilValue; +END_RCPP +} +// libtiledb_profile_get_param +Nullable libtiledb_profile_get_param(XPtr profile, const std::string& param); +RcppExport SEXP _tiledb_libtiledb_profile_get_param(SEXP profileSEXP, SEXP paramSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< XPtr >::type profile(profileSEXP); + Rcpp::traits::input_parameter< const std::string& >::type param(paramSEXP); + rcpp_result_gen = Rcpp::wrap(libtiledb_profile_get_param(profile, param)); + return rcpp_result_gen; +END_RCPP +} +// libtiledb_profile_save +void libtiledb_profile_save(XPtr profile); +RcppExport SEXP _tiledb_libtiledb_profile_save(SEXP profileSEXP) { +BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< XPtr >::type profile(profileSEXP); + libtiledb_profile_save(profile); + return R_NilValue; +END_RCPP +} +// libtiledb_profile_dump +std::string libtiledb_profile_dump(XPtr profile); +RcppExport SEXP _tiledb_libtiledb_profile_dump(SEXP profileSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< XPtr >::type profile(profileSEXP); + rcpp_result_gen = Rcpp::wrap(libtiledb_profile_dump(profile)); + return rcpp_result_gen; +END_RCPP +} // vecbuf_to_shmem void vecbuf_to_shmem(std::string dir, std::string name, XPtr buf, int sz, int numvar); RcppExport SEXP _tiledb_vecbuf_to_shmem(SEXP dirSEXP, SEXP nameSEXP, SEXP bufSEXP, SEXP szSEXP, SEXP numvarSEXP) { @@ -4059,6 +4161,15 @@ static const R_CallMethodDef CallEntries[] = { {"_tiledb_libtiledb_current_domain_set_ndrectangle", (DL_FUNC) &_tiledb_libtiledb_current_domain_set_ndrectangle, 2}, {"_tiledb_libtiledb_current_domain_get_ndrectangle", (DL_FUNC) &_tiledb_libtiledb_current_domain_get_ndrectangle, 1}, {"_tiledb_libtiledb_current_domain_is_empty", (DL_FUNC) &_tiledb_libtiledb_current_domain_is_empty, 1}, + {"_tiledb_libtiledb_profile_new", (DL_FUNC) &_tiledb_libtiledb_profile_new, 2}, + {"_tiledb_libtiledb_profile_load", (DL_FUNC) &_tiledb_libtiledb_profile_load, 2}, + {"_tiledb_libtiledb_profile_remove", (DL_FUNC) &_tiledb_libtiledb_profile_remove, 2}, + {"_tiledb_libtiledb_profile_name", (DL_FUNC) &_tiledb_libtiledb_profile_name, 1}, + {"_tiledb_libtiledb_profile_dir", (DL_FUNC) &_tiledb_libtiledb_profile_dir, 1}, + {"_tiledb_libtiledb_profile_set_param", (DL_FUNC) &_tiledb_libtiledb_profile_set_param, 3}, + {"_tiledb_libtiledb_profile_get_param", (DL_FUNC) &_tiledb_libtiledb_profile_get_param, 2}, + {"_tiledb_libtiledb_profile_save", (DL_FUNC) &_tiledb_libtiledb_profile_save, 1}, + {"_tiledb_libtiledb_profile_dump", (DL_FUNC) &_tiledb_libtiledb_profile_dump, 1}, {"_tiledb_vecbuf_to_shmem", (DL_FUNC) &_tiledb_vecbuf_to_shmem, 5}, {"_tiledb_vlcbuf_to_shmem", (DL_FUNC) &_tiledb_vlcbuf_to_shmem, 4}, {"_tiledb_querybuf_from_shmem", (DL_FUNC) &_tiledb_querybuf_from_shmem, 2}, diff --git a/src/libtiledb.cpp b/src/libtiledb.cpp index 5f9407fc4b..01ea2080dc 100644 --- a/src/libtiledb.cpp +++ b/src/libtiledb.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using namespace Rcpp; @@ -5925,3 +5926,73 @@ bool libtiledb_current_domain_is_empty(XPtr cd) { return false; #endif } + + +/** + * Profile (2.29.0 or later) + */ + +std::optional as_optional_string(Nullable param) { + if (param.isNull()) { + return std::nullopt; + } + CharacterVector tmp(param); + return std::string(tmp[0]); +} + + +// [[Rcpp::export]] +XPtr libtiledb_profile_new(Nullable name = R_NilValue, Nullable dir = R_NilValue) { + auto name_ = as_optional_string(name); + auto dir_ = as_optional_string(dir); + return make_xptr(new tiledb::Profile(name_, dir_)); +} + +// [[Rcpp::export]] +XPtr libtiledb_profile_load(Nullable name = R_NilValue, Nullable dir = R_NilValue) { + auto name_ = as_optional_string(name); + auto dir_ = as_optional_string(dir); + return make_xptr(new tiledb::Profile(tiledb::Profile::load(name_, dir_))); +} + +// [[Rcpp::export]] +void libtiledb_profile_remove(Nullable name = R_NilValue, Nullable dir = R_NilValue) { + auto name_ = as_optional_string(name); + auto dir_ = as_optional_string(dir); + return tiledb::Profile::remove(name_, dir_); +} + +// [[Rcpp::export]] +std::string libtiledb_profile_name(XPtr profile) { + return profile->name(); +} + +// [[Rcpp::export]] +std::string libtiledb_profile_dir(XPtr profile) { + return profile->dir(); +} + +// [[Rcpp::export]] +void libtiledb_profile_set_param(XPtr profile, const std::string& param, const std::string& value) { + return profile->set_param(param, value); +} + +// [[Rcpp::export]] +Nullable libtiledb_profile_get_param(XPtr profile, const std::string& param) { + auto maybe_value = profile->get_param(param); + if (maybe_value.has_value()) { + return wrap(maybe_value.value()); + } + return R_NilValue; +} + +// [[Rcpp::export]] +void libtiledb_profile_save(XPtr profile) { + return profile->save(); +} + +// [[Rcpp::export]] +std::string libtiledb_profile_dump(XPtr profile) { + return profile->dump(); +} + diff --git a/src/libtiledb.h b/src/libtiledb.h index 153aa4334e..2d204273af 100644 --- a/src/libtiledb.h +++ b/src/libtiledb.h @@ -120,12 +120,15 @@ const tiledb_xptr_object tiledb_xptr_object_subarray{200}; const tiledb_xptr_object tiledb_xptr_column_buffer{210}; const tiledb_xptr_object tiledb_xptr_array_buffers{220}; const tiledb_xptr_object tiledb_xptr_map_to_col_buf_t{230}; +const tiledb_xptr_object tiledb_xptr_profile{240}; // the definitions above are internal to tiledb-r but we need a new value here // if we want tag the external pointer const tiledb_xptr_object tiledb_arrow_array_t{300}; const tiledb_xptr_object tiledb_arrow_schema_t{310}; + + // templated checkers for external pointer tags template const int32_t XPtrTagType = tiledb_xptr_default; // clang++ wants a value @@ -188,6 +191,8 @@ template <> inline const int32_t XPtrTagType = tiledb_arrow_array_t; template <> inline const int32_t XPtrTagType = tiledb_arrow_schema_t; +template <> inline const int32_t XPtrTagType = tiledb_xptr_profile; + constexpr const char *xptrObjToString(tiledb_xptr_object xp) { switch (xp) { case tiledb_xptr_default: @@ -238,6 +243,8 @@ constexpr const char *xptrObjToString(tiledb_xptr_object xp) { return "ArrayBuffers"; case tiledb_xptr_map_to_col_buf_t: return "map_to_col_buf_t"; + case tiledb_xptr_profile: + return "Profile"; case tiledb_arrow_array_t: return "ArrowArray"; case tiledb_arrow_schema_t: