Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion cpp/src/arrow/array/array_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,30 @@ class BaseBinaryArray : public FlatArray {
return raw_value_offsets_ + data_->offset;
}

// Neither of these functions will perform boundschecking
/// \brief Return the data buffer absolute offset of the data for the value
/// at the passed index.
///
/// Does not perform boundschecking
offset_type value_offset(int64_t i) const {
return raw_value_offsets_[i + data_->offset];
}

/// \brief Return the length of the data for the value at the passed index.
///
/// Does not perform boundschecking
offset_type value_length(int64_t i) const {
i += data_->offset;
return raw_value_offsets_[i + 1] - raw_value_offsets_[i];
}

/// \brief Return the total length of the memory in the data buffer
/// referenced by this array. If the array has been sliced then this may be
/// less than the size of the data buffer (data_->buffers[2]).
offset_type total_values_length() const {
return raw_value_offsets_[data_->length + data_->offset] -
raw_value_offsets_[data_->offset];
}

protected:
// For subclasses
BaseBinaryArray() : raw_value_offsets_(NULLPTR), raw_data_(NULLPTR) {}
Expand Down
12 changes: 12 additions & 0 deletions cpp/src/arrow/array/array_binary_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ class TestStringArray : public ::testing::Test {
AssertZeroPadded(*strings_);
}

void TestTotalValuesLength() {
auto ty = TypeTraits<T>::type_singleton();
auto arr = ArrayFromJSON(ty, R"(["a", null, "bbb", "cccc", "ddddd"])");

offset_type values_length = arr.total_values_length();
ASSERT_EQ(values_length, static_cast<offset_type>(13));

offset_type sliced_values_length =
checked_cast<const ArrayType&>(*arr.Slice(3)).total_values_length();
ASSERT_EQ(sliced_values_length, static_cast<offset_type>(9));
}

void TestType() {
std::shared_ptr<DataType> type = this->strings_->type();

Expand Down