Skip to content
Open
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
20 changes: 20 additions & 0 deletions cpp/src/arrow/array/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,26 @@ TEST_F(TestArray, TestBinaryViewAppendArraySlice) {
AssertArraysEqual(*src, *dst);
}

// GH-54924: ArraySpan::HasVariadicBuffers must look through extension types.
TEST_F(TestArray, TestBinaryViewExtensionArraySpanRoundtrip) {
auto storage = ArrayFromJSON(
binary_view(),
R"([null, "short", "long string that is not inlined", "another somewhat long string"])");
auto extension_type = binary_view_extension_type();
auto extension_array = ExtensionType::WrapArray(extension_type, storage);
ASSERT_OK(extension_array->ValidateFull());

ArraySpan span(*extension_array->data());
ASSERT_TRUE(span.HasVariadicBuffers());
ASSERT_EQ(span.GetVariadicBuffers().size(), storage->data()->buffers.size() - 2);

auto roundtripped = span.ToArray();
ASSERT_OK(roundtripped->ValidateFull());
AssertArraysEqual(*extension_array, *roundtripped);
ASSERT_EQ(roundtripped->data()->buffers.size(),
extension_array->data()->buffers.size());
}

TEST_F(TestArray, ValidateBuffersPrimitive) {
auto empty_buffer = std::make_shared<Buffer>("");
auto null_buffer = Buffer::FromString("\xff");
Expand Down
9 changes: 7 additions & 2 deletions cpp/src/arrow/array/data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void ArraySpan::SetMembers(const ArrayData& data) {
this->buffers[i] = {};
}

if (type_id == Type::STRING_VIEW || type_id == Type::BINARY_VIEW) {
if (HasVariadicBuffers()) {
// store the span of data buffers in the third buffer
this->buffers[2] = internal::PackVariadicBuffers(std::span(data.buffers).subspan(2));
}
Expand Down Expand Up @@ -687,7 +687,12 @@ std::span<const std::shared_ptr<Buffer>> ArraySpan::GetVariadicBuffers() const {
}

bool ArraySpan::HasVariadicBuffers() const {
return type->id() == Type::BINARY_VIEW || type->id() == Type::STRING_VIEW;
Type::type type_id = type->id();
if (type_id == Type::EXTENSION) {
const auto* ext_type = checked_cast<const ExtensionType*>(type);
type_id = ext_type->storage_type()->id();
}
return type_id == Type::BINARY_VIEW || type_id == Type::STRING_VIEW;
}

std::shared_ptr<Array> ArraySpan::ToArray() const {
Expand Down
Loading