Skip to content

Commit

Permalink
version 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes authored and cran-robot committed May 23, 2023
1 parent fb18a2d commit 782630b
Show file tree
Hide file tree
Showing 1,874 changed files with 102,900 additions and 54,069 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.7.1-1
Version: 0.8.0
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-03-01 09:31:23 UTC; hannes
Packaged: 2023-05-17 10:59:29 UTC; hannes
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 <hannes@cwi.nl>
Repository: CRAN
Date/Publication: 2023-03-01 12:50:02 UTC
Date/Publication: 2023-05-23 10:52:11 UTC
3,487 changes: 1,824 additions & 1,663 deletions MD5

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion R/backend-dbplyr__duckdb_connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ dbplyr_fill0.duckdb_connection <- function(.con, .data, cols_to_fill, order_by_c
# @param cache Enable object cache for parquet files
tbl.duckdb_connection <- function(src, from, cache = FALSE, ...) {
ident_q <- pkg_method("ident_q", "dbplyr")
if (!DBI::dbExistsTable(src, from)) from <- ident_q(from)
if (!inherits(from, "sql") & !DBI::dbExistsTable(src, from)) from <- ident_q(from)
if (cache) DBI::dbExecute(src, "PRAGMA enable_object_cache")
NextMethod("tbl")
}
Expand Down
20 changes: 18 additions & 2 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ rapi_expr_constant <- function(val) {
.Call(`_duckdb_rapi_expr_constant`, val)
}

rapi_expr_function <- function(name, args) {
.Call(`_duckdb_rapi_expr_function`, name, args)
rapi_expr_function <- function(name, args, order_bys, filter_bys) {
.Call(`_duckdb_rapi_expr_function`, name, args, order_bys, filter_bys)
}

rapi_expr_set_alias <- function(expr, alias) {
Expand Down Expand Up @@ -72,6 +72,10 @@ rapi_rel_order <- function(rel, orders) {
.Call(`_duckdb_rapi_rel_order`, rel, orders)
}

rapi_expr_window <- function(window_function, partitions, order_bys, window_boundary_start, window_boundary_end, start_expr, end_expr, offset_expr, default_expr) {
.Call(`_duckdb_rapi_expr_window`, window_function, partitions, order_bys, window_boundary_start, window_boundary_end, start_expr, end_expr, offset_expr, default_expr)
}

rapi_rel_join <- function(left, right, conds, join) {
.Call(`_duckdb_rapi_rel_join`, left, right, conds, join)
}
Expand All @@ -96,6 +100,10 @@ rapi_rel_tostring <- function(rel) {
.Call(`_duckdb_rapi_rel_tostring`, rel)
}

rapi_rel_to_sql <- function(rel) {
.Call(`_duckdb_rapi_rel_to_sql`, rel)
}

rapi_rel_explain <- function(rel) {
.Call(`_duckdb_rapi_rel_explain`, rel)
}
Expand All @@ -104,6 +112,10 @@ rapi_rel_alias <- function(rel) {
.Call(`_duckdb_rapi_rel_alias`, rel)
}

rapi_get_null_SEXP_ptr <- function() {
.Call(`_duckdb_rapi_get_null_SEXP_ptr`)
}

rapi_rel_set_alias <- function(rel, alias) {
.Call(`_duckdb_rapi_rel_set_alias`, rel, alias)
}
Expand All @@ -128,6 +140,10 @@ rapi_rel_set_symdiff <- function(rel_a, rel_b) {
.Call(`_duckdb_rapi_rel_set_symdiff`, rel_a, rel_b)
}

rapi_rel_from_table <- function(con, schema_name, table_name) {
.Call(`_duckdb_rapi_rel_from_table`, con, schema_name, table_name)
}

rapi_rel_to_altrep <- function(rel) {
.Call(`_duckdb_rapi_rel_to_altrep`, rel)
}
Expand Down
1 change: 0 additions & 1 deletion R/register.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ encode_values <- function(value) {
#' dbReadTable(con, "data")
#'
#' duckdb_unregister(con, "data")
#' try(dbReadTable(con, "data"))
#'
#' dbDisconnect(con)
duckdb_register <- function(conn, name, df, overwrite = FALSE, experimental = FALSE) {
Expand Down
75 changes: 73 additions & 2 deletions R/relational.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ expr_constant <- rapi_expr_constant
#' @noRd
#' @examples
#' call_expr <- expr_function("ABS", list(expr_constant(-42)))
expr_function <- rapi_expr_function
expr_function <- function(name, args, order_bys = list(), filter_bys = list()) {
rapi_expr_function(name, args, order_bys, filter_bys)
}

#' Convert an expression to a string for debugging purposes
#' @param expr the expression
Expand Down Expand Up @@ -151,6 +153,48 @@ rel_aggregate <- rapi_rel_aggregate
#' rel2 <- rel_order(rel, list(expr_reference("hp")))
rel_order <- rapi_rel_order

#' Get an external pointer pointing to NULL
#' @return an external pointer pointing to null_ptr.
#' @noRd
#' @examples
#' null_ptr <- sexp_null_ptr()
sexp_null_ptr <- rapi_get_null_SEXP_ptr

expr_window <- function(window_function, partitions=list(), order_bys=list(),
window_boundary_start="unbounded_preceding",
window_boundary_end="current_row_range",
start_expr = NULL, end_expr=NULL, offset_expr=NULL, default_expr=NULL) {
null_ptr <- sexp_null_ptr()
if (is.null(start_expr)) {
start_expr <- null_ptr
}
if (is.null(end_expr)) {
end_expr <- null_ptr
}
if (is.null(offset_expr)) {
offset_expr <- null_ptr
}
if (is.null(default_expr)) {
default_expr <- null_ptr
}
expr_window_(window_function, partitions, order_bys, tolower(window_boundary_start), tolower(window_boundary_end), start_expr, end_expr, offset_expr, default_expr)
}

window_boundaries <- c("unbounded_preceding",
"unbounded_following",
"current_row_range",
"current_row_rows",
"expr_preceding_rows",
"expr_following_rows",
"expr_preceding_range")

expr_window_ <- function (window_function, partitions=list(), order_bys=list(), window_boundary_start=window_boundaries,
window_boundary_end=window_boundaries, start_expr = list(), end_expr=list(), offset_expr=list(), default_expr=list()) {
window_boundary_start <- match.arg(window_boundary_start)
window_boundary_end <- match.arg(window_boundary_end)
rapi_expr_window(window_function, partitions, order_bys, window_boundary_start, window_boundary_end, start_expr, end_expr, offset_expr, default_expr)
}

#' Lazily INNER join two DuckDB relation objects
#' @param left the left-hand-side DuckDB relation object
#' @param right the right-hand-side DuckDB relation object
Expand All @@ -172,7 +216,7 @@ rel_inner_join <- function(left, right, conds) {
rel_join(left, right, conds, "inner")
}

rel_join <- function(left, right, conds, join = c("inner", "left", "right", "outer")) {
rel_join <- function(left, right, conds, join = c("inner", "left", "right", "outer", "cross", "semi", "anti")) {
join <- match.arg(join)
rapi_rel_join(left, right, conds, join)
}
Expand Down Expand Up @@ -308,3 +352,30 @@ rel_from_altrep_df <- rapi_rel_from_altrep_df
#' str(df)
#' stopifnot(df_is_materialized(df))
df_is_materialized <- rapi_df_is_materialized



#' Convert a relation to a SQL string
#' @param rel the DuckDB relation object
#' @return a SQL string
#' @noRd
#' @examples
#' con <- DBI::dbConnect(duckdb())
#' rel <- rel_from_df(con, mtcars)
#' print(rel_to_sql(rel))
rel_to_sql <- rapi_rel_to_sql



#' Convert a duckdb table relation
#' @param table the table name
#' @return a duckdb relation
#' @noRd
#' @examples
#' con <- DBI::dbConnect(duckdb())
#' DBI::dbWriteTable(con, "mtcars", mtcars)
#' rel <- rel_from_table(con, "mtcars")
rel_from_table <- function(con, table_name, schema_name="MAIN") {
rapi_rel_from_table(con@conn_ref, schema_name, table_name)
}

20 changes: 20 additions & 0 deletions R/sql.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
#' Run a SQL query
#'
#' `sql()` runs an arbitrary SQL query and returns a data.frame the query results
#'
#' @param sql A SQL string
#' @param conn An optional connection, defaults to built-in default
#' @return A data frame with the query result
#' @noRd
#' @examples
#' print(duckdb::sql("SELECT 42"))

sql <- function(sql, conn = default_connection()) {
stopifnot(dbIsValid(conn))
dbGetQuery(conn, sql)
}

default_duckdb_connection <- new.env(parent=emptyenv())

#' Get the default connection
#'
#' `default_connection()` returns a default, built-in connection
#'
#' @return A DuckDB connection object
#' @noRd
#' @examples
#' conn <- default_connection()
#' print(duckdb::sql("SELECT 42", conn=conn))
default_connection <- function() {
if(!exists("con", default_duckdb_connection)) {
con <- DBI::dbConnect(duckdb::duckdb())
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ DUCKDB_R_EXTENSIONS=tpch R CMD INSTALL .

## Development

To build the R package, you first need to install the dependencies, these are located in `tools/rpkg/dependencies.R`
Navigate over to the `tools/rpkg` folder and run `Rscript dependencies.R`

For development, setting the `DUCKDB_R_DEBUG` environment variable enables incremental debugging builds for the R package.

```sh
Expand Down
Loading

0 comments on commit 782630b

Please sign in to comment.