Skip to content

Commit ea8cb5f

Browse files
authored
Merge pull request #588 from duckdb/f-un-enable
chore: Remove `enable_materialization` argument in favor of creating a new data frame when needed
2 parents 624951c + f043782 commit ea8cb5f

File tree

6 files changed

+14
-19
lines changed

6 files changed

+14
-19
lines changed

R/cpp11.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ rapi_rel_to_altrep <- function(rel, allow_materialization = TRUE) {
181181
.Call(`_duckdb_rapi_rel_to_altrep`, rel, allow_materialization)
182182
}
183183

184-
rapi_rel_from_altrep_df <- function(df, strict, allow_materialized, enable_materialization) {
185-
.Call(`_duckdb_rapi_rel_from_altrep_df`, df, strict, allow_materialized, enable_materialization)
184+
rapi_rel_from_altrep_df <- function(df, strict, allow_materialized) {
185+
.Call(`_duckdb_rapi_rel_from_altrep_df`, df, strict, allow_materialized)
186186
}
187187

188188
rapi_release <- function(stmt) {

R/relational.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,15 @@ rel_to_altrep <- function(rel, allow_materialization = TRUE) {
392392
#' @param strict whether to throw an error if the data frame is not an altrep
393393
#' or if other criteria are not met
394394
#' @param allow_materialized whether to succeed if the data frame is already materialized
395-
#' @param enable_materialization set to `TRUE` for side effect: allow materialization of this a data frame
396-
#' if it was not allowed previously
397395
#' @return the relation object
398396
#' @noRd
399397
#' @examples
400398
#' con <- DBI::dbConnect(duckdb())
401399
#' rel <- rel_from_df(con, mtcars)
402400
#' df = rel_to_altrep(rel)
403401
#' print(rel_from_altrep_df(df))
404-
rel_from_altrep_df <- function(df, strict = TRUE, allow_materialized = TRUE, enable_materialization = FALSE) {
405-
rethrow_rapi_rel_from_altrep_df(df, strict, allow_materialized, enable_materialization)
402+
rel_from_altrep_df <- function(df, strict = TRUE, allow_materialized = TRUE) {
403+
rethrow_rapi_rel_from_altrep_df(df, strict, allow_materialized)
406404
}
407405

408406

R/rethrow-gen.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,9 @@ rethrow_rapi_rel_to_altrep <- function(rel, allow_materialization = TRUE, call =
406406
)
407407
}
408408

409-
rethrow_rapi_rel_from_altrep_df <- function(df, strict, allow_materialized, enable_materialization, call = parent.frame(2)) {
409+
rethrow_rapi_rel_from_altrep_df <- function(df, strict, allow_materialized, call = parent.frame(2)) {
410410
rlang::try_fetch(
411-
rapi_rel_from_altrep_df(df, strict, allow_materialized, enable_materialization),
411+
rapi_rel_from_altrep_df(df, strict, allow_materialized),
412412
error = function(e) {
413413
rethrow_error_from_rapi(e, call)
414414
}

src/cpp11.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,10 @@ extern "C" SEXP _duckdb_rapi_rel_to_altrep(SEXP rel, SEXP allow_materialization)
329329
END_CPP11
330330
}
331331
// reltoaltrep.cpp
332-
SEXP rapi_rel_from_altrep_df(SEXP df, bool strict, bool allow_materialized, bool enable_materialization);
333-
extern "C" SEXP _duckdb_rapi_rel_from_altrep_df(SEXP df, SEXP strict, SEXP allow_materialized, SEXP enable_materialization) {
332+
SEXP rapi_rel_from_altrep_df(SEXP df, bool strict, bool allow_materialized);
333+
extern "C" SEXP _duckdb_rapi_rel_from_altrep_df(SEXP df, SEXP strict, SEXP allow_materialized) {
334334
BEGIN_CPP11
335-
return cpp11::as_sexp(rapi_rel_from_altrep_df(cpp11::as_cpp<cpp11::decay_t<SEXP>>(df), cpp11::as_cpp<cpp11::decay_t<bool>>(strict), cpp11::as_cpp<cpp11::decay_t<bool>>(allow_materialized), cpp11::as_cpp<cpp11::decay_t<bool>>(enable_materialization)));
335+
return cpp11::as_sexp(rapi_rel_from_altrep_df(cpp11::as_cpp<cpp11::decay_t<SEXP>>(df), cpp11::as_cpp<cpp11::decay_t<bool>>(strict), cpp11::as_cpp<cpp11::decay_t<bool>>(allow_materialized)));
336336
END_CPP11
337337
}
338338
// statement.cpp
@@ -472,7 +472,7 @@ static const R_CallMethodDef CallEntries[] = {
472472
{"_duckdb_rapi_rel_distinct", (DL_FUNC) &_duckdb_rapi_rel_distinct, 1},
473473
{"_duckdb_rapi_rel_explain", (DL_FUNC) &_duckdb_rapi_rel_explain, 1},
474474
{"_duckdb_rapi_rel_filter", (DL_FUNC) &_duckdb_rapi_rel_filter, 2},
475-
{"_duckdb_rapi_rel_from_altrep_df", (DL_FUNC) &_duckdb_rapi_rel_from_altrep_df, 4},
475+
{"_duckdb_rapi_rel_from_altrep_df", (DL_FUNC) &_duckdb_rapi_rel_from_altrep_df, 3},
476476
{"_duckdb_rapi_rel_from_df", (DL_FUNC) &_duckdb_rapi_rel_from_df, 3},
477477
{"_duckdb_rapi_rel_from_sql", (DL_FUNC) &_duckdb_rapi_rel_from_sql, 2},
478478
{"_duckdb_rapi_rel_from_table", (DL_FUNC) &_duckdb_rapi_rel_from_table, 3},

src/reltoaltrep.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static R_altrep_class_t LogicalTypeToAltrepType(const LogicalType &type) {
385385
return data_frame;
386386
}
387387

388-
[[cpp11::register]] SEXP rapi_rel_from_altrep_df(SEXP df, bool strict, bool allow_materialized, bool enable_materialization) {
388+
[[cpp11::register]] SEXP rapi_rel_from_altrep_df(SEXP df, bool strict, bool allow_materialized) {
389389
if (!Rf_inherits(df, "data.frame")) {
390390
if (strict) {
391391
cpp11::stop("rapi_rel_from_altrep_df: Not a data.frame");
@@ -439,12 +439,6 @@ static R_altrep_class_t LogicalTypeToAltrepType(const LogicalType &type) {
439439
}
440440
}
441441

442-
// Side effect comes last
443-
// FIXME: Add separate rapi_() function for this
444-
if (enable_materialization) {
445-
wrapper->rel->allow_materialization = true;
446-
}
447-
448442
return res;
449443
}
450444

tests/testthat/test-relational.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ test_that("rel_project does not automatically quote upper-case column names", {
809809
ref <- expr_reference(names(df))
810810
exprs <- list(ref)
811811
proj <- rel_project(rel, exprs)
812+
# FIXME: Change to rel_to_altrep() in 1.1.3
812813
ans <- rapi_rel_to_altrep(proj)
813814
expect_equal(df, ans)
814815
})
@@ -860,6 +861,7 @@ test_that("we don't crash with evaluation errors", {
860861
)
861862
)
862863

864+
# FIXME: Change to rel_to_altrep() in 1.1.3
863865
ans <- rapi_rel_to_altrep(rel2)
864866

865867
# This query is supposed to throw a runtime error.
@@ -891,6 +893,7 @@ test_that("we don't crash with evaluation errors", {
891893
)
892894
)
893895

896+
# FIXME: Change to rel_to_altrep() in 1.1.3
894897
ans <- rapi_rel_to_altrep(rel2)
895898

896899
# This query is supposed to throw a runtime error.

0 commit comments

Comments
 (0)