| 45 | namespace bytedance::bolt { |
| 46 | |
| 47 | BaseVector::BaseVector( |
| 48 | bolt::memory::MemoryPool* pool, |
| 49 | std::shared_ptr<const Type> type, |
| 50 | VectorEncoding::Simple encoding, |
| 51 | BufferPtr nulls, |
| 52 | size_t length, |
| 53 | std::optional<vector_size_t> distinctValueCount, |
| 54 | std::optional<vector_size_t> nullCount, |
| 55 | std::optional<ByteCount> representedByteCount, |
| 56 | std::optional<ByteCount> storageByteCount) |
| 57 | : type_(std::move(type)), |
| 58 | typeKind_(type_ ? type_->kind() : TypeKind::INVALID), |
| 59 | encoding_(encoding), |
| 60 | nulls_(std::move(nulls)), |
| 61 | rawNulls_(nulls_.get() ? nulls_->as<uint64_t>() : nullptr), |
| 62 | pool_(pool), |
| 63 | length_(length), |
| 64 | nullCount_(nullCount), |
| 65 | distinctValueCount_(distinctValueCount), |
| 66 | representedByteCount_(representedByteCount), |
| 67 | storageByteCount_(storageByteCount) { |
| 68 | BOLT_CHECK_NOT_NULL(type_, "Vector creation requires a non-null type."); |
| 69 | |
| 70 | if (nulls_) { |
| 71 | int32_t bytes = byteSize<bool>(length_); |
| 72 | BOLT_CHECK_GE(nulls_->capacity(), bytes); |
| 73 | if (nulls_->size() < bytes) { |
| 74 | // Set the size so that values get preserved by resize. Do not |
| 75 | // set if already large enough, so that it is safe to take a |
| 76 | // second reference to an immutable 'nulls_'. |
| 77 | nulls_->setSize(bytes); |
| 78 | } |
| 79 | inMemoryBytes_ += nulls_->size(); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | void BaseVector::ensureNullsCapacity( |
| 84 | vector_size_t minimumSize, |