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

feat: Only allow constants in mutate() that are actually representable in duckdb #73

Merged
merged 1 commit into from
Nov 12, 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
20 changes: 15 additions & 5 deletions R/relational-duckdb.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ duckdb_rel_from_df <- function(df) {
df <- as_duckplyr_df(df)
}

out <- check_df_for_rel(df)

meta_rel_register_df(out, df)

out

# Causes protection errors
# duckdb$rel_from_df(get_default_duckdb_connection(), df)
}

# FIXME: This should be duckdb's responsibility
check_df_for_rel <- function(df) {
if (is.character(.row_names_info(df, 0L))) {
stop("Need data frame without row names to convert to relational.")
}
Expand Down Expand Up @@ -133,12 +145,7 @@ duckdb_rel_from_df <- function(df) {
}
}

meta_rel_register_df(out, df)

out

# Causes protection errors
# duckdb$rel_from_df(get_default_duckdb_connection(), df)
}

#' @export
Expand Down Expand Up @@ -370,6 +377,9 @@ to_duckdb_expr <- function(x) {
out
},
relational_relexpr_constant = {
# FIXME: Should be duckdb's responsibility
check_df_for_rel(tibble(constant = x$val))

if ("experimental" %in% names(formals(duckdb$expr_constant))) {
experimental <- (Sys.getenv("DUCKPLYR_EXPERIMENTAL") == "TRUE")
out <- duckdb$expr_constant(x$val, experimental = experimental)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/relational-duckdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
data.frame(a = vctrs::new_vctr(1:3)) %>% duckdb_rel_from_df()
Condition
Error in `duckdb_rel_from_df()`:
Error in `check_df_for_rel()`:
! Attributes are lost during conversion. Affected column: `a`.

# rel_aggregate()
Expand Down
Loading