You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by fs...@apache.org on 2020/05/25 12:42:45 UTC
[arrow] branch master updated: ARROW-8911: [C++] Fix segfault when
slicing ChunkedArray with zero chunks
This is an automated email from the ASF dual-hosted git repository.
fsaintjacques pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 20957ab ARROW-8911: [C++] Fix segfault when slicing ChunkedArray with zero chunks
20957ab is described below
commit 20957abe78b0c9ee887e99ae106ec702076f0e05
Author: Wes McKinney <we...@apache.org>
AuthorDate: Mon May 25 08:42:25 2020 -0400
ARROW-8911: [C++] Fix segfault when slicing ChunkedArray with zero chunks
Closes #7262 from wesm/ARROW-8911
Authored-by: Wes McKinney <we...@apache.org>
Signed-off-by: François Saint-Jacques <fs...@gmail.com>
---
cpp/src/arrow/table.cc | 4 ++--
cpp/src/arrow/table_test.cc | 11 +++++++++++
python/pyarrow/tests/test_array.py | 12 ++++++++++++
3 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/cpp/src/arrow/table.cc b/cpp/src/arrow/table.cc
index 9c62fe7..a9c2f76 100644
--- a/cpp/src/arrow/table.cc
+++ b/cpp/src/arrow/table.cc
@@ -111,9 +111,9 @@ std::shared_ptr<ChunkedArray> ChunkedArray::Slice(int64_t offset, int64_t length
}
ArrayVector new_chunks;
- if (offset_equals_length || (length == 0 && num_chunks() > 0)) {
+ if (num_chunks() > 0 && (offset_equals_length || length == 0)) {
// Special case the zero-length slice to make sure there is at least 1 Array
- // in the result
+ // in the result. When there are zero chunks we return zero chunks
new_chunks.push_back(chunk(std::min(curr_chunk, num_chunks() - 1))->Slice(0, 0));
} else {
while (curr_chunk < num_chunks() && length > 0) {
diff --git a/cpp/src/arrow/table_test.cc b/cpp/src/arrow/table_test.cc
index 4df241f..76d817a 100644
--- a/cpp/src/arrow/table_test.cc
+++ b/cpp/src/arrow/table_test.cc
@@ -152,6 +152,17 @@ TEST_F(TestChunkedArray, SliceEquals) {
ASSERT_TRUE(slice5->type()->Equals(one_->type()));
}
+TEST_F(TestChunkedArray, ZeroChunksIssues) {
+ ArrayVector empty = {};
+ auto no_chunks = std::make_shared<ChunkedArray>(empty, int8());
+
+ // ARROW-8911, assert that slicing is a no-op when there are zero-chunks
+ auto sliced = no_chunks->Slice(0, 0);
+ auto sliced2 = no_chunks->Slice(0, 5);
+ AssertChunkedEqual(*no_chunks, *sliced);
+ AssertChunkedEqual(*no_chunks, *sliced2);
+}
+
TEST_F(TestChunkedArray, Validate) {
// Valid if empty
ArrayVector empty = {};
diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py
index e5ccbf1..9cc80ed 100644
--- a/python/pyarrow/tests/test_array.py
+++ b/python/pyarrow/tests/test_array.py
@@ -965,6 +965,18 @@ def test_cast_list_to_primitive():
arr.cast(pa.binary())
+def test_slice_chunked_array_zero_chunks():
+ # ARROW-8911
+ arr = pa.chunked_array([], type='int8')
+ assert arr.num_chunks == 0
+
+ result = arr[:]
+ assert result.equals(arr)
+
+ # Do not crash
+ arr[:5]
+
+
def test_cast_chunked_array():
arrays = [pa.array([1, 2, 3]), pa.array([4, 5, 6])]
carr = pa.chunked_array(arrays)