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

Method FillFromScalar

cpp/src/arrow/array/data.cc:418–608  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

416} // namespace internal
417
418void ArraySpan::FillFromScalar(const Scalar& value) {
419 static uint8_t kTrueBit = 0x01;
420 static uint8_t kFalseBit = 0x00;
421
422 this->type = value.type.get();
423 this->length = 1;
424
425 Type::type type_id = value.type->id();
426
427 if (type_id == Type::NA) {
428 this->null_count = 1;
429 } else if (!internal::may_have_validity_bitmap(type_id)) {
430 this->null_count = 0;
431 } else {
432 // Populate null count and validity bitmap
433 this->null_count = value.is_valid ? 0 : 1;
434 this->buffers[0].data = value.is_valid ? &kTrueBit : &kFalseBit;
435 this->buffers[0].size = 1;
436 }
437
438 if (type_id == Type::BOOL) {
439 const auto& scalar = checked_cast<const BooleanScalar&>(value);
440 this->buffers[1].data = scalar.value ? &kTrueBit : &kFalseBit;
441 this->buffers[1].size = 1;
442 } else if (is_primitive(type_id) || is_decimal(type_id) ||
443 type_id == Type::DICTIONARY) {
444 const auto& scalar = checked_cast<const internal::PrimitiveScalarBase&>(value);
445 const uint8_t* scalar_data = reinterpret_cast<const uint8_t*>(scalar.view().data());
446 this->buffers[1].data = const_cast<uint8_t*>(scalar_data);
447 this->buffers[1].size = scalar.type->byte_width();
448 if (type_id == Type::DICTIONARY) {
449 // Populate dictionary data
450 const auto& dict_scalar = checked_cast<const DictionaryScalar&>(value);
451 this->child_data.resize(1);
452 this->child_data[0].SetMembers(*dict_scalar.value.dictionary->data());
453 }
454 } else if (is_base_binary_like(type_id)) {
455 const auto& scalar = checked_cast<const BaseBinaryScalar&>(value);
456
457 const uint8_t* data_buffer = nullptr;
458 int64_t data_size = 0;
459 if (scalar.is_valid) {
460 data_buffer = scalar.value->data();
461 data_size = scalar.value->size();
462 }
463 if (is_binary_like(type_id)) {
464 const auto& binary_scalar = checked_cast<const BinaryScalar&>(value);
465 this->buffers[1] = OffsetsForScalar(binary_scalar.scratch_space_, sizeof(int32_t));
466 } else {
467 // is_large_binary_like
468 const auto& large_binary_scalar = checked_cast<const LargeBinaryScalar&>(value);
469 this->buffers[1] =
470 OffsetsForScalar(large_binary_scalar.scratch_space_, sizeof(int64_t));
471 }
472 this->buffers[2].data = const_cast<uint8_t*>(data_buffer);
473 this->buffers[2].size = data_size;
474 } else if (type_id == Type::BINARY_VIEW || type_id == Type::STRING_VIEW) {
475 const auto& scalar = checked_cast<const BinaryViewScalar&>(value);

Callers 1

PromoteExecSpanScalarsFunction · 0.80

Calls 15

may_have_validity_bitmapFunction · 0.85
is_base_binary_likeFunction · 0.85
is_binary_likeFunction · 0.85
OffsetsForScalarFunction · 0.85
PackVariadicBuffersFunction · 0.85
is_var_length_list_likeFunction · 0.85
FillZeroLengthArrayFunction · 0.85
OffsetsAndSizesForScalarFunction · 0.85
resizeMethod · 0.80
SetMembersMethod · 0.80
is_primitiveFunction · 0.50
is_decimalFunction · 0.50

Tested by

no test coverage detected