Skip to content

Panic: index out of bounds: the len is 0 but the index is 0 in first_value / last_value when used as an aggregate #7118

@alamb

Description

@alamb

Describe the bug

Panic: index out of bounds: the len is 0 but the index is 0 in first_value / last_value when used as an aggregate

To Reproduce

create table foo (x int) as values (1), (2);
select last_value(x) from foo;

Result:

(arrow_dev) alamb@MacBook-Pro-8:~/Software/influxdb_iox2$ datafusion-cli
DataFusion CLI v28.0.0
❯ create table foo (x int) as values (1), (2);
0 rows in set. Query took 0.003 seconds.
❯ select last_value(x) from foo;
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /Users/alamb/Software/arrow-datafusion/datafusion/physical-expr/src/aggregate/first_last.rs:374:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

These other queries panic:

0 rows in set. Query took 0.003 seconds.
❯ select last_value(x) from foo GROUP BY x;
thread 'thread 'tokio-runtime-workertokio-runtime-worker' panicked at '' panicked at 'index out of bounds: the len is 0 but the index is 0index out of bounds: the len is 0 but the index is 0', ', /Users/alamb/Software/arrow-datafusion/datafusion/physical-expr/src/aggregate/first_last.rs/Users/alamb/Software/arrow-datafusion/datafusion/physical-expr/src/aggregate/first_last.rs::374374::1313


❯ select first_value(x) from foo GROUP BY x;
thread 'thread 'tokio-runtime-workertokio-runtime-worker' panicked at '' panicked at 'index out of bounds: the len is 0 but the index is 0index out of bounds: the len is 0 but the index is 0', ', /Users/alamb/Software/arrow-datafusion/datafusion/physical-expr/src/aggregate/first_last.rs/Users/alamb/Software/arrow-datafusion/datafusion/physical-expr/src/aggregate/first_last.rs:189::13189
:note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior

query should run successfully

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    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