apache / apache/datafusion

octet_length(char) doesn't behave as expected.

Open
#6,508 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

### Describe the bug

Hi there,

``select octet_length(char)`` doesn't behave as expected.

In the example below - in Postgres (``text`` column) the below SQL would return 25 as the result however in DataFusion (``StringArray`` column ) it just returns the original length of the values in ``n_name``.

```sql
select octet_length(n_name::char(25)) from nation;
```

I'm not sure if this is because the cast to a ``char(25)`` is not behaving as expected

### To Reproduce

create a StringColumn in DF, populate it with some values and run the following SQL on it.

```sql
select octet_length(n_name::char(25)) from nation;
```

### Expected behavior

Should return 25, but it returns the length of each of the values in the column.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the SQL reproduction using a DataFusion StringArray and compare octet_length(n_name::char(25)) with PostgreSQL's result. Trace the cast to char(25) and octet_length behavior, then add coverage showing that the expression returns 25 for the reproduced values.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, rust, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.