Skip to content

Commit e02e24f

Browse files
+chunked_array and tests
1 parent b20e4b0 commit e02e24f

File tree

7 files changed

+133
-2
lines changed

7 files changed

+133
-2
lines changed

r/NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export(Type)
1818
export(array)
1919
export(as_tibble)
2020
export(boolean)
21+
export(chunked_array)
2122
export(date32)
2223
export(date64)
2324
export(decimal)

r/R/RcppExports.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ ChunkedArray__as_vector <- function(chunked_array) {
117117
.Call(`_arrow_ChunkedArray__as_vector`, chunked_array)
118118
}
119119

120+
ChunkArray__Slice1 <- function(chunked_array, offset) {
121+
.Call(`_arrow_ChunkArray__Slice1`, chunked_array, offset)
122+
}
123+
124+
ChunkArray__Slice2 <- function(chunked_array, offset, length) {
125+
.Call(`_arrow_ChunkArray__Slice2`, chunked_array, offset, length)
126+
}
127+
128+
ChunkedArray__Make <- function(chunks) {
129+
.Call(`_arrow_ChunkedArray__Make`, chunks)
130+
}
131+
120132
RecordBatch_to_dataframe <- function(batch) {
121133
.Call(`_arrow_RecordBatch_to_dataframe`, batch)
122134
}

r/R/array.R

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,14 @@ read_record_batch <- function(path){
108108
chunk = function(i) `arrow::Array`$new(ChunkedArray__chunk(self, i)),
109109
chunks = function() purrr::map(ChunkedArray__chunks(self), `arrow::Array`$new),
110110
type = function() `arrow::DataType`$dispatch(ChunkedArray__type(self)),
111-
as_vector = function() ChunkedArray__as_vector(self)
111+
as_vector = function() ChunkedArray__as_vector(self),
112+
Slice = function(offset, length = NULL){
113+
if (is.null(length)) {
114+
`arrow::ChunkedArray`$new(ChunkArray__Slice1(self, offset))
115+
} else {
116+
`arrow::ChunkedArray`$new(ChunkArray__Slice2(self, offset, length))
117+
}
118+
}
112119
)
113120
)
114121

@@ -161,4 +168,11 @@ read_arrow <- function(path){
161168
as_tibble(read_table(path))
162169
}
163170

164-
171+
#' create an arrow::Array from an R vector
172+
#'
173+
#' @param \dots Vectors to coerce
174+
#'
175+
#' @export
176+
chunked_array <- function(...){
177+
`arrow::ChunkedArray`$new(ChunkedArray__Make(list(...)))
178+
}

