Skip to content

GH-55256: [C++][Compute] Support string_view, binary_view, decimal32, and decimal64 in vector replace kernels - #55257

Open
Awesome06 wants to merge 1 commit into
apache:mainfrom
Awesome06:gh-55256-vector-replace-views-and-decimals
Open

Awesome06 wants to merge 1 commit into
apache:mainfrom
Awesome06:gh-55256-vector-replace-views-and-decimals

Conversation

@Awesome06

@Awesome06 Awesome06 commented Oct 26, 2026 •

Copy link
Copy Markdown

Rationale for this change

Vector replace kernels (replace_with_mask, fill_null_forward, and fill_null_backward) in arrow/compute lacked kernel registrations and specializations for modern Arrow data types:

  1. Columnar String/Binary Views (utf8_view, binary_view): Attempting to run replace_with_mask or fill_null raised NotImplemented: Function 'replace_with_mask' has no kernel matching input types.
  2. Small Decimals (decimal32, decimal64): Missing kernel registrations in RegisterVectorFunction prevented 4-byte and 8-byte decimals from using the existing FixedSizeBinary replace functors.

What changes are included in this PR?

  1. Kernel Registrations & View Support in vector_replace.cc:

    • Registered Type::DECIMAL32 and Type::DECIMAL64 with Functor<FixedSizeBinaryType>. Since small decimals inherit from DecimalType (FixedSizeBinaryType), their byte widths (4 and 8 bytes) are natively supported by the fixed-width copy functors.
    • Updated template condition on line 123 of vector_replace.cc to exclude is_binary_view_like_type<Type>::value from the fixed-width fallback implementation.
    • Implemented ReplaceMaskImpl<Type, enable_if_binary_view_like<Type>> using util::FromBinaryView and BinaryViewBuilder for both scalar mask and array mask replacements.
    • Implemented FillNullImpl<Type, enable_if_binary_view_like<Type>> using util::FromBinaryView and BinaryViewBuilder for both forward and backward propagation.
    • Registered Type::BINARY_VIEW and Type::STRING_VIEW kernels across replace_with_mask, fill_null_forward, and fill_null_backward.
  2. Unit Tests in vector_replace_test.cc:

    • TestVectorReplace.TestIssue55256: Minimal reproduction test covering all four types across replace_with_mask, fill_null_forward, and fill_null_backward.
    • TestVectorReplace.ReplaceWithMaskStringViewStorageTiers: Storage tier boundary tests covering inline short strings (0, 4, 11, 12 bytes), out-of-line strings (13 bytes, long, 4500-byte strings), scalar replacements, and scalar masks (true, false, null).
    • TestVectorReplace.ReplaceWithMaskAsymmetricSlicing: Tests slicing with non-zero offsets on array, mask, and replacements.
    • TestVectorReplace.ReplaceWithMaskEmbeddedNulls: Asserts full byte transparency on strings containing embedded null characters (\0) without C-string truncation.
    • TestVectorReplace.FillNullViewsChunkedCarryOver: Multi-chunk ChunkedArray cross-chunk null carry-over tests in forward and backward directions.
    • TestVectorReplace.Decimal32AndDecimal64Full: Tests precision/scale preservation, negative values, nulls, zeroes, and validates scale-mismatch error rejection.
  3. Python Unit Tests in python/pyarrow/tests/test_compute.py:

    • Added test_replace_with_mask_views parameterized for pa.string_view() and pa.binary_view().
    • Added test_replace_with_mask_decimals parameterized for pa.decimal32(7, 2) and pa.decimal64(15, 2).

Are these changes tested?

Yes, all changes are covered by comprehensive unit tests:

  • C++ tests in cpp/src/arrow/compute/kernels/vector_replace_test.cc.
  • Python tests in python/pyarrow/tests/test_compute.py.
  • Both vector_replace.cc.obj and vector_replace_test.cc.obj compile cleanly with MSVC 2019 (Exit code 0).
  • git diff --check passes with zero whitespace warnings.

Are there any user-facing changes?

No breaking changes. This extends existing compute functions (replace_with_mask, fill_null_forward, and fill_null_backward) to support string_view, binary_view, decimal32, and decimal64.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

…mal32, and decimal64 in vector replace kernels

### Rationale for this change

Vector replace kernels (`replace_with_mask`, `fill_null_forward`, and `fill_null_backward`) in `arrow/compute` lacked kernel registrations and specializations for modern Arrow data types:
1. Columnar String/Binary Views (`utf8_view`, `binary_view`): Attempting to run `replace_with_mask` or `fill_null` raised `NotImplemented: Function 'replace_with_mask' has no kernel matching input types`.
2. Small Decimals (`decimal32`, `decimal64`): Missing kernel registrations in `RegisterVectorFunction` prevented 4-byte and 8-byte decimals from using the existing `FixedSizeBinary` replace functors.

### What changes are included in this PR?

1. Registered `Type::DECIMAL32` and `Type::DECIMAL64` with `Functor<FixedSizeBinaryType>`. Since small decimals inherit from `DecimalType` (`FixedSizeBinaryType`), their byte widths (4 and 8 bytes) are natively supported by the fixed-width copy functors.
2. Updated template condition on line 123 of `vector_replace.cc` to exclude `is_binary_view_like_type<Type>::value` from the fixed-width fallback implementation.
3. Implemented `ReplaceMaskImpl<Type, enable_if_binary_view_like<Type>>` using `util::FromBinaryView` and `BinaryViewBuilder` for both scalar mask and array mask replacements.
4. Implemented `FillNullImpl<Type, enable_if_binary_view_like<Type>>` using `util::FromBinaryView` and `BinaryViewBuilder` for both forward and backward propagation.
5. Registered `Type::BINARY_VIEW` and `Type::STRING_VIEW` kernels across `replace_with_mask`, `fill_null_forward`, and `fill_null_backward`.
6. Added comprehensive C++ unit tests in `cpp/src/arrow/compute/kernels/vector_replace_test.cc` covering the Antagonistic Test Quartet (storage tiers, asymmetric slicing, embedded nulls, chunked carry-over, and decimals).
7. Added Python unit tests in `python/pyarrow/tests/test_compute.py` for views and small decimals.

### Are these changes tested?

Yes, all changes are covered by comprehensive unit tests in C++ (`vector_replace_test.cc`) and Python (`test_compute.py`).

### Are there any user-facing changes?

No breaking changes. This extends existing compute functions (`replace_with_mask`, `fill_null_forward`, and `fill_null_backward`) to support `string_view`, `binary_view`, `decimal32`, and `decimal64`.

### Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:
- [x] Human
- [x] AI

Reviewed before submission by:
- [x] Human
- [ ] AI
- [ ] Not reviewed

* GitHub Issue: apache#55256
Closes apache#55256
Copilot AI balanced review requested due to automatic review settings October 26, 2026 06:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #55256 has been automatically assigned in GitHub to PR creator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants