felipecrv commented on code in PR #41700:
URL: https://github.com/apache/arrow/pull/41700#discussion_r1723511661
##########
cpp/src/arrow/compute/kernels/vector_selection_take_internal.cc:
##########
@@ -326,6 +327,129 @@ namespace {
using TakeState = OptionsWrapper<TakeOptions>;
+class ValuesSpan {
+ private:
+ const std::shared_ptr<ChunkedArray> chunked_ = nullptr;
+ const ArraySpan chunk0_; // first chunk or the whole array
+
+ public:
+ explicit ValuesSpan(const std::shared_ptr<ChunkedArray> values)
+ : chunked_(std::move(values)), chunk0_{*values->chunk(0)->data()} {
+ DCHECK(chunked_);
+ DCHECK_GT(chunked_->num_chunks(), 0);
+ }
+
+ explicit ValuesSpan(const ArraySpan& values) : chunk0_(values) {}
+
+ bool is_chunked() const { return chunked_ != nullptr; }
+
+ const ChunkedArray& chunked_array() const {
+ DCHECK(is_chunked());
+ return *chunked_;
+ }
+
+ const ArraySpan& chunk0() const { return chunk0_; }
+
+ const ArraySpan& array() const {
+ DCHECK(!is_chunked());
+ return chunk0_;
+ }
+
+ const DataType* type() const { return chunk0_.type; }
+
+ int64_t length() const { return is_chunked() ? chunked_->length() :
array().length; }
+
+ bool MayHaveNulls() const {
+ return is_chunked() ? chunked_->null_count() != 0 : array().MayHaveNulls();
+ }
+};
+
+struct ChunkedFixedWidthValuesSpan {
+ private:
+ // src_residual_bit_offsets_[i] is used to store the bit offset of the first
byte (0-7)
+ // in src_chunks_[i] iff kValueWidthInBits == 1.
+ std::vector<int> src_residual_bit_offsets;
+ // Pre-computed pointers to the start of the values in each chunk.
+ std::vector<const uint8_t*> src_chunks;
+
+ public:
+ explicit ChunkedFixedWidthValuesSpan(const ChunkedArray& values) {
+ const bool chunk_values_are_bit_sized = values.type()->id() == Type::BOOL;
+ DCHECK_EQ(chunk_values_are_bit_sized,
util::FixedWidthInBytes(*values.type()) == -1);
+ if (chunk_values_are_bit_sized) {
+ src_residual_bit_offsets.resize(values.num_chunks());
+ }
+ src_chunks.resize(values.num_chunks());
+
+ for (int i = 0; i < values.num_chunks(); ++i) {
+ const ArraySpan chunk{*values.chunk(i)->data()};
+ DCHECK(util::IsFixedWidthLike(chunk));
+
+ auto offset_pointer = util::OffsetPointerOfFixedBitWidthValues(chunk);
+ if (chunk_values_are_bit_sized) {
+ src_residual_bit_offsets[i] = offset_pointer.first;
+ } else {
+ DCHECK_EQ(offset_pointer.first, 0);
+ }
+ src_chunks[i] = offset_pointer.second;
+ }
+ }
+
+ ~ChunkedFixedWidthValuesSpan() = default;
Review Comment:
I will remove.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]