Skip to content

Commit 44d53fd

Browse files
chore: Add request source and ODFV to version 0.19 test repo (feast-dev#2691)
* Add request source and ODFV to version 0.19 test repo Signed-off-by: Felix Wang <wangfelix98@gmail.com> * Format Signed-off-by: Felix Wang <wangfelix98@gmail.com> * Enable ODFVs for unit tests Signed-off-by: Felix Wang <wangfelix98@gmail.com> * Switch to RequestDataSource Signed-off-by: Felix Wang <wangfelix98@gmail.com>
1 parent c8b11b3 commit 44d53fd

File tree

5 files changed

+80
-12
lines changed

5 files changed

+80
-12
lines changed

.github/workflows/unit_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
run: make install-python-ci-dependencies
5656
- name: Test Python
5757
env:
58+
IS_TEST: "True"
5859
SNOWFLAKE_CI_DEPLOYMENT: ${{ secrets.SNOWFLAKE_CI_DEPLOYMENT }}
5960
SNOWFLAKE_CI_USER: ${{ secrets.SNOWFLAKE_CI_USER }}
6061
SNOWFLAKE_CI_PASSWORD: ${{ secrets.SNOWFLAKE_CI_PASSWORD }}

sdk/python/feast/data_source.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from feast.field import Field
2525
from feast.protos.feast.core.DataSource_pb2 import DataSource as DataSourceProto
2626
from feast.repo_config import RepoConfig, get_data_source_class_from_type
27-
from feast.types import VALUE_TYPES_TO_FEAST_TYPES
27+
from feast.types import from_value_type
2828
from feast.value_type import ValueType
2929

3030

@@ -557,12 +557,10 @@ def __init__(
557557
"Please use List[Field] instead for the schema",
558558
DeprecationWarning,
559559
)
560-
schemaList = []
561-
for key, valueType in _schema.items():
562-
schemaList.append(
563-
Field(name=key, dtype=VALUE_TYPES_TO_FEAST_TYPES[valueType])
564-
)
565-
self.schema = schemaList
560+
schema_list = []
561+
for key, value_type in _schema.items():
562+
schema_list.append(Field(name=key, dtype=from_value_type(value_type)))
563+
self.schema = schema_list
566564
elif isinstance(_schema, List):
567565
self.schema = _schema
568566
else:
@@ -641,9 +639,7 @@ def to_proto(self) -> DataSourceProto:
641639
if isinstance(self.schema, Dict):
642640
for key, value in self.schema.items():
643641
schema_pb.append(
644-
Field(
645-
name=key, dtype=VALUE_TYPES_TO_FEAST_TYPES[value.value]
646-
).to_proto()
642+
Field(name=key, dtype=from_value_type(value.value)).to_proto()
647643
)
648644
else:
649645
for field in self.schema:

sdk/python/feast/on_demand_feature_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ def feature_view_to_batch_feature_view(fv: FeatureView) -> BatchFeatureView:
674674
online=fv.online,
675675
owner=fv.owner,
676676
schema=fv.schema,
677-
source=fv.source,
677+
source=fv.batch_source,
678678
)
679679

680680
bfv.features = copy.copy(fv.features)

sdk/python/tests/example_repos/example_feature_repo_version_0_19.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from datetime import timedelta
22

3+
import pandas as pd
4+
35
from feast import Entity, Feature, FeatureView, FileSource, ValueType
6+
from feast.data_source import RequestDataSource
7+
from feast.on_demand_feature_view import on_demand_feature_view
48

59
driver_hourly_stats = FileSource(
610
path="%PARQUET_PATH%", # placeholder to be replaced by the test
@@ -50,3 +54,27 @@
5054
batch_source=global_daily_stats, # Changed to `source` in 0.20
5155
tags={},
5256
)
57+
58+
59+
request_source = RequestDataSource(
60+
name="conv_rate_input", schema={"val_to_add": ValueType.INT64},
61+
)
62+
63+
64+
@on_demand_feature_view(
65+
inputs={
66+
"conv_rate_input": request_source,
67+
"driver_hourly_stats": driver_hourly_stats_view,
68+
},
69+
features=[
70+
Feature(name="conv_rate_plus_100", dtype=ValueType.DOUBLE),
71+
Feature(name="conv_rate_plus_val_to_add", dtype=ValueType.DOUBLE),
72+
],
73+
)
74+
def conv_rate_plus_100(features_df: pd.DataFrame) -> pd.DataFrame:
75+
df = pd.DataFrame()
76+
df["conv_rate_plus_100"] = features_df["conv_rate"] + 100
77+
df["conv_rate_plus_val_to_add"] = (
78+
features_df["conv_rate"] + features_df["val_to_add"]
79+
)
80+
return df

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _assert_online_features(
4141
full_feature_names=True,
4242
)
4343

44-
# Float features should still be floats from the online store...
44+
# Float features should still be floats.
4545
assert (
4646
response.proto.results[
4747
list(response.proto.metadata.feature_names.val).index(
@@ -67,6 +67,49 @@ def _assert_online_features(
6767
assert "global_daily_stats__num_rides" in result
6868
assert "global_daily_stats__avg_ride_length" in result
6969

70+
# Test the ODFV if it exists.
71+
odfvs = store.list_on_demand_feature_views()
72+
if odfvs and odfvs[0].name == "conv_rate_plus_100":
73+
response = store.get_online_features(
74+
features=[
75+
"conv_rate_plus_100:conv_rate_plus_100",
76+
"conv_rate_plus_100:conv_rate_plus_val_to_add",
77+
],
78+
entity_rows=[{"driver_id": 1001, "val_to_add": 100}],
79+
full_feature_names=True,
80+
)
81+
82+
# Check that float64 feature is stored correctly in proto format.
83+
assert (
84+
response.proto.results[
85+
list(response.proto.metadata.feature_names.val).index(
86+
"conv_rate_plus_100__conv_rate_plus_100"
87+
)
88+
]
89+
.values[0]
90+
.double_val
91+
> 0
92+
)
93+
94+
result = response.to_dict()
95+
assert len(result) == 3
96+
assert "conv_rate_plus_100__conv_rate_plus_100" in result
97+
assert "conv_rate_plus_100__conv_rate_plus_val_to_add" in result
98+
assert (
99+
abs(
100+
result["conv_rate_plus_100__conv_rate_plus_100"][0]
101+
- (_get_last_feature_row(driver_df, 1001, max_date)["conv_rate"] + 100)
102+
)
103+
< 0.01
104+
)
105+
assert (
106+
abs(
107+
result["conv_rate_plus_100__conv_rate_plus_val_to_add"][0]
108+
- (_get_last_feature_row(driver_df, 1001, max_date)["conv_rate"] + 100)
109+
)
110+
< 0.01
111+
)
112+
70113

71114
def _test_materialize_and_online_retrieval(
72115
runner: CliRunner,

0 commit comments

Comments
 (0)