Skip to content

Commit 1a61567

Browse files
committed
Expand online retrieval test to also retrieve pushable_location_stats SFV
Signed-off-by: Felix Wang <wangfelix98@gmail.com>
1 parent 39e4148 commit 1a61567

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def test_online_retrieval(
490490
)
491491

492492
entity_sample = datasets.orders_df.sample(10)[
493-
["customer_id", "driver_id", "order_id", "event_timestamp"]
493+
["customer_id", "driver_id", "order_id", "origin_id", "event_timestamp"]
494494
]
495495
orders_df = datasets.orders_df[
496496
(
@@ -509,6 +509,8 @@ def test_online_retrieval(
509509
datasets.customer_df["customer_id"].isin(sample_customers)
510510
]
511511

512+
sample_origins = entity_sample["origin_id"]
513+
512514
location_pairs = np.array(list(itertools.permutations(entities.location_vals, 2)))
513515
sample_location_pairs = location_pairs[
514516
np.random.choice(len(location_pairs), 10)
@@ -521,10 +523,12 @@ def test_online_retrieval(
521523
]
522524

523525
global_df = datasets.global_df
526+
location_df = datasets.location_df
524527

528+
# Rename origin -> location for the purposes of selecting
525529
entity_rows = [
526-
{"driver_id": d, "customer_id": c, "val_to_add": 50}
527-
for (d, c) in zip(sample_drivers, sample_customers)
530+
{"driver_id": d, "customer_id": c, "location_id": o, "val_to_add": 50}
531+
for (d, c, o) in zip(sample_drivers, sample_customers, sample_origins)
528532
]
529533

530534
feature_refs = [
@@ -538,6 +542,7 @@ def test_online_retrieval(
538542
"order:order_is_success",
539543
"global_stats:num_rides",
540544
"global_stats:avg_ride_length",
545+
"pushable_location_stats:temperature",
541546
]
542547
unprefixed_feature_refs = [f.rsplit(":", 1)[-1] for f in feature_refs if ":" in f]
543548
# Remove the on demand feature view output features, since they're not present in the source dataframe
@@ -568,7 +573,7 @@ def test_online_retrieval(
568573
expected_keys = set(
569574
f.replace(":", "__") if full_feature_names else f.split(":")[-1]
570575
for f in feature_refs
571-
) | {"customer_id", "driver_id"}
576+
) | {"customer_id", "driver_id", "location_id"}
572577
assert (
573578
keys == expected_keys
574579
), f"Response keys are different from expected: {keys - expected_keys} (extra) and {expected_keys - keys} (missing)"
@@ -581,6 +586,7 @@ def test_online_retrieval(
581586
orders_df=orders_df,
582587
global_df=global_df,
583588
entity_row=entity_row,
589+
location_df=location_df,
584590
)
585591

586592
assert df_features["customer_id"] == online_features_dict["customer_id"][i]
@@ -619,7 +625,9 @@ def test_online_retrieval(
619625
environment=environment,
620626
endpoint=feature_server_endpoint,
621627
features=feature_refs,
622-
entity_rows=[{"driver_id": 0, "customer_id": 0, "val_to_add": 100}],
628+
entity_rows=[
629+
{"driver_id": 0, "customer_id": 0, "location_id": 0, "val_to_add": 100}
630+
],
623631
full_feature_names=full_feature_names,
624632
)
625633
assert missing_responses_dict is not None
@@ -639,7 +647,7 @@ def test_online_retrieval(
639647
environment=environment,
640648
endpoint=feature_server_endpoint,
641649
features=feature_refs,
642-
entity_rows=[{"driver_id": 0, "customer_id": 0}],
650+
entity_rows=[{"driver_id": 0, "customer_id": 0, "location_id": 0}],
643651
full_feature_names=full_feature_names,
644652
)
645653

@@ -653,6 +661,7 @@ def test_online_retrieval(
653661
customers_df,
654662
orders_df,
655663
global_df,
664+
location_df,
656665
)
657666

658667
entity_rows = [
@@ -780,14 +789,19 @@ def get_latest_feature_values_from_dataframes(
780789
customer_df,
781790
orders_df,
782791
entity_row,
792+
location_df,
783793
global_df=None,
784794
origin_df=None,
785795
destination_df=None,
786796
):
797+
# TODO: retrieve temperature feature
787798
latest_driver_row = get_latest_row(entity_row, driver_df, "driver_id", "driver_id")
788799
latest_customer_row = get_latest_row(
789800
entity_row, customer_df, "customer_id", "customer_id"
790801
)
802+
latest_location_row = get_latest_row(
803+
entity_row, location_df, "location_id", "location_id"
804+
)
791805

792806
# Since the event timestamp columns may contain timestamps of different timezones,
793807
# we must first convert the timestamps to UTC before we can compare them.
@@ -807,7 +821,7 @@ def get_latest_feature_values_from_dataframes(
807821
global_df["event_timestamp"].idxmax()
808822
].to_dict()
809823
if origin_df is not None:
810-
latest_location_row = get_latest_feature_values_for_location_df(
824+
latest_location_aliased_row = get_latest_feature_values_for_location_df(
811825
entity_row, origin_df, destination_df
812826
)
813827

@@ -820,6 +834,7 @@ def get_latest_feature_values_from_dataframes(
820834
**latest_driver_row,
821835
**latest_orders_row,
822836
**latest_global_row,
837+
**latest_location_row,
823838
**request_data_features,
824839
}
825840
if origin_df is not None:
@@ -830,12 +845,14 @@ def get_latest_feature_values_from_dataframes(
830845
**latest_driver_row,
831846
**latest_orders_row,
832847
**latest_location_row,
848+
**latest_location_aliased_row,
833849
**request_data_features,
834850
}
835851
return {
836852
**latest_customer_row,
837853
**latest_driver_row,
838854
**latest_orders_row,
855+
**latest_location_row,
839856
**request_data_features,
840857
}
841858

@@ -869,6 +886,7 @@ def assert_feature_service_correctness(
869886
customers_df,
870887
orders_df,
871888
global_df,
889+
location_df,
872890
):
873891
feature_service_online_features_dict = get_online_features_dict(
874892
environment=environment,
@@ -888,6 +906,7 @@ def assert_feature_service_correctness(
888906
assert set(feature_service_keys) == set(expected_feature_refs) | {
889907
"customer_id",
890908
"driver_id",
909+
"location_id",
891910
}
892911

893912
tc = unittest.TestCase()
@@ -898,6 +917,7 @@ def assert_feature_service_correctness(
898917
orders_df=orders_df,
899918
global_df=global_df,
900919
entity_row=entity_row,
920+
location_df=location_df,
901921
)
902922
tc.assertAlmostEqual(
903923
feature_service_online_features_dict[

0 commit comments

Comments
 (0)