| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0ee3a1e commit ecad170
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,13 +61,15 @@ class WriteToFeatureStoreRequest(BaseModel): | |||
| 61 | 61 | feature_view_name: str | |
| 62 | 62 | df: dict | |
| 63 | 63 | allow_registry_cache: bool = True | |
| 64 | + transform_on_write: bool = True | ||
| 64 | 65 | ||
| 65 | 66 | ||
| 66 | 67 | class PushFeaturesRequest(BaseModel): | |
| 67 | 68 | push_source_name: str | |
| 68 | 69 | df: dict | |
| 69 | 70 | allow_registry_cache: bool = True | |
| 70 | 71 | to: str = "online" | |
| 72 | + transform_on_write: bool = True | ||
| 71 | 73 | ||
| 72 | 74 | ||
| 73 | 75 | class MaterializeRequest(BaseModel): | |
@@ -302,6 +304,7 @@ async def push(request: PushFeaturesRequest) -> None: | |||
| 302 | 304 | df=df, | |
| 303 | 305 | allow_registry_cache=request.allow_registry_cache, | |
| 304 | 306 | to=to, | |
| 307 | + transform_on_write=request.transform_on_write, | ||
| 305 | 308 | ) | |
| 306 | 309 | ||
| 307 | 310 | should_push_async = ( | |
@@ -336,6 +339,7 @@ def write_to_online_store(request: WriteToFeatureStoreRequest) -> None: | |||
| 336 | 339 | feature_view_name=feature_view_name, | |
| 337 | 340 | df=df, | |
| 338 | 341 | allow_registry_cache=allow_registry_cache, | |
| 342 | + transform_on_write=request.transform_on_write, | ||
| 339 | 343 | ) | |
| 340 | 344 | ||
| 341 | 345 | @app.get("/health") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1464,6 +1464,7 @@ def push( | |||
| 1464 | 1464 | df: pd.DataFrame, | |
| 1465 | 1465 | allow_registry_cache: bool = True, | |
| 1466 | 1466 | to: PushMode = PushMode.ONLINE, | |
| 1467 | + transform_on_write: bool = True, | ||
| 1467 | 1468 | ): | |
| 1468 | 1469 | """ | |
| 1469 | 1470 | Push features to a push source. This updates all the feature views that have the push source as stream source. | |
@@ -1473,13 +1474,17 @@ def push( | |||
| 1473 | 1474 | df: The data being pushed. | |
| 1474 | 1475 | allow_registry_cache: Whether to allow cached versions of the registry. | |
| 1475 | 1476 | to: Whether to push to online or offline store. Defaults to online store only. | |
| 1477 | + transform_on_write: Whether to transform the data before pushing. | ||
| 1476 | 1478 | """ | |
| 1477 | 1479 | for fv in self._fvs_for_push_source_or_raise( | |
| 1478 | 1480 | push_source_name, allow_registry_cache | |
| 1479 | 1481 | ): | |
| 1480 | 1482 | if to == PushMode.ONLINE or to == PushMode.ONLINE_AND_OFFLINE: | |
| 1481 | 1483 | self.write_to_online_store( | |
| 1482 | - fv.name, df, allow_registry_cache=allow_registry_cache | ||
| 1484 | + fv.name, | ||
| 1485 | + df, | ||
| 1486 | + allow_registry_cache=allow_registry_cache, | ||
| 1487 | + transform_on_write=transform_on_write, | ||
| 1483 | 1488 | ) | |
| 1484 | 1489 | if to == PushMode.OFFLINE or to == PushMode.ONLINE_AND_OFFLINE: | |
| 1485 | 1490 | self.write_to_offline_store( | |
@@ -1521,6 +1526,7 @@ def _get_feature_view_and_df_for_online_write( | |||
| 1521 | 1526 | df: Optional[pd.DataFrame] = None, | |
| 1522 | 1527 | inputs: Optional[Union[Dict[str, List[Any]], pd.DataFrame]] = None, | |
| 1523 | 1528 | allow_registry_cache: bool = True, | |
| 1529 | + transform_on_write: bool = True, | ||
| 1524 | 1530 | ): | |
| 1525 | 1531 | feature_view_dict = { | |
| 1526 | 1532 | fv_proto.name: fv_proto | |
@@ -1553,6 +1559,7 @@ def _get_feature_view_and_df_for_online_write( | |||
| 1553 | 1559 | if ( | |
| 1554 | 1560 | isinstance(feature_view, OnDemandFeatureView) | |
| 1555 | 1561 | and feature_view.write_to_online_store | |
| 1562 | + and transform_on_write | ||
| 1556 | 1563 | ): | |
| 1557 | 1564 | if ( | |
| 1558 | 1565 | feature_view.mode == "python" | |
@@ -1638,6 +1645,7 @@ def write_to_online_store( | |||
| 1638 | 1645 | df: Optional[pd.DataFrame] = None, | |
| 1639 | 1646 | inputs: Optional[Union[Dict[str, List[Any]], pd.DataFrame]] = None, | |
| 1640 | 1647 | allow_registry_cache: bool = True, | |
| 1648 | + transform_on_write: bool = True, | ||
| 1641 | 1649 | ): | |
| 1642 | 1650 | """ | |
| 1643 | 1651 | Persists a dataframe to the online store. | |
@@ -1647,13 +1655,15 @@ def write_to_online_store( | |||
| 1647 | 1655 | df: The dataframe to be persisted. | |
| 1648 | 1656 | inputs: Optional the dictionary object to be written | |
| 1649 | 1657 | allow_registry_cache (optional): Whether to allow retrieving feature views from a cached registry. | |
| 1658 | + transform_on_write (optional): Whether to transform the data before pushing. | ||
| 1650 | 1659 | """ | |
| 1651 | 1660 | ||
| 1652 | 1661 | feature_view, df = self._get_feature_view_and_df_for_online_write( | |
| 1653 | 1662 | feature_view_name=feature_view_name, | |
| 1654 | 1663 | df=df, | |
| 1655 | 1664 | inputs=inputs, | |
| 1656 | 1665 | allow_registry_cache=allow_registry_cache, | |
| 1666 | + transform_on_write=transform_on_write, | ||
| 1657 | 1667 | ) | |
| 1658 | 1668 | provider = self._get_provider() | |
| 1659 | 1669 | provider.ingest_df(feature_view, df) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -874,7 +874,8 @@ def test_stored_writes(self): | |||
| 874 | 874 | assert driver_stats_fv.entity_columns == [] | |
| 875 | 875 | ||
| 876 | 876 | ODFV_STRING_CONSTANT = "guaranteed constant" | |
| 877 | - ODFV_OTHER_STRING_CONSTANT = "somethign else" | ||
| 877 | + ODFV_OTHER_STRING_CONSTANT = "something else" | ||
| 878 | + ODFV_UNTRANSFORMED_STRING_CONSTANT = "also something else" | ||
| 878 | 879 | ||
| 879 | 880 | @on_demand_feature_view( | |
| 880 | 881 | entities=[driver], | |
@@ -1069,6 +1070,52 @@ def python_stored_writes_feature_view( | |||
| 1069 | 1070 | assert online_odfv_python_response["string_constant"] != [ | |
| 1070 | 1071 | ODFV_OTHER_STRING_CONSTANT | |
| 1071 | 1072 | ] | |
| 1073 | + odfv_entity_rows_to_write_no_transform = [ | ||
| 1074 | + { | ||
| 1075 | + "driver_id": 1003, | ||
| 1076 | + "counter": 10, | ||
| 1077 | + "conv_rate": 0.25, | ||
| 1078 | + "acc_rate": 0.50, | ||
| 1079 | + "input_datetime": current_datetime, | ||
| 1080 | + "string_constant": ODFV_UNTRANSFORMED_STRING_CONSTANT, | ||
| 1081 | + } | ||
| 1082 | + ] | ||
| 1083 | + odfv_entity_rows_to_read_no_transform = [ | ||
| 1084 | + { | ||
| 1085 | + "driver_id": 1003, | ||
| 1086 | + "conv_rate_plus_acc": 7, # note how this is not the correct value and would be calculate on demand | ||
| 1087 | + "conv_rate": 0.25, | ||
| 1088 | + "acc_rate": 0.50, | ||
| 1089 | + "counter": 0, | ||
| 1090 | + "input_datetime": current_datetime, | ||
| 1091 | + "string_constant": ODFV_UNTRANSFORMED_STRING_CONSTANT, | ||
| 1092 | + } | ||
| 1093 | + ] | ||
| 1094 | + print("storing ODFV features") | ||
| 1095 | + self.store.write_to_online_store( | ||
| 1096 | + feature_view_name="python_stored_writes_feature_view", | ||
| 1097 | + df=odfv_entity_rows_to_write_no_transform, | ||
| 1098 | + transform_on_write=False, | ||
| 1099 | + ) | ||
| 1100 | + online_odfv_python_response_no_transform = self.store.get_online_features( | ||
| 1101 | + entity_rows=odfv_entity_rows_to_read_no_transform, | ||
| 1102 | + features=[ | ||
| 1103 | + "python_stored_writes_feature_view:conv_rate_plus_acc", | ||
| 1104 | + "python_stored_writes_feature_view:current_datetime", | ||
| 1105 | + "python_stored_writes_feature_view:counter", | ||
| 1106 | + "python_stored_writes_feature_view:input_datetime", | ||
| 1107 | + "python_stored_writes_feature_view:string_constant", | ||
| 1108 | + ], | ||
| 1109 | + ).to_dict() | ||
| 1110 | + # note these are approximately correct by | ||
| 1111 | + assert online_odfv_python_response_no_transform == { | ||
| 1112 | + "driver_id": [1003], | ||
| 1113 | + "counter": [10], | ||
| 1114 | + "conv_rate_plus_acc": [None], | ||
| 1115 | + "input_datetime": [current_datetime.replace(microsecond=0)], | ||
| 1116 | + "string_constant": [ODFV_UNTRANSFORMED_STRING_CONSTANT], | ||
| 1117 | + "current_datetime": [None], | ||
| 1118 | + } | ||
| 1072 | 1119 | ||
| 1073 | 1120 | def test_stored_writes_with_explode(self): | |
| 1074 | 1121 | with tempfile.TemporaryDirectory() as data_dir: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments