diff --git a/cpp/src/arrow/array/array_list_test.cc b/cpp/src/arrow/array/array_list_test.cc index 4901a1e6fa6..2f5918f79a3 100644 --- a/cpp/src/arrow/array/array_list_test.cc +++ b/cpp/src/arrow/array/array_list_test.cc @@ -1600,6 +1600,16 @@ class TestFixedSizeListArray : public ::testing::Test { std::shared_ptr result_; }; +// TEST_F(TestFixedSizeListArray, TestUnsafeAppend) { +// ASSERT_OK(builder_->Reserve(2)); +// builder_->UnsafeAppend(); +// builder_->UnsafeAppend(); + +// Done(); + +// ASSERT_EQ(result_->length(), 2); +// } + TEST_F(TestFixedSizeListArray, Equality) { Int32Builder* vb = checked_cast(builder_->value_builder()); @@ -1722,6 +1732,30 @@ TEST_F(TestFixedSizeListArray, TestBasics) { ValidateBasicFixedSizeListArray(result_.get(), values, is_valid); } +TEST_F(TestFixedSizeListArray, TestBasicsWithUnsafeAppend) { + std::vector values = {0, 1, 2, 3, 4, 5}; + std::vector is_valid = {1, 0, 1}; + + Int32Builder* vb = checked_cast(builder_->value_builder()); + + int pos = 0; + ASSERT_OK(builder_->Reserve(values.size() / list_size())); + for (size_t i = 0; i < values.size() / list_size(); ++i) { + if (is_valid[i] == 0) { + ASSERT_OK(builder_->AppendNull()); + pos += list_size(); + continue; + } + builder_->UnsafeAppend(); + for (int j = 0; j < list_size(); ++j) { + ASSERT_OK(vb->Append(values[pos++])); + } + } + + Done(); + ValidateBasicFixedSizeListArray(result_.get(), values, is_valid); +} + TEST_F(TestFixedSizeListArray, BulkAppend) { std::vector values = {0, 1, 2, 3, 4, 5}; std::vector is_valid = {1, 0, 1}; diff --git a/cpp/src/arrow/array/builder_nested.cc b/cpp/src/arrow/array/builder_nested.cc index 915fbfbf895..f8475db65b3 100644 --- a/cpp/src/arrow/array/builder_nested.cc +++ b/cpp/src/arrow/array/builder_nested.cc @@ -200,7 +200,7 @@ void FixedSizeListBuilder::Reset() { Status FixedSizeListBuilder::Append() { RETURN_NOT_OK(Reserve(1)); - UnsafeAppendToBitmap(true); + UnsafeAppend(); return Status::OK(); } diff --git a/cpp/src/arrow/array/builder_nested.h b/cpp/src/arrow/array/builder_nested.h index fdbeb0cd7d1..9abfdb6202a 100644 --- a/cpp/src/arrow/array/builder_nested.h +++ b/cpp/src/arrow/array/builder_nested.h @@ -725,6 +725,13 @@ class ARROW_EXPORT FixedSizeListBuilder : public ArrayBuilder { return std::numeric_limits::max() - 1; } + /// \brief UnsafeAppend a valid fixed length list. + /// + /// This function affects only the validity bitmap; the child values must be appended + /// using the child array builder. The caller must ensure that sufficient capacity is + /// available. + void UnsafeAppend() { UnsafeAppendToBitmap(true); } + protected: std::shared_ptr value_field_; const int32_t list_size_;