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
8 changes: 6 additions & 2 deletions lance_ray/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,17 @@ def create_scalar_index(
is_supported = (
pa.types.is_integer(value_type)
or pa.types.is_floating(value_type)
or (
pa.types.is_temporal(value_type)
and not pa.types.is_interval(value_type)
)
or pa.types.is_string(value_type)
or pa.types.is_large_string(value_type)
)
if not is_supported:
raise TypeError(
f"Column {column} must be numeric or string type for "
f"{index_type} index, got {value_type}"
f"Column {column} must be numeric, temporal (except interval), "
f"or string type for {index_type} index, got {value_type}"
)
case "LABEL_LIST":
if not (
Expand Down
53 changes: 52 additions & 1 deletion tests/test_vector_index_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ def _load_index_module_with_stubs() -> ModuleType:
index_mod = _load_index_module_with_stubs()


_TEMPORAL_TYPES = {
"event_date": pa.date32(),
"event_date64": pa.date64(),
"event_time32_s": pa.time32("s"),
"event_time32_ms": pa.time32("ms"),
"event_time64_us": pa.time64("us"),
"event_time64_ns": pa.time64("ns"),
"event_timestamp_s": pa.timestamp("s"),
"event_timestamp_ms": pa.timestamp("ms"),
"event_timestamp_us": pa.timestamp("us"),
"event_timestamp_ns": pa.timestamp("ns"),
"event_timestamp_s_utc": pa.timestamp("s", tz="UTC"),
"event_timestamp_ms_utc": pa.timestamp("ms", tz="UTC"),
"event_timestamp_us_utc": pa.timestamp("us", tz="UTC"),
"event_timestamp_ns_utc": pa.timestamp("ns", tz="UTC"),
"event_duration_s": pa.duration("s"),
"event_duration_ms": pa.duration("ms"),
"event_duration_us": pa.duration("us"),
"event_duration_ns": pa.duration("ns"),
}


class _FakeField:
def __init__(self, name: str, field_type: Any = None) -> None:
self.name = name
Expand All @@ -72,7 +94,7 @@ def id(self) -> int:

class _FakeLanceSchema:
def field(self, column: str) -> "_FakeLanceField":
if column not in {"value", "text", "labels"}:
if column not in {"value", "text", "labels"} and column not in _TEMPORAL_TYPES:
raise KeyError(column)
return _FakeLanceField()

Expand All @@ -87,6 +109,8 @@ def field(self, column: str) -> "_FakeField":
return _FakeField(column, pa.string())
if column == "labels":
return _FakeField(column, pa.list_(pa.string()))
if column in _TEMPORAL_TYPES:
return _FakeField(column, _TEMPORAL_TYPES[column])
else:
raise KeyError(column)

Expand All @@ -97,6 +121,7 @@ def __iter__(self) -> Any:
_FakeField("value", pa.int64()),
_FakeField("text", pa.string()),
_FakeField("labels", pa.list_(pa.string())),
*[_FakeField(name, dtype) for name, dtype in _TEMPORAL_TYPES.items()],
]
)

Expand Down Expand Up @@ -474,6 +499,11 @@ def test_create_index_rejects_invalid_num_segments(
("BLOOMFILTER", "value"),
("RTREE", "value"),
("LABEL_LIST", "labels"),
*[
(index_type, column)
for index_type in ("BTREE", "ZONEMAP")
for column in _TEMPORAL_TYPES
],
],
)
def test_create_scalar_index_uses_segment_path(
Expand Down Expand Up @@ -530,6 +560,27 @@ def fake_map_async_with_pool(**kwargs: Any) -> Any:
assert fake_dataset.commit_kwargs["segments"] == ["segment"]


@pytest.mark.parametrize("index_type", ["BTREE", "ZONEMAP"])
def test_create_ordered_scalar_index_rejects_interval_column(
monkeypatch: pytest.MonkeyPatch, index_type: str
) -> None:
"""Intervals should fail validation before Ray workers start."""

fake_dataset: Any = _FakeDataset()
monkeypatch.setattr(
fake_dataset,
"schema",
pa.schema([pa.field("event_date", pa.month_day_nano_interval())]),
)

with pytest.raises(TypeError, match=r"temporal \(except interval\)"):
index_mod.create_scalar_index(
uri=fake_dataset,
column="event_date",
index_type=cast(Any, index_type),
)


def test_create_label_list_index_rejects_non_list_column() -> None:
"""LABEL_LIST should reject invalid columns before Ray workers start."""

Expand Down
Loading