Skip to content

Commit 27bd3bc

Browse files
authored
feat: last_rel (#529)
1 parent f82d5e4 commit 27bd3bc

File tree

7 files changed

+29
-30
lines changed

7 files changed

+29
-30
lines changed

R/cpp11.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ rapi_rel_from_table_function <- function(con, function_name, positional_paramete
172172
.Call(`_duckdb_rapi_rel_from_table_function`, con, function_name, positional_parameters_sexps, named_parameters_sexps)
173173
}
174174

175-
rapi_get_last_rel_mat <- function() {
176-
.Call(`_duckdb_rapi_get_last_rel_mat`)
175+
rapi_get_last_rel <- function() {
176+
.Call(`_duckdb_rapi_get_last_rel`)
177177
}
178178

179179
# allow_materialization = TRUE: compatibility with duckplyr <= 0.4.1

R/relational.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,6 @@ load_rfuns <- function() {
476476
rethrow_rapi_load_rfuns()
477477
}
478478

479-
get_last_rel_mat <- function() {
480-
rethrow_rapi_get_last_rel_mat()
479+
get_last_rel <- function() {
480+
rethrow_rapi_get_last_rel()
481481
}

R/rethrow-gen.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,9 @@ rethrow_rapi_rel_from_table_function <- function(con, function_name, positional_
387387
)
388388
}
389389

390-
rethrow_rapi_get_last_rel_mat <- function(call = parent.frame(2)) {
390+
rethrow_rapi_get_last_rel <- function(call = parent.frame(2)) {
391391
rlang::try_fetch(
392-
rapi_get_last_rel_mat(),
392+
rapi_get_last_rel(),
393393
error = function(e) {
394394
rethrow_error_from_rapi(e, call)
395395
}
@@ -585,7 +585,7 @@ rethrow_restore <- function() {
585585
rethrow_rapi_rel_from_sql <<- rapi_rel_from_sql
586586
rethrow_rapi_rel_from_table <<- rapi_rel_from_table
587587
rethrow_rapi_rel_from_table_function <<- rapi_rel_from_table_function
588-
rethrow_rapi_get_last_rel_mat <<- rapi_get_last_rel_mat
588+
rethrow_rapi_get_last_rel <<- rapi_get_last_rel
589589
rethrow_rapi_rel_to_altrep <<- rapi_rel_to_altrep
590590
rethrow_rapi_rel_from_altrep_df <<- rapi_rel_from_altrep_df
591591
rethrow_rapi_release <<- rapi_release

src/cpp11.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,10 @@ extern "C" SEXP _duckdb_rapi_rel_from_table_function(SEXP con, SEXP function_nam
315315
END_CPP11
316316
}
317317
// reltoaltrep.cpp
318-
std::string rapi_get_last_rel_mat();
319-
extern "C" SEXP _duckdb_rapi_get_last_rel_mat() {
318+
SEXP rapi_get_last_rel();
319+
extern "C" SEXP _duckdb_rapi_get_last_rel() {
320320
BEGIN_CPP11
321-
return cpp11::as_sexp(rapi_get_last_rel_mat());
321+
return cpp11::as_sexp(rapi_get_last_rel());
322322
END_CPP11
323323
}
324324
// reltoaltrep.cpp
@@ -452,7 +452,7 @@ static const R_CallMethodDef CallEntries[] = {
452452
{"_duckdb_rapi_expr_set_alias", (DL_FUNC) &_duckdb_rapi_expr_set_alias, 2},
453453
{"_duckdb_rapi_expr_tostring", (DL_FUNC) &_duckdb_rapi_expr_tostring, 1},
454454
{"_duckdb_rapi_expr_window", (DL_FUNC) &_duckdb_rapi_expr_window, 9},
455-
{"_duckdb_rapi_get_last_rel_mat", (DL_FUNC) &_duckdb_rapi_get_last_rel_mat, 0},
455+
{"_duckdb_rapi_get_last_rel", (DL_FUNC) &_duckdb_rapi_get_last_rel, 0},
456456
{"_duckdb_rapi_get_null_SEXP_ptr", (DL_FUNC) &_duckdb_rapi_get_null_SEXP_ptr, 0},
457457
{"_duckdb_rapi_get_substrait", (DL_FUNC) &_duckdb_rapi_get_substrait, 3},
458458
{"_duckdb_rapi_get_substrait_json", (DL_FUNC) &_duckdb_rapi_get_substrait_json, 3},

src/include/rapi.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,17 @@ cpp11::r_string rapi_ptr_to_str(SEXP extptr);
218218
void duckdb_r_transform(duckdb::Vector &src_vec, SEXP dest, duckdb::idx_t dest_offset, duckdb::idx_t n, bool integer64);
219219
SEXP duckdb_r_allocate(const duckdb::LogicalType &type, duckdb::idx_t nrows);
220220
void duckdb_r_decorate(const duckdb::LogicalType &type, SEXP dest, bool integer64);
221+
222+
template <typename T, typename... ARGS>
223+
cpp11::external_pointer<T> make_external(const std::string &rclass, ARGS &&... args) {
224+
auto extptr = cpp11::external_pointer<T>(new T(std::forward<ARGS>(args)...));
225+
((cpp11::sexp)extptr).attr("class") = rclass;
226+
return extptr;
227+
}
228+
229+
template <typename T, typename... ARGS>
230+
cpp11::external_pointer<T> make_external_prot(const std::string &rclass, SEXP prot, ARGS &&... args) {
231+
auto extptr = cpp11::external_pointer<T>(new T(std::forward<ARGS>(args)...), true, true, prot);
232+
((cpp11::sexp)extptr).attr("class") = rclass;
233+
return extptr;
234+
}

src/relational.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@
3333
using namespace duckdb;
3434
using namespace cpp11;
3535

36-
template <typename T, typename... ARGS>
37-
external_pointer<T> make_external(const string &rclass, ARGS &&... args) {
38-
auto extptr = external_pointer<T>(new T(std::forward<ARGS>(args)...));
39-
((sexp)extptr).attr("class") = rclass;
40-
return extptr;
41-
}
42-
43-
template <typename T, typename... ARGS>
44-
external_pointer<T> make_external_prot(const string &rclass, SEXP prot, ARGS &&... args) {
45-
auto extptr = external_pointer<T>(new T(std::forward<ARGS>(args)...), true, true, prot);
46-
((sexp)extptr).attr("class") = rclass;
47-
return extptr;
48-
}
4936
// DuckDB Expressions
5037

5138
[[cpp11::register]] SEXP rapi_expr_reference(r_vector<r_string> rnames) {

src/reltoaltrep.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct AltrepRelationWrapper {
101101

102102
auto option = Rf_GetOption(RStrings::get().materialize_sym, R_BaseEnv);
103103
if (option != R_NilValue && !Rf_isNull(option) && LOGICAL_ELT(option, 0) == true) {
104-
Rprintf("duckplyr: materializing, review details with duckplyr::last_rel_mat()\n");
104+
Rprintf("duckplyr: materializing, review details with duckplyr::last_rel()\n");
105105
}
106106

107107
last_rel = rel;
@@ -338,11 +338,9 @@ static R_altrep_class_t LogicalTypeToAltrepType(const LogicalType &type) {
338338
}
339339
}
340340

341-
[[cpp11::register]] std::string rapi_get_last_rel_mat() {
342-
if (!AltrepRelationWrapper::last_rel) {
343-
return "";
344-
}
345-
return AltrepRelationWrapper::last_rel->ToString();
341+
[[cpp11::register]] SEXP rapi_get_last_rel() {
342+
auto last_rel = AltrepRelationWrapper::last_rel;
343+
return sexp(make_external_prot<RelationWrapper>("duckdb_relation", R_NilValue, std::move(last_rel)));
346344
}
347345

348346
[[cpp11::register]] SEXP rapi_rel_to_altrep(duckdb::rel_extptr_t rel, bool allow_materialization) {

0 commit comments

Comments
 (0)