forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Supports nested struct columns as features, timestamp fields (#153
) * feat: Supports nested struct columns as features, timestamp fields * fix: Added field mapping support for spark streaming * feat: Add support for field mapping in SparkOfflineStore * feat: Add timing for batch write operations in SparkKafkaProcessor * feat: Enhance SparkKafkaProcessor logging and add unit tests for SparkOfflineStore * fix: Remove unnecessary f-string usage in SparkOfflineStore tests * fix: Renamed integration test file name to avoid conflicts * refactor: Remove unused ingest_df method and clean up imports in ExpediaProvider --------- Co-authored-by: Bhargav Dodla <[email protected]>
- Loading branch information
1 parent
d56d202
commit cf0f2f2
Showing
7 changed files
with
216 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
129 changes: 129 additions & 0 deletions
129
sdk/python/tests/unit/infra/offline_stores/contrib/spark_offline_store/test_spark.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
from datetime import datetime | ||
from unittest.mock import MagicMock, patch | ||
|
||
from feast.infra.offline_stores.contrib.spark_offline_store.spark import ( | ||
SparkOfflineStore, | ||
SparkOfflineStoreConfig, | ||
) | ||
from feast.infra.offline_stores.contrib.spark_offline_store.spark_source import ( | ||
SparkSource, | ||
) | ||
from feast.infra.offline_stores.offline_store import RetrievalJob | ||
from feast.repo_config import RepoConfig | ||
|
||
|
||
@patch( | ||
"feast.infra.offline_stores.contrib.spark_offline_store.spark.get_spark_session_or_start_new_with_repoconfig" | ||
) | ||
def test_pull_latest_from_table_with_nested_timestamp_or_query(mock_get_spark_session): | ||
mock_spark_session = MagicMock() | ||
mock_get_spark_session.return_value = mock_spark_session | ||
|
||
test_repo_config = RepoConfig( | ||
project="test_project", | ||
registry="test_registry", | ||
provider="local", | ||
offline_store=SparkOfflineStoreConfig(type="spark"), | ||
) | ||
|
||
test_data_source = SparkSource( | ||
name="test_nested_batch_source", | ||
description="test_nested_batch_source", | ||
table="offline_store_database_name.offline_store_table_name", | ||
timestamp_field="nested_timestamp", | ||
field_mapping={ | ||
"event_header.event_published_datetime_utc": "nested_timestamp", | ||
}, | ||
) | ||
|
||
# Define the parameters for the method | ||
join_key_columns = ["key1", "key2"] | ||
feature_name_columns = ["feature1", "feature2"] | ||
timestamp_field = "event_header.event_published_datetime_utc" | ||
created_timestamp_column = "created_timestamp" | ||
start_date = datetime(2021, 1, 1) | ||
end_date = datetime(2021, 1, 2) | ||
|
||
# Call the method | ||
retrieval_job = SparkOfflineStore.pull_latest_from_table_or_query( | ||
config=test_repo_config, | ||
data_source=test_data_source, | ||
join_key_columns=join_key_columns, | ||
feature_name_columns=feature_name_columns, | ||
timestamp_field=timestamp_field, | ||
created_timestamp_column=created_timestamp_column, | ||
start_date=start_date, | ||
end_date=end_date, | ||
) | ||
|
||
expected_query = """SELECT | ||
key1, key2, feature1, feature2, nested_timestamp, created_timestamp | ||
FROM ( | ||
SELECT key1, key2, feature1, feature2, event_header.event_published_datetime_utc AS nested_timestamp, created_timestamp, | ||
ROW_NUMBER() OVER(PARTITION BY key1, key2 ORDER BY event_header.event_published_datetime_utc DESC, created_timestamp DESC) AS feast_row_ | ||
FROM `offline_store_database_name`.`offline_store_table_name` t1 | ||
WHERE event_header.event_published_datetime_utc BETWEEN TIMESTAMP('2021-01-01 00:00:00.000000') AND TIMESTAMP('2021-01-02 00:00:00.000000') | ||
) t2 | ||
WHERE feast_row_ = 1""" # noqa: W293 | ||
|
||
assert isinstance(retrieval_job, RetrievalJob) | ||
assert retrieval_job.query.strip() == expected_query.strip() | ||
|
||
|
||
@patch( | ||
"feast.infra.offline_stores.contrib.spark_offline_store.spark.get_spark_session_or_start_new_with_repoconfig" | ||
) | ||
def test_pull_latest_from_table_without_nested_timestamp_or_query( | ||
mock_get_spark_session, | ||
): | ||
mock_spark_session = MagicMock() | ||
mock_get_spark_session.return_value = mock_spark_session | ||
|
||
test_repo_config = RepoConfig( | ||
project="test_project", | ||
registry="test_registry", | ||
provider="local", | ||
offline_store=SparkOfflineStoreConfig(type="spark"), | ||
) | ||
|
||
test_data_source = SparkSource( | ||
name="test_batch_source", | ||
description="test_nested_batch_source", | ||
table="offline_store_database_name.offline_store_table_name", | ||
timestamp_field="event_published_datetime_utc", | ||
) | ||
|
||
# Define the parameters for the method | ||
join_key_columns = ["key1", "key2"] | ||
feature_name_columns = ["feature1", "feature2"] | ||
timestamp_field = "event_published_datetime_utc" | ||
created_timestamp_column = "created_timestamp" | ||
start_date = datetime(2021, 1, 1) | ||
end_date = datetime(2021, 1, 2) | ||
|
||
# Call the method | ||
retrieval_job = SparkOfflineStore.pull_latest_from_table_or_query( | ||
config=test_repo_config, | ||
data_source=test_data_source, | ||
join_key_columns=join_key_columns, | ||
feature_name_columns=feature_name_columns, | ||
timestamp_field=timestamp_field, | ||
created_timestamp_column=created_timestamp_column, | ||
start_date=start_date, | ||
end_date=end_date, | ||
) | ||
|
||
expected_query = """SELECT | ||
key1, key2, feature1, feature2, event_published_datetime_utc, created_timestamp | ||
FROM ( | ||
SELECT key1, key2, feature1, feature2, event_published_datetime_utc, created_timestamp, | ||
ROW_NUMBER() OVER(PARTITION BY key1, key2 ORDER BY event_published_datetime_utc DESC, created_timestamp DESC) AS feast_row_ | ||
FROM `offline_store_database_name`.`offline_store_table_name` t1 | ||
WHERE event_published_datetime_utc BETWEEN TIMESTAMP('2021-01-01 00:00:00.000000') AND TIMESTAMP('2021-01-02 00:00:00.000000') | ||
) t2 | ||
WHERE feast_row_ = 1""" # noqa: W293 | ||
|
||
assert isinstance(retrieval_job, RetrievalJob) | ||
assert retrieval_job.query.strip() == expected_query.strip() |