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

Function GenerateBinaryArray

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

Source from the content-addressed store, hash-verified

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