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

Function ResolveMany

cpp/src/arrow/chunk_resolver.h:172–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170 /// \return false iff chunks.size() > std::numeric_limits<IndexType>::max()
171 template <typename IndexType>
172 [[nodiscard]] bool ResolveMany(int64_t n_indices, const IndexType* logical_index_vec,
173 TypedChunkLocation<IndexType>* out_chunk_location_vec,
174 IndexType chunk_hint = 0) const {
175 if constexpr (sizeof(IndexType) < sizeof(uint32_t)) {
176 // The max value returned by Bisect is `offsets.size() - 1` (= chunks.size()).
177 constexpr int64_t kMaxIndexTypeValue = std::numeric_limits<IndexType>::max();
178 // A ChunkedArray with enough empty chunks can make the index of a chunk
179 // exceed the logical index and thus the maximum value of IndexType.
180 const bool chunk_index_fits_on_type = num_chunks() <= kMaxIndexTypeValue;
181 if (ARROW_PREDICT_FALSE(!chunk_index_fits_on_type)) {
182 return false;
183 }
184 // Since an index-in-chunk cannot possibly exceed the logical index being
185 // queried, we don't have to worry about these values not fitting on IndexType.
186 }
187 if constexpr (std::is_signed_v<IndexType>) {
188 // We interpret signed integers as unsigned and avoid having to generate double
189 // the amount of binary code to handle each integer width.
190 //
191 // Negative logical indices can become large values when cast to unsigned, and
192 // they are gracefully handled by ResolveManyImpl, but both the chunk index
193 // and the index in chunk values will be undefined in these cases. This
194 // happend because int8_t(-1) == uint8_t(255) and 255 could be a valid
195 // logical index in the chunked array.
196 using U = std::make_unsigned_t<IndexType>;
197 ResolveManyImpl(n_indices, reinterpret_cast<const U*>(logical_index_vec),
198 reinterpret_cast<TypedChunkLocation<U>*>(out_chunk_location_vec),
199 static_cast<int32_t>(chunk_hint));
200 } else {
201 static_assert(std::is_unsigned_v<IndexType>);
202 ResolveManyImpl(n_indices, logical_index_vec, out_chunk_location_vec,
203 static_cast<int32_t>(chunk_hint));
204 }
205 return true;
206 }
207
208 private:
209 template <bool StoreCachedChunk>

Callers 2

TEST_FFunction · 0.85
TestOverflowFunction · 0.85

Calls 1

num_chunksFunction · 0.70

Tested by 2

TEST_FFunction · 0.68
TestOverflowFunction · 0.68