-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #396 from r-dbi/f-arrow-more
- Loading branch information
Showing
12 changed files
with
147 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#' @name dbWriteTable | ||
#' @aliases dbAppendStream | ||
#' @export | ||
setGeneric("dbAppendStream", | ||
def = function(conn, name, value, ...) standardGeneric("dbAppendStream") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' @rdname hidden_aliases | ||
#' @usage NULL | ||
dbAppendStream_DBIConnection <- function(conn, name, value, ...) { | ||
require_arrow() | ||
|
||
name <- dbQuoteIdentifier(conn, name) | ||
|
||
value <- arrow::as_record_batch_reader(value) | ||
|
||
while (TRUE) { | ||
# Append next batch (starting with the first or second, doesn't matter) | ||
tmp <- value$read_next_batch() | ||
if (is.null(tmp)) { | ||
break | ||
} | ||
dbAppendTable(conn, name, as.data.frame(tmp), ...) | ||
} | ||
|
||
TRUE | ||
} | ||
#' @rdname hidden_aliases | ||
#' @export | ||
setMethod("dbAppendStream", signature("DBIConnection"), dbAppendStream_DBIConnection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#' @name dbWriteTable | ||
#' @aliases dbCreateFromStream | ||
#' @export | ||
setGeneric("dbCreateFromStream", | ||
def = function(conn, name, value, ...) standardGeneric("dbCreateFromStream") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#' @rdname hidden_aliases | ||
#' @usage NULL | ||
dbCreateFromStream_DBIConnection <- function(conn, name, value, ..., temporary = FALSE) { | ||
require_arrow() | ||
|
||
value <- arrow::as_record_batch_reader(value) | ||
|
||
ptype <- get_arrow_ptype(value) | ||
dbCreateTable(conn, name, ptype, ..., temporary = temporary) | ||
} | ||
|
||
get_arrow_ptype <- function(value) { | ||
schema <- value$schema | ||
stopifnot(!is.null(schema)) | ||
|
||
arrays <- lapply( | ||
stats::setNames(schema$fields, schema$names), | ||
function(field) arrow::concat_arrays(type = field$type) | ||
) | ||
vectors <- lapply( | ||
arrays, | ||
function(array) tryCatch( | ||
as.vector(array), | ||
error = function(...) vctrs::unspecified() | ||
) | ||
) | ||
|
||
vctrs::new_data_frame(vectors, n = 0L) | ||
} | ||
|
||
#' @rdname hidden_aliases | ||
#' @export | ||
setMethod("dbCreateFromStream", signature("DBIConnection"), dbCreateFromStream_DBIConnection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters