Skip to content

Commit 4629efa

Browse files
committed
working other than stack imablances
1 parent 120a6d6 commit 4629efa

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

r/src/materialize.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ SEXP nanoarrow_materialize_finalize_result(SEXP converter_xptr, SEXP result) {
333333
Rf_lang4(new_nanoarrow_vctr_sym, chunks_list, schema_xptr, subclass_sexp));
334334
SEXP final_result = PROTECT(Rf_eval(new_nanoarrow_vctr_call, nanoarrow_ns_pkg));
335335

336-
UNPROTECT(8);
336+
UNPROTECT(6);
337337
return final_result;
338338
} else {
339339
return result;
@@ -345,11 +345,13 @@ static int nanoarrow_materialize_nanoarrow_vctr(struct RConverter* converter,
345345
// This is a case where the callee needs ownership, which we can do via a
346346
// shallow copy.
347347
SEXP converter_shelter = R_ExternalPtrProtected(converter_xptr);
348+
SEXP schema_xptr = VECTOR_ELT(converter_shelter, 1);
348349
SEXP array_xptr = VECTOR_ELT(converter_shelter, 2);
349350

350351
SEXP array_out_xptr = PROTECT(nanoarrow_array_owning_xptr());
351-
struct ArrowArray* out_array = nanoarrow_output_array_from_xptr(array_xptr);
352+
struct ArrowArray* out_array = nanoarrow_output_array_from_xptr(array_out_xptr);
352353
array_export(array_xptr, out_array);
354+
R_SetExternalPtrTag(array_out_xptr, schema_xptr);
353355

354356
// Get the cached copy of the pairlist node at the end of the current
355357
// chunks list.

r/tests/testthat/test-convert-array.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,27 @@ test_that("convert to vector works for nanoarrow_vctr()", {
195195
expect_identical(schema$format, "+s")
196196
})
197197

198+
test_that("batched convert to vector works for nanoarrow_vctr()", {
199+
empty_stream <- basic_array_stream(list(), schema = na_string())
200+
empty_vctr <- convert_array_stream(empty_stream, nanoarrow_vctr())
201+
expect_length(empty_vctr, 0)
202+
expect_identical(infer_nanoarrow_schema(empty_vctr)$format, "u")
203+
204+
stream1 <- basic_array_stream(list(c("one", "two", "three")))
205+
vctr1 <- convert_array_stream(stream1, nanoarrow_vctr())
206+
expect_length(vctr1, 3)
207+
208+
stream2 <- basic_array_stream(
209+
list(c("one", "two", "three"), c("four", "five", "six", "seven"))
210+
)
211+
vctr2 <- convert_array_stream(stream2, nanoarrow_vctr())
212+
expect_length(vctr2, 7)
213+
expect_identical(
214+
convert_array_stream(as_nanoarrow_array_stream(vctr2)),
215+
c("one", "two", "three", "four", "five", "six", "seven")
216+
)
217+
})
218+
198219
test_that("convert to vector works for struct-style vectors", {
199220
array <- as_nanoarrow_array(as.POSIXlt("2021-01-01", tz = "America/Halifax"))
200221
expect_identical(

0 commit comments

Comments
 (0)