Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions python/python/tests/test_scalar_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,25 @@ def test_label_list_index_array_contains(tmp_path: Path):
assert "ScalarIndexQuery" not in explain


def test_label_list_index_empty_list_filters(tmp_path: Path):
"""Empty list filters should not panic and should match pre-index results."""
tbl = pa.table({"labels": [["foo"], ["bar"], ["foo", None], [None], [], None]})
dataset = lance.write_dataset(tbl, tmp_path / "dataset")

filters = [
"array_has_any(labels, [])",
"array_has_all(labels, [])",
"NOT array_has_all(labels, [])",
"NOT array_has_any(labels, [])",
]
expected = {f: dataset.to_table(filter=f).num_rows for f in filters}

dataset.create_scalar_index("labels", index_type="LABEL_LIST")

for f in filters:
assert dataset.to_table(filter=f).num_rows == expected[f]


def test_label_list_index_null_element_match(tmp_path: Path):
"""Covers NULL elements inside non-NULL lists (list itself is never NULL)."""
tbl = pa.table(
Expand Down
3 changes: 3 additions & 0 deletions rust/lance-index/src/scalar/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ impl ScalarQueryParser for LabelListQueryParser {
let label_list = maybe_scalar(&args[1], data_type)?;
if let ScalarValue::List(list_arr) = label_list {
let list_values = list_arr.values();
if list_values.is_empty() {
return None;
}
let mut scalars = Vec::with_capacity(list_values.len());
for idx in 0..list_values.len() {
scalars.push(ScalarValue::try_from_array(list_values.as_ref(), idx).ok()?);
Expand Down
Loading