Skip to content

Commit

Permalink
fix: Allow data frames as arguments to relational table-valued functions
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Sep 14, 2024
1 parent 698fc54 commit 6fc9050
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/include/typesr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ struct RApiTypes {
static LogicalType LogicalTypeFromRType(const RType &rtype, bool experimental);
static string DetectLogicalType(const LogicalType &stype, const char *caller);
static R_len_t GetVecSize(RType rtype, SEXP coldata);
static R_len_t GetVecSize(SEXP coldata, bool integer64 = false);
static Value SexpToValue(SEXP valsexp, R_len_t idx, bool typed_logical_null = true);
static SEXP ValueToSexp(Value &val, string &timezone_config);
};
Expand Down
4 changes: 2 additions & 2 deletions src/relational.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ static SEXP result_to_df(duckdb::unique_ptr<QueryResult> res) {
vector<Value> positional_parameters;

for (sexp parameter_sexp : positional_parameters_sexps) {
if (LENGTH(parameter_sexp) < 1) {
if (RApiTypes::GetVecSize(parameter_sexp) < 1) {
stop("rel_from_table_function: Can't have zero-length parameter");
}
positional_parameters.push_back(RApiTypes::SexpToValue(parameter_sexp, 0));
Expand All @@ -531,7 +531,7 @@ static SEXP result_to_df(duckdb::unique_ptr<QueryResult> res) {
}
R_xlen_t named_parameter_idx = 0;
for (sexp parameter_sexp : named_parameters_sexps) {
if (LENGTH(parameter_sexp) != 1) {
if (RApiTypes::GetVecSize(parameter_sexp) != 1) {
stop("rel_from_table_function: Need scalar parameter");
}
named_parameters[names[named_parameter_idx]] = RApiTypes::SexpToValue(parameter_sexp, 0);
Expand Down
5 changes: 5 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ R_len_t RApiTypes::GetVecSize(RType rtype, SEXP coldata) {
return Rf_length(coldata);
}

R_len_t RApiTypes::GetVecSize(SEXP coldata, bool integer64) {
auto rtype = DetectRType(coldata, integer64);
return GetVecSize(rtype, coldata);
}

Value RApiTypes::SexpToValue(SEXP valsexp, R_len_t idx, bool typed_logical_null) {
auto rtype = RApiTypes::DetectRType(valsexp, false); // TODO
switch (rtype.id()) {
Expand Down

0 comments on commit 6fc9050

Please sign in to comment.