diff --git a/R/cpp11.R b/R/cpp11.R index d2336e063..500e61a84 100644 --- a/R/cpp11.R +++ b/R/cpp11.R @@ -32,8 +32,8 @@ rapi_unregister_arrow <- function(conn, name) { invisible(.Call(`_duckdb_rapi_unregister_arrow`, conn, name)) } -rapi_expr_reference <- function(name, table) { - .Call(`_duckdb_rapi_expr_reference`, name, table) +rapi_expr_reference <- function(rnames) { + .Call(`_duckdb_rapi_expr_reference`, rnames) } rapi_expr_constant <- function(val) { diff --git a/R/relational.R b/R/relational.R index f77f42902..3be93409d 100644 --- a/R/relational.R +++ b/R/relational.R @@ -1,18 +1,21 @@ # expressions #' Create a column reference expression -#' @param name the column name to be referenced +#' @param names the column name to be referenced, could be a list to refer to schema.table.column etc. #' @param table the optional table name or a relation object to be referenced #' @return a column reference expression #' @noRd #' @examples #' col_ref_expr <- expr_reference("some_column_name") #' col_ref_expr2 <- expr_reference("some_column_name", "some_table_name") -expr_reference <- function(name, table = "") { +expr_reference <- function(names, table = NULL) { if (inherits(table, "duckdb_relation")) { - table <- rel_alias(table) + names <- c(rel_alias(table), names) } - rapi_expr_reference(name, table) + if (is.character(table) && !identical(table, "")) { + names <- c(table, names) + } + rapi_expr_reference(names) } #' Create a constant expression diff --git a/src/cpp11.cpp b/src/cpp11.cpp index 228b5fac0..72f316327 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -68,10 +68,10 @@ extern "C" SEXP _duckdb_rapi_unregister_arrow(SEXP conn, SEXP name) { END_CPP11 } // relational.cpp -SEXP rapi_expr_reference(std::string name, std::string table); -extern "C" SEXP _duckdb_rapi_expr_reference(SEXP name, SEXP table) { +SEXP rapi_expr_reference(r_vector rnames); +extern "C" SEXP _duckdb_rapi_expr_reference(SEXP rnames) { BEGIN_CPP11 - return cpp11::as_sexp(rapi_expr_reference(cpp11::as_cpp>(name), cpp11::as_cpp>(table))); + return cpp11::as_sexp(rapi_expr_reference(cpp11::as_cpp>>(rnames))); END_CPP11 } // relational.cpp @@ -381,7 +381,7 @@ static const R_CallMethodDef CallEntries[] = { {"_duckdb_rapi_execute_arrow", (DL_FUNC) &_duckdb_rapi_execute_arrow, 2}, {"_duckdb_rapi_expr_constant", (DL_FUNC) &_duckdb_rapi_expr_constant, 1}, {"_duckdb_rapi_expr_function", (DL_FUNC) &_duckdb_rapi_expr_function, 4}, - {"_duckdb_rapi_expr_reference", (DL_FUNC) &_duckdb_rapi_expr_reference, 2}, + {"_duckdb_rapi_expr_reference", (DL_FUNC) &_duckdb_rapi_expr_reference, 1}, {"_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}, diff --git a/src/relational.cpp b/src/relational.cpp index a55041941..15f8469a9 100644 --- a/src/relational.cpp +++ b/src/relational.cpp @@ -46,17 +46,18 @@ external_pointer make_external_prot(const string &rclass, SEXP prot, ARGS &&. } // DuckDB Expressions -[[cpp11::register]] SEXP rapi_expr_reference(std::string name, std::string table) { - if (name.size() == 0) { - stop("expr_reference: Zero length name"); - } - if (!table.empty()) { - auto res = make_external("duckdb_expr", name, table); - res->alias = name; // TODO does this really make sense here? - return res; - } else { - return make_external("duckdb_expr", name); +[[cpp11::register]] SEXP rapi_expr_reference(r_vector rnames) { + if (rnames.size() == 0) { + stop("expr_reference: Zero length name vector"); + } + duckdb::vector names; + for (auto name : rnames) { + if (name.size() == 0) { + stop("expr_reference: Zero length name"); + } + names.push_back(name); } + return make_external("duckdb_expr", names);; } [[cpp11::register]] SEXP rapi_expr_constant(sexp val) {