| 172 | RowTableImpl::RowTableImpl() : pool_(nullptr), rows_capacity_(0), bytes_capacity_(0) {} |
| 173 | |
| 174 | Status RowTableImpl::Init(MemoryPool* pool, const RowTableMetadata& metadata) { |
| 175 | pool_ = pool; |
| 176 | metadata_ = metadata; |
| 177 | |
| 178 | DCHECK(!null_masks_ && !offsets_ && !rows_); |
| 179 | |
| 180 | constexpr int64_t kInitialRowsCapacity = 8; |
| 181 | constexpr int64_t kInitialBytesCapacity = 1024; |
| 182 | |
| 183 | // Null masks |
| 184 | ARROW_ASSIGN_OR_RAISE( |
| 185 | auto null_masks, |
| 186 | AllocateResizableBuffer(size_null_masks(kInitialRowsCapacity), pool_)); |
| 187 | null_masks_ = std::move(null_masks); |
| 188 | memset(null_masks_->mutable_data(), 0, size_null_masks(kInitialRowsCapacity)); |
| 189 | |
| 190 | // Offsets and rows |
| 191 | if (!metadata.is_fixed_length) { |
| 192 | ARROW_ASSIGN_OR_RAISE( |
| 193 | auto offsets, AllocateResizableBuffer(size_offsets(kInitialRowsCapacity), pool_)); |
| 194 | offsets_ = std::move(offsets); |
| 195 | memset(offsets_->mutable_data(), 0, size_offsets(kInitialRowsCapacity)); |
| 196 | reinterpret_cast<offset_type*>(offsets_->mutable_data())[0] = 0; |
| 197 | |
| 198 | ARROW_ASSIGN_OR_RAISE( |
| 199 | auto rows, |
| 200 | AllocateResizableBuffer(size_rows_varying_length(kInitialBytesCapacity), pool_)); |
| 201 | rows_ = std::move(rows); |
| 202 | memset(rows_->mutable_data(), 0, size_rows_varying_length(kInitialBytesCapacity)); |
| 203 | bytes_capacity_ = |
| 204 | size_rows_varying_length(kInitialBytesCapacity) - kPaddingForVectors; |
| 205 | } else { |
| 206 | ARROW_ASSIGN_OR_RAISE( |
| 207 | auto rows, |
| 208 | AllocateResizableBuffer(size_rows_fixed_length(kInitialRowsCapacity), pool_)); |
| 209 | rows_ = std::move(rows); |
| 210 | memset(rows_->mutable_data(), 0, size_rows_fixed_length(kInitialRowsCapacity)); |
| 211 | bytes_capacity_ = size_rows_fixed_length(kInitialRowsCapacity) - kPaddingForVectors; |
| 212 | } |
| 213 | |
| 214 | UpdateBufferPointers(); |
| 215 | |
| 216 | rows_capacity_ = kInitialRowsCapacity; |
| 217 | |
| 218 | num_rows_ = 0; |
| 219 | num_rows_for_has_any_nulls_ = 0; |
| 220 | has_any_nulls_ = false; |
| 221 | |
| 222 | return Status::OK(); |
| 223 | } |
| 224 | |
| 225 | void RowTableImpl::Clean() { |
| 226 | num_rows_ = 0; |