Skip to content

array_slice can't correctly handle NULL parameters or some edge cases #10548

@jonahgao

Description

@jonahgao

Describe the bug

These queries will give errors or incorrect results.

To Reproduce

Run queries in CLI:

DataFusion CLI v38.0.0

> select array_slice([1,2,3], 1, NULL);
Internal error: could not cast value to arrow_array::array::primitive_array::PrimitiveArray<arrow_array::types::Int64Type>.
This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker

> select array_slice([1,2,3], -100, 1) r;
+----+
| r  |
+----+
| [] |
+----+
1 row(s) fetched.
Elapsed 0.006 seconds.

> select array_slice([1,2,3], 1, 1, -1) r;
+----+
| r  |
+----+
| [] |
+----+

Expected behavior

The results of DuckDB look correct to me.

v0.10.3-dev779 d26007417b

D select array_slice([1,2,3], 1, NULL);
┌────────────────────────────────────────────────┐
│ array_slice(main.list_value(1, 2, 3), 1, NULL) │
│                    int32[]                     │
├────────────────────────────────────────────────┤
│                                                │
└────────────────────────────────────────────────┘
D select array_slice([1,2,3], -100, 1);
┌────────────────────────────────────────────────┐
│ array_slice(main.list_value(1, 2, 3), -100, 1) │
│                    int32[]                     │
├────────────────────────────────────────────────┤
│ [1]                                            │
└────────────────────────────────────────────────┘
D select array_slice([1,2,3], 1, 1, -1) r;
┌─────────┐
│    r    │
│ int32[] │
├─────────┤
│ [1]     │
└─────────┘

Additional context

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions