| 137 | |
| 138 | template <typename TypeClass> |
| 139 | Status MakeListArray(const std::shared_ptr<Array>& child_array, int num_lists, |
| 140 | bool include_nulls, MemoryPool* pool, std::shared_ptr<Array>* out) { |
| 141 | using offset_type = typename TypeClass::offset_type; |
| 142 | using ArrayType = typename TypeTraits<TypeClass>::ArrayType; |
| 143 | |
| 144 | // Create the null list values |
| 145 | std::vector<uint8_t> valid_lists(num_lists); |
| 146 | const double null_percent = include_nulls ? 0.1 : 0; |
| 147 | random_null_bytes(num_lists, null_percent, valid_lists.data()); |
| 148 | |
| 149 | // Create list offsets |
| 150 | const int max_list_size = 10; |
| 151 | |
| 152 | std::vector<offset_type> list_sizes(num_lists, 0); |
| 153 | std::vector<offset_type> offsets( |
| 154 | num_lists + 1, 0); // +1 so we can shift for nulls. See partial sum below. |
| 155 | const auto seed = static_cast<uint32_t>(child_array->length()); |
| 156 | |
| 157 | if (num_lists > 0) { |
| 158 | rand_uniform_int(num_lists, seed, 0, max_list_size, list_sizes.data()); |
| 159 | // make sure sizes are consistent with null |
| 160 | std::transform(list_sizes.begin(), list_sizes.end(), valid_lists.begin(), |
| 161 | list_sizes.begin(), |
| 162 | [](offset_type size, uint8_t valid) { return valid == 0 ? 0 : size; }); |
| 163 | std::partial_sum(list_sizes.begin(), list_sizes.end(), ++offsets.begin()); |
| 164 | |
| 165 | // Force invariants |
| 166 | const auto child_length = static_cast<offset_type>(child_array->length()); |
| 167 | offsets[0] = 0; |
| 168 | std::replace_if( |
| 169 | offsets.begin(), offsets.end(), |
| 170 | [child_length](offset_type offset) { return offset > child_length; }, |
| 171 | child_length); |
| 172 | } |
| 173 | |
| 174 | offsets[num_lists] = static_cast<offset_type>(child_array->length()); |
| 175 | |
| 176 | // Create offsets array |
| 177 | using OffsetArrowType = typename TypeTraits<TypeClass>::OffsetType; |
| 178 | std::shared_ptr<Array> offsets_array; |
| 179 | ArrayFromVector<OffsetArrowType, offset_type>(offsets, &offsets_array); |
| 180 | |
| 181 | // Create null bitmap |
| 182 | std::shared_ptr<Buffer> null_bitmap; |
| 183 | RETURN_NOT_OK(GetBitmapFromVector(valid_lists, &null_bitmap)); |
| 184 | |
| 185 | // Use FromArrays which supports nulls via null_bitmap parameter |
| 186 | ARROW_ASSIGN_OR_RAISE(*out, ArrayType::FromArrays(*offsets_array, *child_array, pool, |
| 187 | null_bitmap, kUnknownNullCount)); |
| 188 | return Status::OK(); |
| 189 | } |
| 190 | |
| 191 | Status MakeRandomListViewArray(const std::shared_ptr<Array>& child_array, int num_lists, |
| 192 | bool include_nulls, MemoryPool* pool, |
nothing calls this directly
no test coverage detected