Skip to content

Commit ba39f93

Browse files
committed
add test
1 parent 7935071 commit ba39f93

7 files changed

Lines changed: 74 additions & 5 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ test-python-universal-postgres-offline:
200200
test-python-universal-postgres-online:
201201
PYTHONPATH='.' \
202202
FULL_REPO_CONFIGS_MODULE=sdk.python.feast.infra.online_stores.contrib.postgres_repo_configuration \
203-
PYTEST_PLUGINS=sdk.python.feast.infra.offline_stores.contrib.postgres_offline_store.tests \
203+
PYTEST_PLUGINS=sdk.python.tests.integration.feature_repos.universal.online_store.postgres \
204204
python -m pytest -n 8 --integration \
205205
-k "not test_universal_cli and \
206206
not test_go_feature_server and \

sdk/python/feast/feature_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,12 +1698,12 @@ def retrieve_online_documents(
16981698
top_k: int,
16991699
) -> OnlineResponse:
17001700
"""
1701-
Retrieves the top k closest document features.
1701+
Retrieves the top k closest document features. Note, embeddings are a subset of features.
17021702
17031703
Args:
17041704
feature: The list of document features that should be retrieved from the online document store. These features can be
17051705
specified either as a list of string document feature references or as a feature service. String feature
1706-
references must have format "feature_view:feature", e.g, "document_fv:document_embedding_feature".
1706+
references must have format "feature_view:feature", e.g, "document_fv:document_embeddings".
17071707
query: The query to retrieve the closest document features for.
17081708
top_k: The number of closest document features to retrieve.
17091709
"""

sdk/python/feast/infra/online_stores/contrib/postgres.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def retrieve_online_documents(
267267
requested_feature: str,
268268
embedding: List[float],
269269
top_k: int,
270-
) -> List[Tuple[Optional[datetime], Optional[Dict[str, ValueProto]]]]:
270+
) -> List[Tuple[Optional[datetime], Optional[ValueProto]]]:
271271
"""
272272
273273
Args:

sdk/python/feast/infra/passthrough_provider.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def __init__(self, config: RepoConfig):
4747
self.repo_config = config
4848
self._offline_store = None
4949
self._online_store = None
50-
self._document_store = None
5150
self._batch_engine: Optional[BatchMaterializationEngine] = None
5251

5352
@property

sdk/python/tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,15 @@ def fake_ingest_data():
405405
"created": [pd.Timestamp(datetime.utcnow()).round("ms")],
406406
}
407407
return pd.DataFrame(data)
408+
409+
410+
@pytest.fixture
411+
def fake_ingest_document_data():
412+
"""Fake document data to ingest into the feature store"""
413+
data = {
414+
"driver_id": [1],
415+
"doc": [4, 5],
416+
"event_timestamp": [pd.Timestamp(datetime.utcnow()).round("ms")],
417+
"created": [pd.Timestamp(datetime.utcnow()).round("ms")],
418+
}
419+
return pd.DataFrame(data)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from typing import Dict
2+
3+
from testcontainers.postgres import PostgresContainer
4+
5+
from tests.integration.feature_repos.universal.online_store_creator import (
6+
OnlineStoreCreator,
7+
)
8+
9+
10+
class PostgresOnlieStoreCreator(OnlineStoreCreator):
11+
def __init__(self, project_name: str, **kwargs):
12+
super().__init__(project_name)
13+
self.container = (
14+
PostgresContainer("postgres:latest", platform="linux/amd64")
15+
.with_exposed_ports(5432)
16+
.with_env("POSTGRES_USER", "root")
17+
.with_env("POSTGRES_PASSWORD", "test")
18+
.with_env("POSTGRES_DB", "test")
19+
)
20+
21+
def create_online_store(self) -> Dict[str, str]:
22+
self.container.start()
23+
exposed_port = self.container.get_exposed_port(5432)
24+
return {
25+
"type": "postgres",
26+
"user": "root",
27+
"password": "test",
28+
"database": "test",
29+
"port": exposed_port,
30+
}
31+
32+
def teardown(self):
33+
self.container.stop()

sdk/python/tests/integration/online_store/test_universal_online.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,3 +785,28 @@ def assert_feature_service_entity_mapping_correctness(
785785
entity_rows=entity_rows,
786786
full_feature_names=full_feature_names,
787787
)
788+
789+
790+
@pytest.mark.integration
791+
@pytest.mark.universal_online_stores(only=["postgres"])
792+
def test_retrieve_online_documents(
793+
environment, universal_data_sources, fake_ingest_document_data
794+
):
795+
fs = environment.feature_store
796+
entities, datasets, data_sources = universal_data_sources
797+
driver_hourly_stats = create_driver_hourly_stats_feature_view(data_sources.driver)
798+
driver_entity = driver()
799+
800+
# Register Feature View and Entity
801+
fs.apply([driver_hourly_stats, driver_entity])
802+
803+
# directly ingest data into the Online Store
804+
fs.write_to_online_store("document_fv", fake_ingest_document_data)
805+
806+
# retrieve the online documents
807+
documents = fs.retrieve_online_documents(
808+
feature="document_fv:doc",
809+
query="[1, 2]",
810+
top_k=5
811+
)
812+
assert len(documents) == 2

0 commit comments

Comments
 (0)