From 26a4926ff0b7f3dca39950c29a191d9cc39f98d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 27 Oct 2024 09:59:07 +0100 Subject: [PATCH] rapi_get_last_rel_mat() --- R/cpp11.R | 4 ++++ src/cpp11.cpp | 8 ++++++++ src/reltoaltrep.cpp | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/R/cpp11.R b/R/cpp11.R index 91d92bdad..64ac5f377 100644 --- a/R/cpp11.R +++ b/R/cpp11.R @@ -172,6 +172,10 @@ rapi_rel_from_table_function <- function(con, function_name, positional_paramete .Call(`_duckdb_rapi_rel_from_table_function`, con, function_name, positional_parameters_sexps, named_parameters_sexps) } +rapi_get_last_rel_mat <- function() { + .Call(`_duckdb_rapi_get_last_rel_mat`) +} + # allow_materialization = TRUE: compatibility with duckplyr <= 0.4.1 rapi_rel_to_altrep <- function(rel, allow_materialization = TRUE) { .Call(`_duckdb_rapi_rel_to_altrep`, rel, allow_materialization) diff --git a/src/cpp11.cpp b/src/cpp11.cpp index b42b45ac2..fa0c76fda 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -315,6 +315,13 @@ extern "C" SEXP _duckdb_rapi_rel_from_table_function(SEXP con, SEXP function_nam END_CPP11 } // reltoaltrep.cpp +std::string rapi_get_last_rel_mat(); +extern "C" SEXP _duckdb_rapi_get_last_rel_mat() { + BEGIN_CPP11 + return cpp11::as_sexp(rapi_get_last_rel_mat()); + END_CPP11 +} +// reltoaltrep.cpp SEXP rapi_rel_to_altrep(duckdb::rel_extptr_t rel, bool allow_materialization); extern "C" SEXP _duckdb_rapi_rel_to_altrep(SEXP rel, SEXP allow_materialization) { BEGIN_CPP11 @@ -445,6 +452,7 @@ static const R_CallMethodDef CallEntries[] = { {"_duckdb_rapi_expr_set_alias", (DL_FUNC) &_duckdb_rapi_expr_set_alias, 2}, {"_duckdb_rapi_expr_tostring", (DL_FUNC) &_duckdb_rapi_expr_tostring, 1}, {"_duckdb_rapi_expr_window", (DL_FUNC) &_duckdb_rapi_expr_window, 9}, + {"_duckdb_rapi_get_last_rel_mat", (DL_FUNC) &_duckdb_rapi_get_last_rel_mat, 0}, {"_duckdb_rapi_get_null_SEXP_ptr", (DL_FUNC) &_duckdb_rapi_get_null_SEXP_ptr, 0}, {"_duckdb_rapi_get_substrait", (DL_FUNC) &_duckdb_rapi_get_substrait, 3}, {"_duckdb_rapi_get_substrait_json", (DL_FUNC) &_duckdb_rapi_get_substrait_json, 3}, diff --git a/src/reltoaltrep.cpp b/src/reltoaltrep.cpp index 5408eb472..60cf9dc0b 100644 --- a/src/reltoaltrep.cpp +++ b/src/reltoaltrep.cpp @@ -338,6 +338,13 @@ static R_altrep_class_t LogicalTypeToAltrepType(const LogicalType &type) { } } +[[cpp11::register]] std::string rapi_get_last_rel_mat() { + if (!AltrepRelationWrapper::last_rel) { + return ""; + } + return AltrepRelationWrapper::last_rel->ToString(); +} + [[cpp11::register]] SEXP rapi_rel_to_altrep(duckdb::rel_extptr_t rel, bool allow_materialization) { D_ASSERT(rel && rel->rel); auto drel = rel->rel;