datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

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

Open jonahgao opened this issue 1 year ago • 0 comments

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

jonahgao avatar May 16 '24 14:05 jonahgao