| 284 | // Methods for ArraySpan |
| 285 | |
| 286 | void ArraySpan::SetMembers(const ArrayData& data) { |
| 287 | this->type = data.type.get(); |
| 288 | this->length = data.length; |
| 289 | if (this->type->id() == Type::NA) { |
| 290 | this->null_count = this->length; |
| 291 | } else { |
| 292 | this->null_count = data.null_count.load(); |
| 293 | } |
| 294 | this->offset = data.offset; |
| 295 | |
| 296 | for (int i = 0; i < std::min(static_cast<int>(data.buffers.size()), 3); ++i) { |
| 297 | const std::shared_ptr<Buffer>& buffer = data.buffers[i]; |
| 298 | // It is the invoker-of-kernels's responsibility to ensure that |
| 299 | // const buffers are not written to accidentally. |
| 300 | if (buffer) { |
| 301 | SetBuffer(i, buffer); |
| 302 | } else { |
| 303 | this->buffers[i] = {}; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | Type::type type_id = this->type->id(); |
| 308 | if (type_id == Type::EXTENSION) { |
| 309 | auto* ext_type = checked_cast<const ExtensionType*>(this->type); |
| 310 | type_id = ext_type->storage_type()->id(); |
| 311 | } |
| 312 | |
| 313 | if ((data.buffers.size() == 0 || data.buffers[0] == nullptr) && type_id != Type::NA && |
| 314 | type_id != Type::SPARSE_UNION && type_id != Type::DENSE_UNION) { |
| 315 | // This should already be zero but we make for sure |
| 316 | this->null_count = 0; |
| 317 | } |
| 318 | |
| 319 | // Makes sure any other buffers are seen as null / nonexistent |
| 320 | for (int i = static_cast<int>(data.buffers.size()); i < 3; ++i) { |
| 321 | this->buffers[i] = {}; |
| 322 | } |
| 323 | |
| 324 | if (type_id == Type::STRING_VIEW || type_id == Type::BINARY_VIEW) { |
| 325 | // store the span of data buffers in the third buffer |
| 326 | this->buffers[2] = internal::PackVariadicBuffers(std::span(data.buffers).subspan(2)); |
| 327 | } |
| 328 | |
| 329 | if (type_id == Type::DICTIONARY) { |
| 330 | this->child_data.resize(1); |
| 331 | this->child_data[0].SetMembers(*data.dictionary); |
| 332 | } else { |
| 333 | this->child_data.resize(data.child_data.size()); |
| 334 | for (size_t child_index = 0; child_index < data.child_data.size(); ++child_index) { |
| 335 | this->child_data[child_index].SetMembers(*data.child_data[child_index]); |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | namespace { |
| 341 | |