Skip to content

[BUG] Panic when querying table with wrong partition columns order #9785

@MohamedAbdeen21

Description

@MohamedAbdeen21

Describe the bug

Assume a table test that is partitioned on columns a then b, creating an external table and setting wrong order for the partition columns (b then a) doesn't raise an error, but querying it causes a panic.

To Reproduce

copy these queries into panic.sql

CREATE EXTERNAL TABLE test(name string, year string, month string) PARTITIONED BY (year, month) STORED AS csv LOCATION 'tmp/';
INSERT INTO test VALUES('name', '2024', '03');

-- notice the different ordering in the PARTITIONED BY clause
CREATE EXTERNAL TABLE test2(name string, year string, month string) PARTITIONED BY (month, year) STORED AS csv LOCATION 'tmp/';
SELECT * FROM test2;

And run

$ datafusion-cli -f panic.sql
DataFusion CLI v36.0.0
0 rows in set. Query took 0.002 seconds.

+-------+
| count |
+-------+
| 1     |
+-------+
1 row in set. Query took 0.004 seconds.

0 rows in set. Query took 0.001 seconds.

thread 'main' panicked at /home/user/dev/arrow-datafusion/datafusion/core/src/datasource/physical_plan/file_scan_config.rs:261:54:
index out of bounds: the len is 0 but the index is 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior

Should never panic. Instead, return an error on table creation or at least on the queries after.

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