Skip to content

Commit

Permalink
stub geoarrow array stream for arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Dec 6, 2023
1 parent 0ff86c6 commit 5dcf5d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions r/geoarrow/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ S3method(as_geoarrow_array,sfc)
S3method(as_geoarrow_array,wk_wkb)
S3method(as_geoarrow_array,wk_wkt)
S3method(as_geoarrow_array,wk_xy)
S3method(as_geoarrow_array_stream,Array)
S3method(as_geoarrow_array_stream,ChunkedArray)
S3method(as_geoarrow_array_stream,default)
S3method(as_geoarrow_array_stream,geoarrow_vctr)
S3method(as_geoarrow_array_stream,nanoarrow_array_stream)
Expand Down
22 changes: 22 additions & 0 deletions r/geoarrow/R/arrow-compat.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,25 @@ as_chunked_array.geoarrow_vctr <- function(x, ..., type = NULL) {

arrow::ChunkedArray$create(!!!arrays, type = type)
}

#' @export
as_geoarrow_array_stream.ChunkedArray <- function(x, ..., schema = NULL) {
stream <- nanoarrow::basic_array_stream(
lapply(x$chunks, as_nanoarrow_array),
schema = as_nanoarrow_schema(x$type),
validate = FALSE
)

as_geoarrow_array_stream(stream, schema = schema)
}

#' @export
as_geoarrow_array_stream.Array <- function(x, ..., schema = NULL) {
stream <- nanoarrow::basic_array_stream(
list(as_nanoarrow_array(x)),
schema = as_nanoarrow_schema(x$type),
validate = FALSE
)

as_geoarrow_array_stream(stream, schema = schema)
}
2 changes: 1 addition & 1 deletion r/geoarrow/tests/testthat/test-arrow-compat.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ test_that("as_arrow_array() works for geoarrow_vctr", {
expect_equal(array$length(), 2)

# Check with a requested type
chunked <- arrow::as_arrow_array(vctr2, type = na_extension_wkb())
array <- arrow::as_arrow_array(vctr2, type = na_extension_wkb())
})

0 comments on commit 5dcf5d5

Please sign in to comment.