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

Function vec_to_arrow_ChunkedArray

r/src/r_to_arrow.cpp:1299–1342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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