MCPcopy
hub / github.com/feast-dev/feast / run_demo

Function run_demo

sdk/python/feast/templates/gcp/feature_repo/test_workflow.py:11–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9
10
11def run_demo():
12 store = FeatureStore(repo_path=".")
13 print("\n--- Run feast apply to setup feature store on GCP ---")
14 subprocess.run(["feast", "apply"])
15
16 print("\n--- Historical features for training ---")
17 fetch_historical_features_entity_df(store, for_batch_scoring=False)
18
19 print("\n--- Historical features for batch scoring ---")
20 fetch_historical_features_entity_df(store, for_batch_scoring=True)
21
22 print(
23 "\n--- Historical features for training (all entities in a window using SQL entity dataframe) ---"
24 )
25 fetch_historical_features_entity_sql(store, for_batch_scoring=False)
26
27 print(
28 "\n--- Historical features for batch scoring (all entities in a window using SQL entity dataframe) ---"
29 )
30 fetch_historical_features_entity_sql(store, for_batch_scoring=True)
31
32 print("\n--- Load features into online store ---")
33 store.materialize_incremental(end_date=datetime.now())
34
35 print("\n--- Online features ---")
36 fetch_online_features(store)
37
38 print("\n--- Online features retrieved (instead) through a feature service---")
39 fetch_online_features(store, source="feature_service")
40
41 print(
42 "\n--- Online features retrieved (using feature service v3, which uses a feature view with a push source---"
43 )
44 fetch_online_features(store, source="push")
45
46 print("\n--- Simulate a stream event ingestion of the hourly stats df ---")
47 event_df = pd.DataFrame.from_dict(
48 {
49 "driver_id": [1001],
50 "event_timestamp": [
51 datetime.now(),
52 ],
53 "created": [
54 datetime.now(),
55 ],
56 "conv_rate": [1.0],
57 "acc_rate": [1.0 + random.random()],
58 "avg_daily_trips": [int(1000 * random.random())],
59 }
60 )
61 print(event_df)
62 # You can normally push to offline too, but in this case, you don't have access (since it's a Feast owned
63 # BigQuery source)
64 store.push("driver_stats_push_source", event_df, to=PushMode.ONLINE)
65
66 print("\n--- Online features again with updated values from a stream push---")
67 fetch_online_features(store, source="push")
68

Callers 1

test_workflow.pyFile · 0.70

Calls 8

pushMethod · 0.95
FeatureStoreClass · 0.90
fetch_online_featuresFunction · 0.70
runMethod · 0.45
from_dictMethod · 0.45

Tested by

no test coverage detected