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

Function GenerateBinaryArray

cpp/src/arrow/testing/random.cc:476–516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

474
475template <typename TypeClass, typename offset_type = typename TypeClass::offset_type>
476static std::shared_ptr<Array> GenerateBinaryArray(
477 RandomArrayGenerator* gen, int64_t size, int32_t min_length, int32_t max_length,
478 double null_probability, std::optional<int64_t> max_data_buffer_length,
479 int64_t alignment, MemoryPool* memory_pool) {
480 using BuilderType = typename TypeTraits<TypeClass>::BuilderType;
481 using OffsetArrowType = typename CTypeTraits<offset_type>::ArrowType;
482 using OffsetArrayType = typename TypeTraits<OffsetArrowType>::ArrayType;
483
484 if (null_probability < 0 || null_probability > 1) {
485 ABORT_NOT_OK(Status::Invalid("null_probability must be between 0 and 1"));
486 }
487
488 auto lengths = std::dynamic_pointer_cast<OffsetArrayType>(gen->Numeric<OffsetArrowType>(
489 size, min_length, max_length, null_probability, alignment, memory_pool));
490
491 // Visual Studio does not implement uniform_int_distribution for char types.
492 using GenOpt = GenerateOptions<uint8_t, std::uniform_int_distribution<uint16_t>>;
493 GenOpt options(gen->seed(), static_cast<uint8_t>('A'), static_cast<uint8_t>('z'),
494 /*null_probability=*/0);
495
496 std::vector<uint8_t> str_buffer(max_length);
497 BuilderType builder{memory_pool, alignment};
498 if constexpr (std::is_base_of_v<BinaryViewType, TypeClass>) {
499 if (max_data_buffer_length) {
500 builder.SetBlockSize(*max_data_buffer_length);
501 }
502 }
503
504 for (int64_t i = 0; i < size; ++i) {
505 if (lengths->IsValid(i)) {
506 options.GenerateData(str_buffer.data(), lengths->Value(i));
507 ABORT_NOT_OK(builder.Append(str_buffer.data(), lengths->Value(i)));
508 } else {
509 ABORT_NOT_OK(builder.AppendNull());
510 }
511 }
512
513 std::shared_ptr<Array> result;
514 ABORT_NOT_OK(builder.Finish(&result));
515 return result;
516}
517
518std::shared_ptr<Array> RandomArrayGenerator::String(int64_t size, int32_t min_length,
519 int32_t max_length,

Callers

nothing calls this directly

Calls 8

InvalidFunction · 0.50
IsValidMethod · 0.45
GenerateDataMethod · 0.45
dataMethod · 0.45
ValueMethod · 0.45
AppendMethod · 0.45
AppendNullMethod · 0.45
FinishMethod · 0.45

Tested by

no test coverage detected