diff --git a/sdk/python/tests/unit/infra/online_store/test_dynamodb_online_store.py b/sdk/python/tests/unit/infra/online_store/test_dynamodb_online_store.py new file mode 100644 index 0000000000..0f42230ef5 --- /dev/null +++ b/sdk/python/tests/unit/infra/online_store/test_dynamodb_online_store.py @@ -0,0 +1,57 @@ +from dataclasses import dataclass + +import pytest +from moto import mock_dynamodb2 + +from feast.infra.offline_stores.file import FileOfflineStoreConfig +from feast.infra.online_stores.dynamodb import ( + DynamoDBOnlineStore, + DynamoDBOnlineStoreConfig, +) +from feast.repo_config import RepoConfig +from tests.utils.online_store_utils import ( + _create_n_customer_test_samples, + _create_test_table, + _insert_data_test_table, +) + +REGISTRY = "s3://test_registry/registry.db" +PROJECT = "test_aws" +PROVIDER = "aws" +TABLE_NAME = "dynamodb_online_store" +REGION = "us-west-2" + + +@dataclass +class MockFeatureView: + name: str + + +@pytest.fixture +def repo_config(): + return RepoConfig( + registry=REGISTRY, + project=PROJECT, + provider=PROVIDER, + online_store=DynamoDBOnlineStoreConfig(region=REGION), + offline_store=FileOfflineStoreConfig(), + ) + + +@mock_dynamodb2 +@pytest.mark.parametrize("n_samples", [5, 50, 100]) +def test_online_read(repo_config, n_samples): + """Test DynamoDBOnlineStore online_read method.""" + _create_test_table(PROJECT, f"{TABLE_NAME}_{n_samples}", REGION) + data = _create_n_customer_test_samples(n=n_samples) + _insert_data_test_table(data, PROJECT, f"{TABLE_NAME}_{n_samples}", REGION) + + entity_keys, features = zip(*data) + dynamodb_store = DynamoDBOnlineStore() + returned_items = dynamodb_store.online_read( + config=repo_config, + table=MockFeatureView(name=f"{TABLE_NAME}_{n_samples}"), + entity_keys=entity_keys, + ) + assert len(returned_items) == len(data) + assert [item[1] for item in returned_items] == list(features) diff --git a/sdk/python/tests/unit/infra/test_provider.py b/sdk/python/tests/unit/infra/test_provider.py new file mode 100644 index 0000000000..08337ea74e --- /dev/null +++ b/sdk/python/tests/unit/infra/test_provider.py @@ -0,0 +1,47 @@ +# Copyright 2020 The Feast Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from datetime import timedelta + +from feast import BigQuerySource +from feast.entity import Entity +from feast.feature import Feature +from feast.feature_view import FeatureView +from feast.infra.provider import _get_column_names +from feast.value_type import ValueType + + +def test_get_column_names_preserves_feature_ordering(): + entity = Entity("my-entity", description="My entity", value_type=ValueType.STRING) + fv = FeatureView( + name="my-fv", + entities=["my-entity"], + ttl=timedelta(days=1), + batch_source=BigQuerySource(table="non-existent-mock"), + features=[ + Feature(name="a", dtype=ValueType.STRING), + Feature(name="b", dtype=ValueType.STRING), + Feature(name="c", dtype=ValueType.STRING), + Feature(name="d", dtype=ValueType.STRING), + Feature(name="e", dtype=ValueType.STRING), + Feature(name="f", dtype=ValueType.STRING), + Feature(name="g", dtype=ValueType.STRING), + Feature(name="h", dtype=ValueType.STRING), + Feature(name="i", dtype=ValueType.STRING), + Feature(name="j", dtype=ValueType.STRING), + ], + ) + + _, feature_list, _, _ = _get_column_names(fv, [entity]) + assert feature_list == ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]