apache / apache/arrow

`binary_replace_slice` should not work with `string` types

Open
#33,490 1 comment 0 reactions 0 assignees View on GitHub
Component: C++ Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

`binary_replace_slice` can give in invalid output when used with string types. Given that there is `utf8_replace_slice`, I think `binary_replace_slice` should not support string types.

If a user actually wants to play with bytes for string type, they should explicitly cast to binary type and use `binary_replace_slice`.
```java

>>> pc.binary_replace_slice(["hé"], 1, 2, "x")

[
"hx�"
]
>>> pc.binary_replace_slice(["hé"], 1, 2, "x").validate(full=True)
Traceback (most recent call last):
...
ArrowInvalid: Invalid UTF8 sequence at string index 0
```

Ref:

 

cc: @pitrou  

**Reporter**: [Kshiteej K](https://issues.apache.org/jira/browse/ARROW-18319) / @kshitij12345

**Note**: *This issue was originally created as [ARROW-18319](https://issues.apache.org/jira/browse/ARROW-18319). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Python examples for binary_replace_slice and utf8_replace_slice, including validate(full=True), and trace how string inputs are handled. Done means binary_replace_slice no longer accepts string types that can produce invalid UTF-8, while callers can explicitly cast to binary and use the operation successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.