in cpp/code/creating_arrow_objects.cc [97:120]
arrow::Status Visit(const arrow::ListType& type) {
// Generate offsets first, which determines number of values in sub-array
std::poisson_distribution<> d{/*mean=*/4};
auto builder = arrow::Int32Builder();
ARROW_RETURN_NOT_OK(builder.Append(0));
int32_t last_val = 0;
for (int32_t i = 0; i < num_rows_; ++i) {
last_val += d(gen_);
ARROW_RETURN_NOT_OK(builder.Append(last_val));
}
ARROW_ASSIGN_OR_RAISE(auto offsets, builder.Finish());
// Since children of list has a new length, will use a new generator
RandomBatchGenerator value_gen(arrow::schema({arrow::field("x", type.value_type())}));
// Last index from the offsets array becomes the length of the sub-array
ARROW_ASSIGN_OR_RAISE(auto inner_batch, value_gen.Generate(last_val));
std::shared_ptr<arrow::Array> values = inner_batch->column(0);
ARROW_ASSIGN_OR_RAISE(auto array,
arrow::ListArray::FromArrays(*offsets.get(), *values.get()));
arrays_.push_back(array);
return arrow::Status::OK();
}