diff --git a/R/relational.R b/R/relational.R index f77f42902..08b2f7e15 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)) { + names <- c(table, names) + } + rapi_expr_reference(names) } #' Create a constant expression 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) {