Skip to content

Commit a347f92

Browse files
committed
apacheGH-34535: [C++] Move ChunkResolver to the public API
Co-authored-by: SChakravorti21<[email protected]>
1 parent c50c4fa commit a347f92

11 files changed

Lines changed: 49 additions & 27 deletions

File tree

‎cpp/src/arrow/chunk_resolver.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "arrow/array.h"
2727
#include "arrow/record_batch.h"
2828

29-
namespace arrow::internal {
29+
namespace arrow {
3030

3131
namespace {
3232
template <typename T>
@@ -167,4 +167,4 @@ void ChunkResolver::ResolveManyImpl(int64_t n_indices, const uint64_t* logical_i
167167
logical_index_vec, out_chunk_location_vec, chunk_hint);
168168
}
169169

170-
} // namespace arrow::internal
170+
} // namespace arrow

‎cpp/src/arrow/chunk_resolver.h‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
#include "arrow/type_fwd.h"
2828
#include "arrow/util/macros.h"
2929

30-
namespace arrow::internal {
30+
namespace arrow {
3131

3232
struct ChunkResolver;
3333

3434
template <typename IndexType>
35-
struct TypedChunkLocation {
35+
struct ARROW_EXPORT TypedChunkLocation {
3636
/// \brief Index of the chunk in the array of chunks
3737
///
3838
/// The value is always in the range `[0, chunks.size()]`. `chunks.size()` is used
@@ -41,7 +41,7 @@ struct TypedChunkLocation {
4141

4242
/// \brief Index of the value in the chunk
4343
///
44-
/// The value is UNDEFINED if chunk_index >= chunks.size()
44+
/// The value is UNDEFINED if `chunk_index >= chunks.size()`
4545
IndexType index_in_chunk = 0;
4646

4747
TypedChunkLocation() = default;
@@ -61,7 +61,7 @@ using ChunkLocation = TypedChunkLocation<int64_t>;
6161

6262
/// \brief An utility that incrementally resolves logical indices into
6363
/// physical indices in a chunked array.
64-
struct ARROW_EXPORT ChunkResolver {
64+
class ARROW_EXPORT ChunkResolver {
6565
private:
6666
/// \brief Array containing `chunks.size() + 1` offsets.
6767
///
@@ -75,8 +75,16 @@ struct ARROW_EXPORT ChunkResolver {
7575
mutable std::atomic<int32_t> cached_chunk_;
7676

7777
public:
78+
/// \brief Initialize from an `ArrayVector`.
7879
explicit ChunkResolver(const ArrayVector& chunks) noexcept;
80+
81+
/// \brief Initialize from a vector of raw `Array` pointers.
7982
explicit ChunkResolver(const std::vector<const Array*>& chunks) noexcept;
83+
84+
/// \brief Initialize from a `RecordBatchVector`.
85+
///
86+
/// Because all `Array`s in a `RecordBatch` must have the same length, this
87+
/// can be useful for iterating over multiple columns simultaneously.
8088
explicit ChunkResolver(const RecordBatchVector& batches) noexcept;
8189

8290
/// \brief Construct a ChunkResolver from a vector of chunks.size() + 1 offsets.
@@ -115,11 +123,11 @@ struct ARROW_EXPORT ChunkResolver {
115123
/// The returned ChunkLocation contains the chunk index and the within-chunk index
116124
/// equivalent to the logical index.
117125
///
118-
/// \pre index >= 0
119-
/// \post location.chunk_index in [0, chunks.size()]
126+
/// \pre `index >= 0`
127+
/// \post `location.chunk_index` in `[0, chunks.size()]`
120128
/// \param index The logical index to resolve
121129
/// \return ChunkLocation with a valid chunk_index if index is within
122-
/// bounds, or with chunk_index == chunks.size() if logical index is
130+
/// bounds, or with `chunk_index == chunks.size()` if logical index is
123131
/// `>= chunked_array.length()`.
124132
inline ChunkLocation Resolve(int64_t index) const {
125133
const auto cached_chunk = cached_chunk_.load(std::memory_order_relaxed);
@@ -133,13 +141,13 @@ struct ARROW_EXPORT ChunkResolver {
133141
/// The returned ChunkLocation contains the chunk index and the within-chunk index
134142
/// equivalent to the logical index.
135143
///
136-
/// \pre index >= 0
137-
/// \post location.chunk_index in [0, chunks.size()]
144+
/// \pre `index >= 0`
145+
/// \post `location.chunk_index` in `[0, chunks.size()]`
138146
/// \param index The logical index to resolve
139147
/// \param hint ChunkLocation{} or the last ChunkLocation returned by
140148
/// this ChunkResolver.
141149
/// \return ChunkLocation with a valid chunk_index if index is within
142-
/// bounds, or with chunk_index == chunks.size() if logical index is
150+
/// bounds, or with `chunk_index == chunks.size()` if logical index is
143151
/// `>= chunked_array.length()`.
144152
inline ChunkLocation ResolveWithHint(int64_t index, ChunkLocation hint) const {
145153
assert(hint.chunk_index < static_cast<uint32_t>(offsets_.size()));
@@ -281,4 +289,4 @@ struct ARROW_EXPORT ChunkResolver {
281289
}
282290
};
283291

284-
} // namespace arrow::internal
292+
} // namespace arrow

‎cpp/src/arrow/chunk_resolver_benchmark.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
namespace arrow {
3030

31-
using internal::ChunkResolver;
32-
using internal::TypedChunkLocation;
31+
using ChunkResolver;
32+
using TypedChunkLocation;
3333

3434
namespace {
3535

‎cpp/src/arrow/chunked_array.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class ARROW_EXPORT ChunkedArray {
199199
private:
200200
template <typename T, typename V>
201201
friend class ::arrow::stl::ChunkedArrayIterator;
202-
internal::ChunkResolver chunk_resolver_;
202+
ChunkResolver chunk_resolver_;
203203
ARROW_DISALLOW_COPY_AND_ASSIGN(ChunkedArray);
204204
};
205205

‎cpp/src/arrow/chunked_array_test.cc‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737
namespace arrow {
3838

39-
using internal::ChunkLocation;
40-
using internal::ChunkResolver;
41-
using internal::TypedChunkLocation;
39+
using arrow::ChunkLocation;
40+
using arrow::ChunkResolver;
41+
using arrow::TypedChunkLocation;
4242

4343
class TestChunkedArray : public ::testing::Test {
4444
protected:

‎cpp/src/arrow/compute/kernels/chunked_internal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct ResolvedChunk {
5252

5353
class ChunkedArrayResolver {
5454
private:
55-
::arrow::internal::ChunkResolver resolver_;
55+
ChunkResolver resolver_;
5656
std::vector<const Array*> chunks_;
5757

5858
public:

‎cpp/src/arrow/compute/kernels/vector_sort.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
namespace arrow {
2525

26+
using arrow::ChunkLocation;
2627
using internal::checked_cast;
27-
using internal::ChunkLocation;
2828

2929
namespace compute {
3030
namespace internal {
@@ -852,7 +852,7 @@ class TableSorter {
852852
const RecordBatchVector batches_;
853853
const SortOptions& options_;
854854
const NullPlacement null_placement_;
855-
const ::arrow::internal::ChunkResolver left_resolver_, right_resolver_;
855+
const ::arrow::ChunkResolver left_resolver_, right_resolver_;
856856
const std::vector<ResolvedSortKey> sort_keys_;
857857
uint64_t* indices_begin_;
858858
uint64_t* indices_end_;

‎cpp/src/arrow/compute/kernels/vector_sort_internal.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,9 @@ struct ResolvedTableSortKey {
749749
order(order),
750750
null_count(null_count) {}
751751

752-
using LocationType = ::arrow::internal::ChunkLocation;
752+
using LocationType = ::arrow::ChunkLocation;
753753

754-
ResolvedChunk GetChunk(::arrow::internal::ChunkLocation loc) const {
754+
ResolvedChunk GetChunk(::arrow::ChunkLocation loc) const {
755755
return {chunks[loc.chunk_index], loc.index_in_chunk};
756756
}
757757

‎cpp/src/arrow/stl_iterator.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class ChunkedArrayIterator {
237237
}
238238

239239
private:
240-
arrow::internal::ChunkLocation GetChunkLocation(int64_t index) const {
240+
arrow::ChunkLocation GetChunkLocation(int64_t index) const {
241241
assert(chunked_array_);
242242
return chunked_array_->chunk_resolver_.Resolve(index);
243243
}

‎docs/source/cpp/api/array.rst‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
Arrays
2020
======
2121

22+
Base classes
23+
============
24+
2225
.. doxygenclass:: arrow::ArrayData
2326
:project: arrow_cpp
2427
:members:
@@ -85,6 +88,17 @@ Chunked Arrays
8588
:project: arrow_cpp
8689
:members:
8790

91+
.. doxygenstruct:: arrow::ChunkLocation
92+
:project: arrow_cpp
93+
:members:
94+
95+
.. doxygenstruct:: arrow::TypedChunkLocation
96+
:project: arrow_cpp
97+
:members:
98+
99+
.. doxygenclass:: arrow::ChunkResolver
100+
:project: arrow_cpp
101+
:members:
88102

89103
Utilities
90104
=========

0 commit comments

Comments
 (0)