Skip to content

Commit

Permalink
patch fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tmonster committed Sep 15, 2023
1 parent 64a2f25 commit 912a88b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
11 changes: 7 additions & 4 deletions R/relational.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 11 additions & 10 deletions src/relational.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ external_pointer<T> 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<ColumnRefExpression>("duckdb_expr", name, table);
res->alias = name; // TODO does this really make sense here?
return res;
} else {
return make_external<ColumnRefExpression>("duckdb_expr", name);
[[cpp11::register]] SEXP rapi_expr_reference(r_vector<r_string> rnames) {
if (rnames.size() == 0) {
stop("expr_reference: Zero length name vector");
}
duckdb::vector<std::string> names;
for (auto name : rnames) {
if (name.size() == 0) {
stop("expr_reference: Zero length name");
}
names.push_back(name);
}
return make_external<ColumnRefExpression>("duckdb_expr", names);;
}

[[cpp11::register]] SEXP rapi_expr_constant(sexp val) {
Expand Down

0 comments on commit 912a88b

Please sign in to comment.