MCPcopy Create free account
hub / github.com/apache/arrow / vec_to_arrow_ChunkedArray

Function vec_to_arrow_ChunkedArray

r/src/r_to_arrow.cpp:1292–1335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1290}
1291
1292std::shared_ptr<arrow::ChunkedArray> vec_to_arrow_ChunkedArray(
1293 SEXP x, const std::shared_ptr<arrow::DataType>& type, bool type_inferred) {
1294 // short circuit if `x` is already a chunked array
1295 if (Rf_inherits(x, "ChunkedArray")) {
1296 return cpp11::as_cpp<std::shared_ptr<arrow::ChunkedArray>>(x);
1297 }
1298
1299 // short circuit if `x` is an Array
1300 if (Rf_inherits(x, "Array")) {
1301 return std::make_shared<arrow::ChunkedArray>(
1302 cpp11::as_cpp<std::shared_ptr<arrow::Array>>(x));
1303 }
1304
1305 RConversionOptions options;
1306 options.strict = !type_inferred;
1307 options.type = type;
1308 options.size = arrow::r::vec_size(x);
1309
1310 // If we can handle this in C++ we do so; otherwise we use the
1311 // AsArrowArrayConverter, which calls as_arrow_array().
1312 std::unique_ptr<RConverter> converter;
1313 if (can_convert_native(x) && type->id() != Type::EXTENSION) {
1314 // short circuit if `x` is an altrep vector that shells a chunked Array
1315 auto maybe = altrep::vec_to_arrow_altrep_bypass(x);
1316 if (maybe.get() && maybe->type()->Equals(type)) {
1317 return maybe;
1318 }
1319
1320 // maybe short circuit when zero-copy is possible
1321 if (can_reuse_memory(x, type)) {
1322 return std::make_shared<arrow::ChunkedArray>(vec_to_arrow__reuse_memory(x));
1323 }
1324
1325 // Otherwise go through the converter API.
1326 converter = ValueOrStop(MakeConverter<RConverter, RConverterTrait>(
1327 options.type, options, gc_memory_pool()));
1328 } else {
1329 converter = std::unique_ptr<RConverter>(new AsArrowArrayConverter());
1330 StopIfNotOk(converter->Construct(type, options, gc_memory_pool()));
1331 }
1332
1333 StopIfNotOk(converter->Extend(x, options.size));
1334 return ValueOrStop(converter->ToChunkedArray());
1335}
1336
1337std::shared_ptr<arrow::Array> vec_to_arrow_Array(
1338 SEXP x, const std::shared_ptr<arrow::DataType>& type, bool type_inferred) {

Callers 3

ExtendSetupMethod · 0.85
vec_to_arrow_ArrayFunction · 0.85
ChunkedArray__from_listFunction · 0.85

Calls 15

vec_sizeFunction · 0.85
can_convert_nativeFunction · 0.85
can_reuse_memoryFunction · 0.85
ValueOrStopFunction · 0.85
gc_memory_poolFunction · 0.85
StopIfNotOkFunction · 0.85
idMethod · 0.45
getMethod · 0.45
EqualsMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected