Skip to content

[Bug] BITMAP index panic on BETWEEN when low > high #5878

@fenfeng9

Description

@fenfeng9

Description

When using a BITMAP scalar index, a BETWEEN filter with inverted bounds (low > high) triggers a Rust panic in a background thread. Instead of returning an empty result.

How to reproduce

import tempfile

import lance
import pyarrow as pa


def main() -> None:
    data = pa.table({"c0": pa.array([1, 2, 3], type=pa.int64())})
    filter_expr = "c0 BETWEEN 2 AND 1"  # low > high

    work_dir = tempfile.mkdtemp()
    path = f"{work_dir}/ds"

    lance.write_dataset(data, path)
    ds = lance.dataset(path)
    ds.create_scalar_index("c0", index_type="BITMAP")

    print("Executing query... (expect panic in stderr)")
    result = ds.to_table(filter=filter_expr)
    print("Rows:", result.num_rows)

if __name__ == "__main__":
    main()

Result

Executing query... (expect panic in stderr)

thread 'lance_background_thread' panicked at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library/alloc/src/collections/btree/search.rs:121:21:
range start is greater than range end in BTreeMap
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "test.py", line 23, in <module>
    main()
  File "test.py", line 19, in main
    result = ds.to_table(filter=filter_expr)
  File ".../site-packages/lance/dataset.py", line 1113, in to_table
    ).to_table()
  File ".../site-packages/lance/dataset.py", line 4963, in to_table
    return self.to_reader().read_all()
  File "pyarrow/ipc.pxi", line 762, in pyarrow.lib.RecordBatchReader.read_all
  File "pyarrow/error.pxi", line 92, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: External error: RuntimeError: Task was aborted

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcritical-fixBugs that cause crashes, security vulnerabilities, or incorrect data.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions