-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kevin Zhang <[email protected]>
- Loading branch information
Showing
2 changed files
with
143 additions
and
143 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,72 +77,72 @@ def simple_sfv(df): | |
assert features["dummy_field"] == [None] | ||
|
||
|
||
# @pytest.mark.integration | ||
# def test_stream_feature_view_udf(simple_dataset_1) -> None: | ||
# """ | ||
# Test apply of StreamFeatureView udfs are serialized correctly and usable. | ||
# """ | ||
# runner = CliRunner() | ||
# with runner.local_repo( | ||
# get_example_repo("example_feature_repo_1.py"), "bigquery" | ||
# ) as fs, prep_file_source( | ||
# df=simple_dataset_1, timestamp_field="ts_1" | ||
# ) as file_source: | ||
# entity = Entity(name="driver_entity", join_keys=["test_key"]) | ||
|
||
# stream_source = KafkaSource( | ||
# name="kafka", | ||
# timestamp_field="event_timestamp", | ||
# kafka_bootstrap_servers="", | ||
# message_format=AvroFormat(""), | ||
# topic="topic", | ||
# batch_source=file_source, | ||
# watermark_delay_threshold=timedelta(days=1), | ||
# ) | ||
|
||
# @stream_feature_view( | ||
# entities=[entity], | ||
# ttl=timedelta(days=30), | ||
# owner="[email protected]", | ||
# online=True, | ||
# schema=[Field(name="dummy_field", dtype=Float32)], | ||
# description="desc", | ||
# aggregations=[ | ||
# Aggregation( | ||
# column="dummy_field", function="max", time_window=timedelta(days=1), | ||
# ), | ||
# Aggregation( | ||
# column="dummy_field2", | ||
# function="count", | ||
# time_window=timedelta(days=24), | ||
# ), | ||
# ], | ||
# timestamp_field="event_timestamp", | ||
# mode="spark", | ||
# source=stream_source, | ||
# tags={}, | ||
# ) | ||
# def pandas_view(pandas_df): | ||
# import pandas as pd | ||
|
||
# assert type(pandas_df) == pd.DataFrame | ||
# df = pandas_df.transform(lambda x: x + 10, axis=1) | ||
# df.insert(2, "C", [20.2, 230.0, 34.0], True) | ||
# return df | ||
|
||
# import pandas as pd | ||
|
||
# fs.apply([entity, pandas_view]) | ||
|
||
# stream_feature_views = fs.list_stream_feature_views() | ||
# assert len(stream_feature_views) == 1 | ||
# assert stream_feature_views[0] == pandas_view | ||
|
||
# sfv = stream_feature_views[0] | ||
|
||
# df = pd.DataFrame({"A": [1, 2, 3], "B": [10, 20, 30]}) | ||
# new_df = sfv.udf(df) | ||
# expected_df = pd.DataFrame( | ||
# {"A": [11, 12, 13], "B": [20, 30, 40], "C": [20.2, 230.0, 34.0]} | ||
# ) | ||
# assert new_df.equals(expected_df) | ||
@pytest.mark.integration | ||
def test_stream_feature_view_udf(simple_dataset_1) -> None: | ||
""" | ||
Test apply of StreamFeatureView udfs are serialized correctly and usable. | ||
""" | ||
runner = CliRunner() | ||
with runner.local_repo( | ||
get_example_repo("example_feature_repo_1.py"), "bigquery" | ||
) as fs, prep_file_source( | ||
df=simple_dataset_1, timestamp_field="ts_1" | ||
) as file_source: | ||
entity = Entity(name="driver_entity", join_keys=["test_key"]) | ||
|
||
stream_source = KafkaSource( | ||
name="kafka", | ||
timestamp_field="event_timestamp", | ||
kafka_bootstrap_servers="", | ||
message_format=AvroFormat(""), | ||
topic="topic", | ||
batch_source=file_source, | ||
watermark_delay_threshold=timedelta(days=1), | ||
) | ||
|
||
@stream_feature_view( | ||
entities=[entity], | ||
ttl=timedelta(days=30), | ||
owner="[email protected]", | ||
online=True, | ||
schema=[Field(name="dummy_field", dtype=Float32)], | ||
description="desc", | ||
aggregations=[ | ||
Aggregation( | ||
column="dummy_field", function="max", time_window=timedelta(days=1), | ||
), | ||
Aggregation( | ||
column="dummy_field2", | ||
function="count", | ||
time_window=timedelta(days=24), | ||
), | ||
], | ||
timestamp_field="event_timestamp", | ||
mode="spark", | ||
source=stream_source, | ||
tags={}, | ||
) | ||
def pandas_view(pandas_df): | ||
import pandas as pd | ||
|
||
assert type(pandas_df) == pd.DataFrame | ||
df = pandas_df.transform(lambda x: x + 10, axis=1) | ||
df.insert(2, "C", [20.2, 230.0, 34.0], True) | ||
return df | ||
|
||
import pandas as pd | ||
|
||
fs.apply([entity, pandas_view]) | ||
|
||
stream_feature_views = fs.list_stream_feature_views() | ||
assert len(stream_feature_views) == 1 | ||
assert stream_feature_views[0] == pandas_view | ||
|
||
sfv = stream_feature_views[0] | ||
|
||
df = pd.DataFrame({"A": [1, 2, 3], "B": [10, 20, 30]}) | ||
new_df = sfv.udf(df) | ||
expected_df = pd.DataFrame( | ||
{"A": [11, 12, 13], "B": [20, 30, 40], "C": [20.2, 230.0, 34.0]} | ||
) | ||
assert new_df.equals(expected_df) |