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

Method Slice

cpp/src/arrow/chunked_array.cc:188–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188std::shared_ptr<ChunkedArray> ChunkedArray::Slice(int64_t offset, int64_t length) const {
189 ARROW_CHECK_LE(offset, length_) << "Slice offset greater than array length";
190 bool offset_equals_length = offset == length_;
191 int curr_chunk = 0;
192 while (curr_chunk < num_chunks() && offset >= chunk(curr_chunk)->length()) {
193 offset -= chunk(curr_chunk)->length();
194 curr_chunk++;
195 }
196
197 ArrayVector new_chunks;
198 if (num_chunks() > 0 && (offset_equals_length || length == 0)) {
199 // Special case the zero-length slice to make sure there is at least 1 Array
200 // in the result. When there are zero chunks we return zero chunks
201 new_chunks.push_back(chunk(std::min(curr_chunk, num_chunks() - 1))->Slice(0, 0));
202 } else {
203 while (curr_chunk < num_chunks() && length > 0) {
204 new_chunks.push_back(chunk(curr_chunk)->Slice(offset, length));
205 length -= chunk(curr_chunk)->length() - offset;
206 offset = 0;
207 curr_chunk++;
208 }
209 }
210
211 return std::make_shared<ChunkedArray>(new_chunks, type_);
212}
213
214std::shared_ptr<ChunkedArray> ChunkedArray::Slice(int64_t offset) const {
215 return Slice(offset, length_);

Callers 1

NextMethod · 0.45

Calls 4

push_backMethod · 0.80
num_chunksFunction · 0.70
SliceFunction · 0.70
lengthMethod · 0.45

Tested by

no test coverage detected