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