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

Method Ingest_some_nulls

r/src/array_to_vector.cpp:330–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328 }
329
330 Status Ingest_some_nulls(SEXP data, const std::shared_ptr<arrow::Array>& array,
331 R_xlen_t start, R_xlen_t n, size_t chunk_index) const {
332 auto p_offset = array->data()->GetValues<int32_t>(1);
333 if (!p_offset) {
334 return Status::Invalid("Invalid offset buffer");
335 }
336 auto p_strings = array->data()->GetValues<char>(2, *p_offset);
337 if (!p_strings) {
338 // There is an offset buffer, but the data buffer is null
339 // There is at least one value in the array and not all the values are null
340 // That means all values are either empty strings or nulls so there is nothing to do
341
342 if (array->null_count()) {
343 arrow::internal::BitmapReader null_reader(array->null_bitmap_data(),
344 array->offset(), n);
345 for (int i = 0; i < n; i++, null_reader.Next()) {
346 if (null_reader.IsNotSet()) {
347 SET_STRING_ELT(data, start + i, NA_STRING);
348 }
349 }
350 }
351 return Status::OK();
352 }
353
354 StringArrayType* string_array = static_cast<StringArrayType*>(array.get());
355
356 const bool all_valid = array->null_count() == 0;
357 const bool strip_out_nuls = GetBoolOption("arrow.skip_nul", false);
358
359 bool nul_was_stripped = false;
360
361 if (all_valid) {
362 // no need to watch for missing strings
363 cpp11::unwind_protect([&] {
364 if (strip_out_nuls) {
365 for (int i = 0; i < n; i++) {
366 SET_STRING_ELT(data, start + i,
367 r_string_from_view_strip_nul(string_array->GetView(i),
368 &nul_was_stripped));
369 }
370 return;
371 }
372
373 for (int i = 0; i < n; i++) {
374 SET_STRING_ELT(data, start + i, r_string_from_view(string_array->GetView(i)));
375 }
376 });
377 } else {
378 cpp11::unwind_protect([&] {
379 arrow::internal::BitmapReader validity_reader(array->null_bitmap_data(),
380 array->offset(), n);
381
382 if (strip_out_nuls) {
383 for (int i = 0; i < n; i++, validity_reader.Next()) {
384 if (validity_reader.IsSet()) {
385 SET_STRING_ELT(data, start + i,
386 r_string_from_view_strip_nul(string_array->GetView(i),
387 &nul_was_stripped));

Callers

nothing calls this directly

Calls 11

GetBoolOptionFunction · 0.85
InvalidClass · 0.50
OKFunction · 0.50
dataMethod · 0.45
null_countMethod · 0.45
offsetMethod · 0.45
NextMethod · 0.45
IsNotSetMethod · 0.45
getMethod · 0.45
GetViewMethod · 0.45
IsSetMethod · 0.45

Tested by

no test coverage detected