MCPcopy Create free account
hub / github.com/apache/arrow / AppendValuesInternal

Method AppendValuesInternal

cpp/src/arrow/array/builder_adaptive.cc:170–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168static constexpr int64_t kAdaptiveIntChunkSize = 8192;
169
170Status AdaptiveIntBuilder::AppendValuesInternal(const int64_t* values, int64_t length,
171 const uint8_t* valid_bytes) {
172 if (pending_pos_ > 0) {
173 // UnsafeAppendToBitmap expects length_ to be the pre-update value, satisfy it
174 DCHECK_EQ(length, pending_pos_) << "AppendValuesInternal called while data pending";
175 length_ -= pending_pos_;
176 }
177
178 while (length > 0) {
179 // In case `length` is very large, we don't want to trash the cache by
180 // scanning it twice (first to detect int width, second to copy the data).
181 // Instead, process data in L2-cacheable chunks.
182 const int64_t chunk_size = std::min(length, kAdaptiveIntChunkSize);
183
184 uint8_t new_int_size;
185 new_int_size = internal::DetectIntWidth(values, valid_bytes, chunk_size, int_size_);
186
187 DCHECK_GE(new_int_size, int_size_);
188 if (new_int_size > int_size_) {
189 // This updates int_size_
190 RETURN_NOT_OK(ExpandIntSize(new_int_size));
191 }
192
193 switch (int_size_) {
194 case 1:
195 internal::DowncastInts(values, reinterpret_cast<int8_t*>(raw_data_) + length_,
196 chunk_size);
197 break;
198 case 2:
199 internal::DowncastInts(values, reinterpret_cast<int16_t*>(raw_data_) + length_,
200 chunk_size);
201 break;
202 case 4:
203 internal::DowncastInts(values, reinterpret_cast<int32_t*>(raw_data_) + length_,
204 chunk_size);
205 break;
206 case 8:
207 internal::DowncastInts(values, reinterpret_cast<int64_t*>(raw_data_) + length_,
208 chunk_size);
209 break;
210 default:
211 DCHECK(false);
212 }
213
214 // UnsafeAppendToBitmap increments length_ by chunk_size
215 ArrayBuilder::UnsafeAppendToBitmap(valid_bytes, chunk_size);
216 values += chunk_size;
217 if (valid_bytes != nullptr) {
218 valid_bytes += chunk_size;
219 }
220 length -= chunk_size;
221 }
222
223 return Status::OK();
224}
225
226Status AdaptiveUIntBuilder::CommitPendingData() {
227 if (pending_pos_ == 0) {

Callers

nothing calls this directly

Calls 6

DetectIntWidthFunction · 0.85
DowncastIntsFunction · 0.85
UnsafeAppendToBitmapFunction · 0.85
DetectUIntWidthFunction · 0.85
DowncastUIntsFunction · 0.85
OKFunction · 0.50

Tested by

no test coverage detected