Skip to content

Commit

Permalink
version 0.8.1-2
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes authored and cran-robot committed Aug 25, 2023
1 parent 9226020 commit a011d42
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 70 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: duckdb
Title: DBI Package for the DuckDB Database Management System
Version: 0.8.1-1
Version: 0.8.1-2
Authors@R:
c(person(given = "Hannes",
family = "Mühleisen",
Expand Down Expand Up @@ -49,7 +49,7 @@ Suggests: arrow, bit64, callr, DBItest, dplyr, dbplyr, rlang, testthat,
Encoding: UTF-8
RoxygenNote: 7.2.3
NeedsCompilation: yes
Packaged: 2023-07-17 13:01:26 UTC; hannes
Packaged: 2023-08-25 07:12:45 UTC; kirill
Author: Hannes Mühleisen [aut, cre] (<https://orcid.org/0000-0001-8552-0029>),
Mark Raasveldt [aut] (<https://orcid.org/0000-0001-5005-6844>),
Stichting DuckDB Foundation [cph],
Expand Down Expand Up @@ -78,4 +78,4 @@ Author: Hannes Mühleisen [aut, cre] (<https://orcid.org/0000-0001-8552-0029>),
PCG Project contributors [cph]
Maintainer: Hannes Mühleisen <[email protected]>
Repository: CRAN
Date/Publication: 2023-07-17 19:50:08 UTC
Date/Publication: 2023-08-25 14:50:02 UTC
33 changes: 18 additions & 15 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
4a621f9382e8f478266d9c67bb5b8bb5 *DESCRIPTION
7ed633426be62ce6294fa4d4074eb1ad *DESCRIPTION
6793c89d1af721728c4d58c99d5b9d30 *LICENSE
e975be1b49bcc0e567737d712d3e3cc8 *NAMESPACE
ced14ada4cfff8a89e7feb2203f589fb *R/Connection.R
020754c4367c905a2a063f2c8a286ebf *R/Connection.R
91c325c3a74cc6795a82cac48f471fa3 *R/Driver.R
ffaef65bbcda5b3ba21238b82bce945e *R/Result.R
1b19f326281b21675272963c31a52816 *R/Result.R
d0ef7160705dbda6bfa1a4f64cdcd036 *R/Viewer.R
fdc48d3020beeb6cd3285a54a0033bcb *R/backend-dbplyr__duckdb_connection.R
02d714be6689e35f22b89efab32aa095 *R/backend-dbplyr__duckdb_connection.R
2db929241b4ff8a8df57623513228184 *R/cpp11.R
d49f39f1e48e4dedb7534852ff82d37c *R/csv.R
dd4470c96c18d554032e42de78a4a49f *R/dbAppendTable__duckdb_connection.R
Expand All @@ -14,7 +14,7 @@ dd4470c96c18d554032e42de78a4a49f *R/dbAppendTable__duckdb_connection.R
c8258883a4c6568425d2e855aa1907da *R/dbClearResult__duckdb_result.R
07635ddf3e35a5cb81c94d4ca62c314f *R/dbColumnInfo__duckdb_result.R
96da806c02ffbfcc8c7bdbc23b04d7da *R/dbCommit__duckdb_connection.R
d22f52b957888a7734ff48f48832996f *R/dbConnect__duckdb_driver.R
8e2ba2b5cc33da139e0543d6e47e2755 *R/dbConnect__duckdb_driver.R
0acc42e921d89f2d65b2f53391e0b9c1 *R/dbDataType__duckdb_connection.R
9738c730904876bffc2fedb5cf603794 *R/dbDataType__duckdb_driver.R
0a4ffb009247ea7406b0557441152681 *R/dbDisconnect__duckdb_connection.R
Expand Down Expand Up @@ -48,16 +48,16 @@ e48e0f4d25ce5a055ce7df9b95f99082 *R/show__duckdb_driver.R
8dccf29cb4095ecb8722e8f8731dbc69 *R/show__duckdb_result.R
864c0e9b6d8b508b57234347d3d1d360 *R/sql.R
f3ae5b73437b0149357f91f20741ee7d *R/substrait.R
9a728d72a986d6af11a632eb0c8fcd1b *R/zzz.R
189ce5ba8d8483c372b8961817c1bfbf *README.md
6ef65b78d5a154855e7e7709b8a89c60 *R/zzz.R
a9aab4bcaefc5b07326a047127c88585 *README.md
95645911d270eeea9ebcdc773288dbed *inst/icons/duckdb.png
e8a15f1b5781b5d2803afe6ab00d6404 *inst/include/cpp11.hpp
ac46452ffea887725873cc0608f5025d *inst/include/cpp11/R.hpp
d146ab6c79c037331fd3bd99d5739c4b *inst/include/cpp11/altrep.hpp
b577ac42eb0aeaca47a811a7ed63568d *inst/include/cpp11/as.hpp
19239fd0521865044d48fb9b53017afb *inst/include/cpp11/attribute_proxy.hpp
dd330b4252b03edc39a35fded7420487 *inst/include/cpp11/data_frame.hpp
f70bf6d07cf5c94ed61504a799dab0e0 *inst/include/cpp11/declarations.hpp
14d6e0185a877260325764e51718e7ca *inst/include/cpp11/declarations.hpp
15f3dafbd512e527a36b6264f01897a6 *inst/include/cpp11/doubles.hpp
a675556cd67b8898f5593319a6504a16 *inst/include/cpp11/environment.hpp
99a5723507db2ab211a44dc6c1a493f5 *inst/include/cpp11/external_pointer.hpp
Expand All @@ -68,7 +68,7 @@ db94f12cca5bf0fc32e24fe818106300 *inst/include/cpp11/list.hpp
4b22e60584cc8ae8a3e28e018d6da5dd *inst/include/cpp11/logicals.hpp
0be378f1d599c9fb84deb6a0f01a7358 *inst/include/cpp11/matrix.hpp
8efb781a399a0676e1b3dbd5ea3b8d8d *inst/include/cpp11/named_arg.hpp
f4fd2e4f609f940fe9702d12b80cf230 *inst/include/cpp11/protect.hpp
0de15dfa3de4f9f7c20de1ba06becfa3 *inst/include/cpp11/protect.hpp
e3711a64328f128b523e72b1cb1dda57 *inst/include/cpp11/r_bool.hpp
e43bc609629e112a12443ecdfb196223 *inst/include/cpp11/r_string.hpp
e1315e2cbc06e18314e40161e9057110 *inst/include/cpp11/r_vector.hpp
Expand Down Expand Up @@ -2574,13 +2574,13 @@ bb87e7725e015e2a819b931e6b016e4c *src/duckdb/ub_src_transaction.cpp
c5b82a8a7752d56fe8f8b680cb7c6739 *src/include/rapi.hpp
bfab5b7ebf664cfa9be8b9e23637cde6 *src/include/reltoaltrep.hpp
ad38f5bba84a80f446bb280673dc237f *src/include/typesr.hpp
7fb4b61602795fd02ac2dd7905229fb2 *src/register.cpp
2f3291ac253e9400e34b38559565e477 *src/relational.cpp
fb21581a23e55322399543f4a8988a40 *src/reltoaltrep.cpp
368e7be49467a6409c1aaca0950c89ef *src/register.cpp
67d6f1c97b7f9e0fb337e6e8fd1fb068 *src/relational.cpp
cf10fa41c6993e787c1cf2ef439c23a4 *src/reltoaltrep.cpp
d15a20201fdbed81487c64a0dbb689b1 *src/scan.cpp
88f6f21f6578739bd4f4894a82d3b67e *src/statement.cpp
e9aca686f387592f8c699e2f5a85fd55 *src/transform.cpp
62d774991cae5c1d23ddceb875c38aee *src/types.cpp
042a848f7cc328a4780ca05be49e1721 *src/types.cpp
02f8c7789e450b229e5c7bf9ac1742f2 *src/utils.cpp
78ca03523e01aa272eeb2f0bd5a53011 *tests/testthat.R
96ce833955091e793c1265569d5063ab *tests/testthat/_snaps/backend-dbplyr__duckdb_connection.md
Expand All @@ -2590,9 +2590,11 @@ b685427653b6f6080c558a8386e7b5c4 *tests/testthat/_snaps/multi_statement.md
dabf0e452e677b9c7afaca658ac8371b *tests/testthat/data/binary_string.parquet
2f67292983870c49f4ee50330c4f7b7f *tests/testthat/data/userdata1.parquet
389e9753304e62c280e1b5eafbfc2cbd *tests/testthat/helper-DBItest.R
c5cf38e3b1ceb04719b174f0791b301c *tests/testthat/helper-arrow.R
da441e8ef9a6b41b9d166500608413af *tests/testthat/test-DBItest.R
416307e283e6ab4d585f42ae1479f73b *tests/testthat/test-dbQuoteIdentifier__duckdb_connection.R
2f2914ae28fe3864659d945414650dd5 *tests/testthat/test-rel_api.R
057e655ecc463501f146bdf4e6b54d9b *tests/testthat/test-shutdown.R
bf47c0f3a0781587def97c78490cf625 *tests/testthat/test_ambiguous_prepare.R
c3f90eb02a950bdd18a9cf5afe70d6de *tests/testthat/test_arrow.R
5ad34cfb89166055e124f96647314361 *tests/testthat/test_arrow_recordbatchreader.py
Expand All @@ -2618,9 +2620,10 @@ c6b302ba389c7cedd5aae6bb7fa3731a *tests/testthat/test_parquet.R
a3ce818c4cb2c7c4dd435207fb19c747 *tests/testthat/test_register.R
60434301f7c5e98861b7620cd7035091 *tests/testthat/test_register_arrow.R
891908e0804e2315fa13285f1005a689 *tests/testthat/test_register_readonly.R
1628b8687408ce019baec5acae74918b *tests/testthat/test_relational.R
c9ddbd8f771cc4330f1906ae1b64001b *tests/testthat/test_relational.R
1439bba03df63e03d87acfe916b5e62f *tests/testthat/test_struct.R
ff31415409c10783fc36512cc6ef7920 *tests/testthat/test_tbl__duckdb_connection.R
6f39a7ff5f8d75716824165d951473e4 *tests/testthat/test_timezone.R
b3d7eab44a600a5c4df348969b4a2a85 *tests/testthat/test_timestamp.R
3458bc88f78f37e7b3ce9d0b5756ddb3 *tests/testthat/test_timezone.R
0d70b43b41ce312eb3cb0c418ca2840f *tests/testthat/test_types.R
f61a2bf9f4e00271fc78209a04c0fa07 *tests/testthat/test_viewer.R
26 changes: 14 additions & 12 deletions R/Connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
#' @aliases duckdb_driver
#' @keywords internal
#' @export
setClass("duckdb_driver", contains = "DBIDriver", slots = list(database_ref = "externalptr", dbdir = "character", read_only = "logical", bigint = "character"))
setClass("duckdb_driver", contains = "DBIDriver", slots = list(
database_ref = "externalptr",
dbdir = "character",
read_only = "logical",
bigint = "character"
))

#' DuckDB connection class
#'
Expand All @@ -14,17 +19,14 @@ setClass("duckdb_driver", contains = "DBIDriver", slots = list(database_ref = "e
#' @aliases duckdb_connection
#' @keywords internal
#' @export
setClass("duckdb_connection",
contains = "DBIConnection",
slots = list(
conn_ref = "externalptr",
driver = "duckdb_driver",
debug = "logical",
timezone_out = "character",
tz_out_convert = "character",
reserved_words = "character"
)
)
setClass("duckdb_connection", contains = "DBIConnection", slots = list(
conn_ref = "externalptr",
driver = "duckdb_driver",
debug = "logical",
timezone_out = "character",
tz_out_convert = "character",
reserved_words = "character"
))

duckdb_connection <- function(duckdb_driver, debug) {
out <- new(
Expand Down
4 changes: 2 additions & 2 deletions R/Result.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ tz_convert <- function(x, timezone) {
}

tz_force <- function(x, timezone) {
# convert to character, stripping the timezone
ct <- as.character(x, usetz = FALSE)
# convert to character in ISO format, stripping the timezone
ct <- format(x, format = "%Y-%m-%d %H:%M:%OS", usetz = FALSE)
# recreate the POSIXct with specified timezone
as.POSIXct(ct, tz = timezone)
}
18 changes: 0 additions & 18 deletions R/backend-dbplyr__duckdb_connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -367,24 +367,6 @@ sql_escape_datetime.duckdb_connection <- function(con, x) {
dbQLit(con, x)
}

# Customized translation for fill function
# @param .con A \code{\link{dbConnect}} object, as returned by \code{dbConnect()}
# @param .data Data frame
# @param cols_to_fill Which colums to be altered
# @param order_by_cols Defined order of variables
# @param .direction Direction in which to fill missing values.
# @name dbplyr_fill0
dbplyr_fill0.duckdb_connection <- function(.con, .data, cols_to_fill, order_by_cols, .direction) {
dbplyr_fill0 <- pkg_method("dbplyr_fill0.SQLiteConnection", "dbplyr")

# Required because of the bug in dbplyr (con is not passed to "translate_sql(cumsum..." call)
# See https://github.com/tidyverse/dbplyr/pull/753
setcon <- pkg_method("set_current_con", "dbplyr")
setcon(.con)

dbplyr_fill0(.con, .data, cols_to_fill, order_by_cols, .direction)
}

# Customized handling for tbl() to allow the use of replacement scans
# @param src .con A \code{\link{dbConnect}} object, as returned by \code{dbConnect()}
# @param from Table or parquet/csv -files to be registered
Expand Down
1 change: 0 additions & 1 deletion R/dbConnect__duckdb_driver.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ dbConnect__duckdb_driver <- function(drv, dbdir = DBDIR_MEMORY, ...,

# aha, a late comer. let's make a new instance.
if (!missing_dbdir && dbdir != drv@dbdir) {
duckdb_shutdown(drv)
drv <- duckdb(dbdir, read_only, bigint, config)
}

Expand Down
1 change: 0 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
s3_register("dbplyr::dbplyr_edition", "duckdb_connection")
s3_register("dbplyr::db_connection_describe", "duckdb_connection")
s3_register("dbplyr::sql_translation", "duckdb_connection")
s3_register("dbplyr::dbplyr_fill0", "duckdb_connection")
s3_register("dbplyr::sql_expr_matches", "duckdb_connection")
s3_register("dbplyr::sql_escape_date", "duckdb_connection")
s3_register("dbplyr::sql_escape_datetime", "duckdb_connection")
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,21 @@ DUCKDB_R_DEBUG=1
```

If you do this, remember to use `--vanilla` for building release builds.

### Developing with Extensions
If you wish to build or add extensions to the R package you first need to build duckdb with the
`extension_static_build` flag and move the desired extension to a location where it won't be
modified by other build scripts. The following commands allow you to add the httpfs extension to
a duckdb R build. See the [extension ReadMe](https://github.com/duckdb/duckdb/tree/master/extension#readme) for more
information about extensions
```sh
cd duckdb/
EXTENSION_STATIC_BUILD=1 make
mv ./build/release/extension/httpfs/httpfs.duckdb_extension {{untouched_path}}/httpfs-extension.duckdb_extension
```
Then in R
```r
library(“duckdb”)
con <- DBI::dbConnect(duckdb(config=list(“allow_unsigned_extensions=true”)))
dbExecute(con, “LOAD {{untouched_path}}/httpfs-extension.duckdb_extension")
```
5 changes: 3 additions & 2 deletions inst/include/cpp11/declarations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ T& unmove(T&& t) {
SEXP err = R_NilValue; \
char buf[CPP11_ERROR_BUFSIZE] = ""; \
try {
#define END_CPP11 \
#define END_CPP11_EX(RET) \
} \
catch (cpp11::unwind_exception & e) { \
err = e.token; \
Expand All @@ -51,4 +51,5 @@ T& unmove(T&& t) {
} else if (err != R_NilValue) { \
CPP11_UNWIND \
} \
return R_NilValue;
return RET;
#define END_CPP11 END_CPP11_EX(R_NilValue)
15 changes: 4 additions & 11 deletions inst/include/cpp11/protect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,10 @@ void stop [[noreturn]] (const std::string& fmt_arg, Args&&... args) {
safe.noreturn(Rf_errorcall)(R_NilValue, "%s", msg.c_str());
}

template <typename... Args>
void warning(const char* fmt_arg, Args&&... args) {
std::string msg = fmt::format(fmt_arg, std::forward<Args>(args)...);
safe[Rf_warningcall](R_NilValue, "%s", msg.c_str());
}
// Always making copy of string to avoid weird unwind behavior.

template <typename... Args>
void warning(const std::string& fmt_arg, Args&&... args) {
void warning(const std::string fmt_arg, Args&&... args) {
std::string msg = fmt::format(fmt_arg, std::forward<Args>(args)...);
safe[Rf_warningcall](R_NilValue, "%s", msg.c_str());
}
Expand All @@ -287,13 +283,10 @@ void stop [[noreturn]] (const std::string& fmt, Args... args) {
safe.noreturn(Rf_errorcall)(R_NilValue, fmt.c_str(), args...);
}

template <typename... Args>
void warning(const char* fmt, Args... args) {
safe[Rf_warningcall](R_NilValue, fmt, args...);
}
// Always making copy of string to avoid weird unwind behavior.

template <typename... Args>
void warning(const std::string& fmt, Args... args) {
void warning(const std::string fmt, Args... args) {
safe[Rf_warningcall](R_NilValue, fmt.c_str(), args...);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ using namespace duckdb;
static_cast<cpp11::sexp>(conn).attr("_registered_df_" + name) = R_NilValue;
auto res = conn->conn->Query("DROP VIEW IF EXISTS \"" + name + "\"");
if (res->HasError()) {
cpp11::stop(res->GetError().c_str());
cpp11::stop("%s", res->GetError().c_str());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/relational.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ bool constant_expression_is_not_null(duckdb::expr_extptr_t expr) {

static SEXP result_to_df(duckdb::unique_ptr<QueryResult> res) {
if (res->HasError()) {
stop(res->GetError());
stop("%s", res->GetError().c_str());
}
if (res->type == QueryResultType::STREAM_RESULT) {
res = ((StreamQueryResult &)*res).Materialize();
Expand Down Expand Up @@ -420,7 +420,7 @@ static SEXP result_to_df(duckdb::unique_ptr<QueryResult> res) {
[[cpp11::register]] SEXP rapi_rel_sql(duckdb::rel_extptr_t rel, std::string sql) {
auto res = rel->rel->Query("_", sql);
if (res->HasError()) {
stop(res->GetError());
stop("%s", res->GetError().c_str());
}
return result_to_df(std::move(res));
}
Expand Down
19 changes: 18 additions & 1 deletion src/reltoaltrep.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "rapi.hpp"
#include "typesr.hpp"
#include "reltoaltrep.hpp"
#include "cpp11/declarations.hpp"

using namespace duckdb;

Expand Down Expand Up @@ -68,7 +69,7 @@ struct AltrepRelationWrapper {
}
res = rel->Execute();
if (res->HasError()) {
cpp11::stop(res->GetError().c_str());
cpp11::stop("Error evaluating duckdb query: %s", res->GetError().c_str());
}
D_ASSERT(res->type == QueryResultType::MATERIALIZED_RESULT);
}
Expand Down Expand Up @@ -129,16 +130,20 @@ struct AltrepVectorWrapper {

Rboolean RelToAltrep::RownamesInspect(SEXP x, int pre, int deep, int pvec,
void (*inspect_subtree)(SEXP, int, int, int)) {
BEGIN_CPP11
AltrepRownamesWrapper::Get(x); // make sure this is alive
Rprintf("DUCKDB_ALTREP_REL_ROWNAMES\n");
return TRUE;
END_CPP11_EX(FALSE)
}

Rboolean RelToAltrep::RelInspect(SEXP x, int pre, int deep, int pvec, void (*inspect_subtree)(SEXP, int, int, int)) {
BEGIN_CPP11
auto wrapper = AltrepVectorWrapper::Get(x); // make sure this is alive
auto &col = wrapper->rel->rel->Columns()[wrapper->column_index];
Rprintf("DUCKDB_ALTREP_REL_VECTOR %s (%s)\n", col.Name().c_str(), col.Type().ToString().c_str());
return TRUE;
END_CPP11_EX(FALSE)
}

// this allows us to set row names on a data frame with an int argument without calling INTPTR on it
Expand All @@ -150,31 +155,43 @@ static void install_new_attrib(SEXP vec, SEXP name, SEXP val) {
}

R_xlen_t RelToAltrep::RownamesLength(SEXP x) {
// The BEGIN_CPP11 isn't strictly necessary here, but should be optimized away.
// It will become important if we ever support row names.
BEGIN_CPP11
// row.names vector has length 2 in the "compact" case which we're using
// see https://stat.ethz.ch/R-manual/R-devel/library/base/html/row.names.html
return 2;
END_CPP11_EX(0)
}

void *RelToAltrep::RownamesDataptr(SEXP x, Rboolean writeable) {
BEGIN_CPP11
auto rownames_wrapper = AltrepRownamesWrapper::Get(x);
auto row_count = rownames_wrapper->rel->GetQueryResult()->RowCount();
if (row_count > (idx_t)NumericLimits<int32_t>::Maximum()) {
cpp11::stop("Integer overflow for row.names attribute");
}
rownames_wrapper->rowlen_data[1] = -row_count;
return rownames_wrapper->rowlen_data;
END_CPP11
}

R_xlen_t RelToAltrep::VectorLength(SEXP x) {
BEGIN_CPP11
return AltrepVectorWrapper::Get(x)->rel->GetQueryResult()->RowCount();
END_CPP11_EX(0)
}

void *RelToAltrep::VectorDataptr(SEXP x, Rboolean writeable) {
BEGIN_CPP11
return AltrepVectorWrapper::Get(x)->Dataptr();
END_CPP11
}

SEXP RelToAltrep::VectorStringElt(SEXP x, R_xlen_t i) {
BEGIN_CPP11
return STRING_ELT(AltrepVectorWrapper::Get(x)->Vector(), i);
END_CPP11
}

static R_altrep_class_t LogicalTypeToAltrepType(const LogicalType &type) {
Expand Down
Loading

0 comments on commit a011d42

Please sign in to comment.