|
| 1 | +"""Unit test for Milvus varchar_max_length configuration.""" |
| 2 | + |
| 3 | +from datetime import timedelta |
| 4 | +from unittest.mock import MagicMock, patch |
| 5 | + |
| 6 | +import pytest |
| 7 | +from pydantic import ValidationError |
| 8 | + |
| 9 | +from feast import Entity, FeatureView |
| 10 | +from feast.field import Field |
| 11 | +from feast.infra.online_stores.milvus_online_store.milvus import ( |
| 12 | + MilvusOnlineStore, |
| 13 | + MilvusOnlineStoreConfig, |
| 14 | +) |
| 15 | +from feast.types import Float32, String |
| 16 | +from feast.value_type import ValueType |
| 17 | + |
| 18 | + |
| 19 | +@patch("feast.infra.online_stores.milvus_online_store.milvus.MilvusClient") |
| 20 | +def test_varchar_max_length(mock_client_cls): |
| 21 | + # -- config: default and custom values ------------------------------------ |
| 22 | + assert MilvusOnlineStoreConfig().varchar_max_length == 65535 |
| 23 | + assert MilvusOnlineStoreConfig(varchar_max_length=1024).varchar_max_length == 1024 |
| 24 | + |
| 25 | + # -- config: out-of-bounds values raise ValidationError ------------------- |
| 26 | + for bad in (0, -1, 65536): |
| 27 | + with pytest.raises(ValidationError): |
| 28 | + MilvusOnlineStoreConfig(varchar_max_length=bad) |
| 29 | + |
| 30 | + # -- schema: configured value reaches every VARCHAR FieldSchema ----------- |
| 31 | + mock_client = MagicMock() |
| 32 | + mock_client_cls.return_value = mock_client |
| 33 | + mock_client.has_collection.return_value = False |
| 34 | + |
| 35 | + entity = Entity( |
| 36 | + name="driver_id", join_keys=["driver_id"], value_type=ValueType.INT64 |
| 37 | + ) |
| 38 | + fv = FeatureView( |
| 39 | + name="driver_stats", |
| 40 | + entities=[entity], |
| 41 | + ttl=timedelta(days=1), |
| 42 | + schema=[ |
| 43 | + Field(name="trips_today", dtype=Float32), |
| 44 | + Field(name="wiki_summary", dtype=String), |
| 45 | + ], |
| 46 | + ) |
| 47 | + |
| 48 | + config = MagicMock() |
| 49 | + config.project = "test_project" |
| 50 | + config.entity_key_serialization_version = 2 |
| 51 | + config.registry.enable_online_feature_view_versioning = False |
| 52 | + config.provider = "local" |
| 53 | + config.repo_path = None |
| 54 | + config.online_store = MilvusOnlineStoreConfig(varchar_max_length=4096) |
| 55 | + |
| 56 | + store = MilvusOnlineStore() |
| 57 | + store._collections = {} |
| 58 | + store.client = mock_client |
| 59 | + store._get_or_create_collection(config, fv) |
| 60 | + |
| 61 | + schema = mock_client.create_collection.call_args.kwargs["schema"] |
| 62 | + for field in schema.fields: |
| 63 | + if hasattr(field, "max_length") and field.max_length is not None: |
| 64 | + assert field.max_length == 4096, ( |
| 65 | + f"field '{field.name}': got {field.max_length}" |
| 66 | + ) |
0 commit comments