From 240052da9c2b237176ffd330dfc0ce2a91ed4afb Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Wed, 8 May 2024 18:15:25 +0200 Subject: [PATCH] expr_constant(NA) --- src/relational.cpp | 5 ++++- tests/testthat/test-relational.R | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/relational.cpp b/src/relational.cpp index bc4bda5eb..e6e91e305 100644 --- a/src/relational.cpp +++ b/src/relational.cpp @@ -61,10 +61,13 @@ external_pointer make_external_prot(const string &rclass, SEXP prot, ARGS &&. } [[cpp11::register]] SEXP rapi_expr_constant(sexp val) { + if (val == R_NilValue) { + return make_external("duckdb_expr", Value(LogicalType::SQLNULL)); + } if (LENGTH(val) != 1) { stop("expr_constant: Need value of length one"); } - return make_external("duckdb_expr", RApiTypes::SexpToValue(val, 0, false)); + return make_external("duckdb_expr", RApiTypes::SexpToValue(val, 0, true)); } [[cpp11::register]] SEXP rapi_expr_function(std::string name, list args, list order_bys, list filter_bys) { diff --git a/tests/testthat/test-relational.R b/tests/testthat/test-relational.R index f0edc1a70..0441b2a38 100644 --- a/tests/testthat/test-relational.R +++ b/tests/testthat/test-relational.R @@ -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) @@ -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()))