|
| 1 | +import json |
1 | 2 | import traceback
|
| 3 | +import warnings |
2 | 4 |
|
| 5 | +import pandas as pd |
3 | 6 | import uvicorn
|
4 | 7 | from fastapi import FastAPI, HTTPException, Request
|
5 | 8 | from fastapi.logger import logger
|
6 | 9 | from fastapi.params import Depends
|
7 | 10 | from google.protobuf.json_format import MessageToDict, Parse
|
| 11 | +from pydantic import BaseModel |
8 | 12 |
|
9 | 13 | import feast
|
10 | 14 | from feast import proto_json
|
11 | 15 | from feast.protos.feast.serving.ServingService_pb2 import GetOnlineFeaturesRequest
|
12 | 16 |
|
13 | 17 |
|
| 18 | +class WriteToFeatureStoreRequest(BaseModel): |
| 19 | + feature_view_name: str |
| 20 | + df: dict |
| 21 | + allow_registry_cache: bool = True |
| 22 | + |
| 23 | + |
14 | 24 | def get_app(store: "feast.FeatureStore"):
|
15 | 25 | proto_json.patch()
|
16 | 26 |
|
@@ -58,6 +68,28 @@ def get_online_features(body=Depends(get_body)):
|
58 | 68 | # Raise HTTPException to return the error message to the client
|
59 | 69 | raise HTTPException(status_code=500, detail=str(e))
|
60 | 70 |
|
| 71 | + @app.post("/write-to-online-store") |
| 72 | + def write_to_online_store(body=Depends(get_body)): |
| 73 | + warnings.warn( |
| 74 | + "write_to_online_store is an experimental feature. " |
| 75 | + "This API is unstable and it could be changed in the future. " |
| 76 | + "We do not guarantee that future changes will maintain backward compatibility.", |
| 77 | + RuntimeWarning, |
| 78 | + ) |
| 79 | + try: |
| 80 | + request = WriteToFeatureStoreRequest(**json.loads(body)) |
| 81 | + df = pd.DataFrame(request.df) |
| 82 | + store.write_to_online_store( |
| 83 | + feature_view_name=request.feature_view_name, |
| 84 | + df=df, |
| 85 | + allow_registry_cache=request.allow_registry_cache, |
| 86 | + ) |
| 87 | + except Exception as e: |
| 88 | + # Print the original exception on the server side |
| 89 | + logger.exception(traceback.format_exc()) |
| 90 | + # Raise HTTPException to return the error message to the client |
| 91 | + raise HTTPException(status_code=500, detail=str(e)) |
| 92 | + |
61 | 93 | return app
|
62 | 94 |
|
63 | 95 |
|
|
0 commit comments