r/man/chunked_array.Rd

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r/src/RcppExports.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,42 @@ BEGIN_RCPP
331331
return rcpp_result_gen;
332332
END_RCPP
333333
}
334+
// ChunkArray__Slice1
335+
std::shared_ptr<arrow::ChunkedArray> ChunkArray__Slice1(const std::shared_ptr<arrow::ChunkedArray>& chunked_array, int offset);
336+
RcppExport SEXP _arrow_ChunkArray__Slice1(SEXP chunked_arraySEXP, SEXP offsetSEXP) {
337+
BEGIN_RCPP
338+
Rcpp::RObject rcpp_result_gen;
339+
Rcpp::RNGScope rcpp_rngScope_gen;
340+
Rcpp::traits::input_parameter< const std::shared_ptr<arrow::ChunkedArray>& >::type chunked_array(chunked_arraySEXP);
341+
Rcpp::traits::input_parameter< int >::type offset(offsetSEXP);
342+
rcpp_result_gen = Rcpp::wrap(ChunkArray__Slice1(chunked_array, offset));
343+
return rcpp_result_gen;
344+
END_RCPP
345+
}
346+
// ChunkArray__Slice2
347+
std::shared_ptr<arrow::ChunkedArray> ChunkArray__Slice2(const std::shared_ptr<arrow::ChunkedArray>& chunked_array, int offset, int length);
348+
RcppExport SEXP _arrow_ChunkArray__Slice2(SEXP chunked_arraySEXP, SEXP offsetSEXP, SEXP lengthSEXP) {
349+
BEGIN_RCPP
350+
Rcpp::RObject rcpp_result_gen;
351+
Rcpp::RNGScope rcpp_rngScope_gen;
352+
Rcpp::traits::input_parameter< const std::shared_ptr<arrow::ChunkedArray>& >::type chunked_array(chunked_arraySEXP);
353+
Rcpp::traits::input_parameter< int >::type offset(offsetSEXP);
354+
Rcpp::traits::input_parameter< int >::type length(lengthSEXP);
355+
rcpp_result_gen = Rcpp::wrap(ChunkArray__Slice2(chunked_array, offset, length));
356+
return rcpp_result_gen;
357+
END_RCPP
358+
}
359+
// ChunkedArray__Make
360+
std::shared_ptr<arrow::ChunkedArray> ChunkedArray__Make(List chunks);
361+
RcppExport SEXP _arrow_ChunkedArray__Make(SEXP chunksSEXP) {
362+
BEGIN_RCPP
363+
Rcpp::RObject rcpp_result_gen;
364+
Rcpp::RNGScope rcpp_rngScope_gen;
365+
Rcpp::traits::input_parameter< List >::type chunks(chunksSEXP);
366+
rcpp_result_gen = Rcpp::wrap(ChunkedArray__Make(chunks));
367+
return rcpp_result_gen;
368+
END_RCPP
369+
}
334370
// RecordBatch_to_dataframe
335371
List RecordBatch_to_dataframe(const std::shared_ptr<arrow::RecordBatch>& batch);
336372
RcppExport SEXP _arrow_RecordBatch_to_dataframe(SEXP batchSEXP) {
@@ -1090,6 +1126,9 @@ static const R_CallMethodDef CallEntries[] = {
10901126
{"_arrow_ChunkedArray__chunks", (DL_FUNC) &_arrow_ChunkedArray__chunks, 1},
10911127
{"_arrow_ChunkedArray__type", (DL_FUNC) &_arrow_ChunkedArray__type, 1},
10921128
{"_arrow_ChunkedArray__as_vector", (DL_FUNC) &_arrow_ChunkedArray__as_vector, 1},
1129+
{"_arrow_ChunkArray__Slice1", (DL_FUNC) &_arrow_ChunkArray__Slice1, 2},
1130+
{"_arrow_ChunkArray__Slice2", (DL_FUNC) &_arrow_ChunkArray__Slice2, 3},
1131+
{"_arrow_ChunkedArray__Make", (DL_FUNC) &_arrow_ChunkedArray__Make, 1},
10931132
{"_arrow_RecordBatch_to_dataframe", (DL_FUNC) &_arrow_RecordBatch_to_dataframe, 1},
10941133
{"_arrow_dataframe_to_Table", (DL_FUNC) &_arrow_dataframe_to_Table, 1},
10951134
{"_arrow_Table_num_columns", (DL_FUNC) &_arrow_Table_num_columns, 1},

r/src/buffer.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,25 @@ SEXP ChunkedArray__as_vector(const std::shared_ptr<arrow::ChunkedArray>& chunked
254254
return R_NilValue;
255255
}
256256

257+
// [[Rcpp::export]]
258+
std::shared_ptr<arrow::ChunkedArray> ChunkArray__Slice1( const std::shared_ptr<arrow::ChunkedArray>& chunked_array, int offset) {
259+
return chunked_array->Slice(offset);
260+
}
261+
262+
// [[Rcpp::export]]
263+
std::shared_ptr<arrow::ChunkedArray> ChunkArray__Slice2( const std::shared_ptr<arrow::ChunkedArray>& chunked_array, int offset, int length) {
264+
return chunked_array->Slice(offset, length);
265+
}
266+
267+
// [[Rcpp::export]]
268+
std::shared_ptr<arrow::ChunkedArray> ChunkedArray__Make(List chunks){
269+
std::vector<std::shared_ptr<arrow::Array>> vec;
270+
for ( SEXP chunk: chunks) {
271+
vec.push_back(rvector_to_Array(chunk));
272+
}
273+
return std::make_shared<arrow::ChunkedArray>(std::move(vec));
274+
}
275+
257276
// [[Rcpp::export]]
258277
List RecordBatch_to_dataframe(const std::shared_ptr<arrow::RecordBatch>& batch){
259278
int nc = batch->num_columns();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
context("ChunkedArray")
19+
20+
test_that("ChunkedArray", {
21+
x <- chunked_array(1:10, 1:10, 1:5)
22+
expect_equal(x$type(), int32())
23+
expect_equal(x$num_chunks(), 3L)
24+
expect_equal(x$length(), 25L)
25+
expect_equal(x$as_vector(), c(1:10, 1:10, 1:5))
26+
27+
x <- chunked_array(c(1,2,3), c(4,5,6))
28+
expect_equal(x$type(), float64())
29+
expect_equal(x$num_chunks(), 2L)
30+
expect_equal(x$length(), 6L)
31+
expect_equal(x$as_vector(), as.numeric(1:6))
32+
})

0 commit comments

Comments
 (0)