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

expr_constant(NA) #167

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion src/relational.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ external_pointer<T> make_external_prot(const string &rclass, SEXP prot, ARGS &&.
}

[[cpp11::register]] SEXP rapi_expr_constant(sexp val) {
if (val == R_NilValue) {
return make_external<ConstantExpression>("duckdb_expr", Value(LogicalType::SQLNULL));
}
if (LENGTH(val) != 1) {
stop("expr_constant: Need value of length one");
}
return make_external<ConstantExpression>("duckdb_expr", RApiTypes::SexpToValue(val, 0, false));
return make_external<ConstantExpression>("duckdb_expr", RApiTypes::SexpToValue(val, 0, true));
}

[[cpp11::register]] SEXP rapi_expr_function(std::string name, list args, list order_bys, list filter_bys) {
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-relational.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ test_that("we can create various expressions and don't crash", {
expect_error(expr_reference(""))
expect_error(expr_reference(NULL))

expr_constant(NULL)
expr_constant(TRUE)
expr_constant(FALSE)
expr_constant(NA)
Expand All @@ -62,10 +63,8 @@ test_that("we can create various expressions and don't crash", {
const <- expr_constant("asdf")
print(const)

expect_error(expr_constant(NULL))
expect_error(expr_constant())


expr_function("asdf", list())

expect_error(expr_function("", list()))
Expand Down
Loading