Skip to content

Commit

Permalink
ARROW-12906: [C++][Python] Fix fill_null segfault
Browse files Browse the repository at this point in the history
Closes #10434 from cyb70289/12906-fill-null-crash

Authored-by: Yibo Cai <yibo.cai@arm.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
  • Loading branch information
cyb70289 authored and pitrou committed Jun 2, 2021
1 parent f3344dc commit dc397b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cpp/src/arrow/compute/kernels/scalar_fill_null.cc
Expand Up @@ -162,7 +162,6 @@ struct FillNullFunctor<Type, enable_if_t<is_base_binary_type<Type>::value>> {
const ArrayData& input = *batch[0].array();
const auto& fill_value_scalar =
checked_cast<const BaseBinaryScalar&>(*batch[1].scalar());
util::string_view fill_value(*fill_value_scalar.value);
ArrayData* output = out->mutable_array();

// Ensure the kernel is configured properly to have no validity bitmap /
Expand All @@ -172,6 +171,7 @@ struct FillNullFunctor<Type, enable_if_t<is_base_binary_type<Type>::value>> {
const int64_t null_count = input.GetNullCount();

if (null_count > 0 && fill_value_scalar.is_valid) {
util::string_view fill_value(*fill_value_scalar.value);
BuilderType builder(input.type, ctx->memory_pool());
RETURN_NOT_OK(builder.ReserveData(input.buffers[2]->size() +
fill_value.length() * null_count));
Expand Down
5 changes: 5 additions & 0 deletions python/pyarrow/tests/test_compute.py
Expand Up @@ -1078,6 +1078,11 @@ def test_fill_null():
expected = pa.array([b'a', b'bb', b'ccc'], type=pa.large_binary())
assert result.equals(expected)

arr = pa.array(['a', 'bb', None])
result = arr.fill_null(None)
expected = pa.array(['a', 'bb', None])
assert result.equals(expected)


@pytest.mark.parametrize('arrow_type', numerical_arrow_types)
def test_fill_null_array(arrow_type):
Expand Down

0 comments on commit dc397b7

Please sign in to comment.