| 174 | } |
| 175 | |
| 176 | std::shared_ptr<ChunkedArray> ChunkedArray::Slice(int64_t offset, int64_t length) const { |
| 177 | ARROW_CHECK_LE(offset, length_) << "Slice offset greater than array length"; |
| 178 | bool offset_equals_length = offset == length_; |
| 179 | int curr_chunk = 0; |
| 180 | while (curr_chunk < num_chunks() && offset >= chunk(curr_chunk)->length()) { |
| 181 | offset -= chunk(curr_chunk)->length(); |
| 182 | curr_chunk++; |
| 183 | } |
| 184 | |
| 185 | ArrayVector new_chunks; |
| 186 | if (num_chunks() > 0 && (offset_equals_length || length == 0)) { |
| 187 | // Special case the zero-length slice to make sure there is at least 1 Array |
| 188 | // in the result. When there are zero chunks we return zero chunks |
| 189 | new_chunks.push_back(chunk(std::min(curr_chunk, num_chunks() - 1))->Slice(0, 0)); |
| 190 | } else { |
| 191 | while (curr_chunk < num_chunks() && length > 0) { |
| 192 | new_chunks.push_back(chunk(curr_chunk)->Slice(offset, length)); |
| 193 | length -= chunk(curr_chunk)->length() - offset; |
| 194 | offset = 0; |
| 195 | curr_chunk++; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | return std::make_shared<ChunkedArray>(new_chunks, type_); |
| 200 | } |
| 201 | |
| 202 | std::shared_ptr<ChunkedArray> ChunkedArray::Slice(int64_t offset) const { |
| 203 | return Slice(offset, length_); |
no test coverage detected