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

Correct 'raw' stats export to json string interface #514

Merged
merged 1 commit into from
Feb 3, 2023
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 R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ libtiledb_stats_dump <- function(path = "") {
invisible(.Call(`_tiledb_libtiledb_stats_dump`, path))
}

libtiledb_stats_raw_dump <- function(path = "") {
invisible(.Call(`_tiledb_libtiledb_stats_raw_dump`, path))
libtiledb_stats_raw_dump <- function() {
.Call(`_tiledb_libtiledb_stats_raw_dump`)
}

libtiledb_stats_raw_get <- function() {
Expand Down
36 changes: 18 additions & 18 deletions R/Stats.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2017-2021 TileDB Inc.
# Copyright (c) 2017-2023 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
Expand Down Expand Up @@ -44,7 +44,7 @@ tiledb_stats_reset <- function() {
libtiledb_stats_reset()
}

#' Dumps internal TileDB statistics to file
#' Dumps internal TileDB statistics to file or stdout
#'
#' @param path Character variable with path to stats file;
#' if the empty string is passed then the result is displayed on stdout.
Expand All @@ -68,23 +68,20 @@ tiledb_stats_print <- function() {
libtiledb_stats_dump("")
}

#' Dumps internal TileDB statistics as JSON to file
#' Dumps internal TileDB statistics as JSON to a string
#'
#' This function requires TileDB Embedded 2.0.3 or later.
#' @param path Character variable with path to stats file;
#' if the empty string is passed then the result is displayed on stdout.
#' @examples
#' \dontshow{ctx <- tiledb_ctx(limitTileDBCores())}
#' if (tiledb_version(TRUE) >= "2.0.3") {
#' pth <- tempfile()
#' tiledb_stats_raw_dump(pth)
#' cat(readLines(pth)[1:10], sep = "\n")
#' txt <- tiledb_stats_raw_dump()
#' cat(txt, "\n")
#' }
#' @export
tiledb_stats_raw_dump <- function(path) {
stopifnot(`Argument 'path' must be character` = is.character(path),
`Raw statistics are available with TileDB Embedded verion 2.0.3 or later` = tiledb_version(TRUE) >= "2.0.3")
libtiledb_stats_raw_dump(path)
tiledb_stats_raw_dump <- function() {
stopifnot("Raw statistics are available with TileDB Embedded verion 2.0.3 or later" =
tiledb_version(TRUE) >= "2.0.3")
libtiledb_stats_raw_dump()
}

#' Print internal TileDB statistics as JSON
Expand All @@ -93,17 +90,20 @@ tiledb_stats_raw_dump <- function(path) {
#' It required TileDB Embedded 2.0.3 or later.
#' @export
tiledb_stats_raw_print <- function() {
stopifnot(`Raw statistics are available with TileDB Embedded verion 2.0.3 or later` = tiledb_version(TRUE) >= "2.0.3")
libtiledb_stats_raw_dump("")
stopifnot("Raw statistics are available with TileDB Embedded verion 2.0.3 or later"
= tiledb_version(TRUE) >= "2.0.3")
cat(libtiledb_stats_raw_dump(), "\n")
}

#' Gets internal TileDB statistics as JSON string
#'
#' This function is a convenience wrapper for \code{tiledb_stats_raw_dump}
#' This function is a (now deprecated) convenience wrapper for \code{tiledb_stats_raw_dump}
#' and returns the result as a JSON string.
#' It required TileDB Embedded 2.0.3 or later.
#' @export
tiledb_stats_raw_get <- function() {
stopifnot(`Raw statistics are available with TileDB Embedded verion 2.0.3 or later` = tiledb_version(TRUE) >= "2.0.3")
libtiledb_stats_raw_get()
}
stopifnot("Raw statistics are available with TileDB Embedded verion 2.0.3 or later"
= tiledb_version(TRUE) >= "2.0.3")
.Deprecated(msg="Use 'tiledb_stats_raw_dump' instead of 'tiledb_stats_raw_get'.")
libtiledb_stats_raw_get()
}
30 changes: 16 additions & 14 deletions inst/tinytest/test_querycondition.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,22 @@ expect_equal(NROW(res), 34L)
expect_true(all(res$bill_length_mm < 40))
expect_true(all(res$year == 2009))

qc3 <- parse_query_condition(island %in% c("Dream", "Biscoe"), arr)
arrwithqc3 <- tiledb_array(uri, as.data.frame=TRUE, strings_as_factors=TRUE, query_condition=qc3)
res <- arrwithqc3[]
expect_equal(NROW(res), 168+124)
expect_true(all(res$island != "Torgersen"))
expect_true(all(res$island == "Dream" | res$island == "Biscoe"))

qc4 <- parse_query_condition(island %in% c("Dream", "Biscoe") && body_mass_g > 3500, arr)
arrwithqc4 <- tiledb_array(uri, as.data.frame=TRUE, strings_as_factors=TRUE, query_condition=qc4)
res <- arrwithqc4[]
expect_equal(NROW(res), 153+80)
expect_true(all(res$island != "Torgersen"))
expect_true(all(res$island == "Dream" | res$island == "Biscoe"))
expect_true(all(res$body_mass_g > 3500))
if (tiledb_version(TRUE) >= "2.10.0") { # the OR operator is more recent than query conditions overall
qc3 <- parse_query_condition(island %in% c("Dream", "Biscoe"), arr)
arrwithqc3 <- tiledb_array(uri, as.data.frame=TRUE, strings_as_factors=TRUE, query_condition=qc3)
res <- arrwithqc3[]
expect_equal(NROW(res), 168+124)
expect_true(all(res$island != "Torgersen"))
expect_true(all(res$island == "Dream" | res$island == "Biscoe"))

qc4 <- parse_query_condition(island %in% c("Dream", "Biscoe") && body_mass_g > 3500, arr)
arrwithqc4 <- tiledb_array(uri, as.data.frame=TRUE, strings_as_factors=TRUE, query_condition=qc4)
res <- arrwithqc4[]
expect_equal(NROW(res), 153+80)
expect_true(all(res$island != "Torgersen"))
expect_true(all(res$island == "Dream" | res$island == "Biscoe"))
expect_true(all(res$body_mass_g > 3500))
}

unlink(uri, recursive=TRUE)

Expand Down
12 changes: 6 additions & 6 deletions man/tiledb_dim.Rd

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

4 changes: 2 additions & 2 deletions man/tiledb_stats_dump.Rd

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

13 changes: 4 additions & 9 deletions man/tiledb_stats_raw_dump.Rd

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

2 changes: 1 addition & 1 deletion man/tiledb_stats_raw_get.Rd

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

12 changes: 6 additions & 6 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2524,13 +2524,13 @@ BEGIN_RCPP
END_RCPP
}
// libtiledb_stats_raw_dump
void libtiledb_stats_raw_dump(std::string path);
RcppExport SEXP _tiledb_libtiledb_stats_raw_dump(SEXP pathSEXP) {
std::string libtiledb_stats_raw_dump();
RcppExport SEXP _tiledb_libtiledb_stats_raw_dump() {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< std::string >::type path(pathSEXP);
libtiledb_stats_raw_dump(path);
return R_NilValue;
rcpp_result_gen = Rcpp::wrap(libtiledb_stats_raw_dump());
return rcpp_result_gen;
END_RCPP
}
// libtiledb_stats_raw_get
Expand Down Expand Up @@ -3385,7 +3385,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_tiledb_libtiledb_stats_disable", (DL_FUNC) &_tiledb_libtiledb_stats_disable, 0},
{"_tiledb_libtiledb_stats_reset", (DL_FUNC) &_tiledb_libtiledb_stats_reset, 0},
{"_tiledb_libtiledb_stats_dump", (DL_FUNC) &_tiledb_libtiledb_stats_dump, 1},
{"_tiledb_libtiledb_stats_raw_dump", (DL_FUNC) &_tiledb_libtiledb_stats_raw_dump, 1},
{"_tiledb_libtiledb_stats_raw_dump", (DL_FUNC) &_tiledb_libtiledb_stats_raw_dump, 0},
{"_tiledb_libtiledb_stats_raw_get", (DL_FUNC) &_tiledb_libtiledb_stats_raw_get, 0},
{"_tiledb_libtiledb_fragment_info", (DL_FUNC) &_tiledb_libtiledb_fragment_info, 2},
{"_tiledb_libtiledb_fragment_info_uri", (DL_FUNC) &_tiledb_libtiledb_fragment_info_uri, 2},
Expand Down
27 changes: 9 additions & 18 deletions src/libtiledb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4165,33 +4165,24 @@ void libtiledb_stats_dump(std::string path = "") {
}

// [[Rcpp::export]]
void libtiledb_stats_raw_dump(std::string path = "") {
std::string libtiledb_stats_raw_dump() {
#if TILEDB_VERSION < TileDB_Version(2,0,3)
Rcpp::stop("This function requires TileDB Embedded 2.0.3 or later.");
Rcpp::stop("This function requires TileDB Embedded 2.0.3 or later.");
#else
if (path == "") {
tiledb::Stats::raw_dump();
} else {
FILE* fptr = nullptr;
fptr = fopen(path.c_str(), "w");
if (fptr == nullptr) {
Rcpp::stop("error opening stats dump file for writing");
}
tiledb::Stats::raw_dump(fptr);
fclose(fptr);
}
std::string txt;
tiledb::Stats::raw_dump(&txt);
return txt;
#endif
}

// [[Rcpp::export]]
std::string libtiledb_stats_raw_get() {
#if TILEDB_VERSION < TileDB_Version(2,0,3)
Rcpp::stop("This function requires TileDB Embedded 2.0.3 or later.");
return(std::string());//not reached
Rcpp::stop("This function requires TileDB Embedded 2.0.3 or later.");
return(std::string());//not reached
#else
std::string result;
tiledb::Stats::raw_dump(&result);
return result;
Rcpp::message(Rcpp::wrap("This function is deprecated, please use 'libtiledb_stats_raw_dump'."));
return libtiledb_stats_raw_dump();
#endif
}

Expand Down