Skip to content

Commit

Permalink
feat: Add /write-to-online-store method to the python feature server (
Browse files Browse the repository at this point in the history
#2423)

Signed-off-by: Tomas Pereira de Vasconcelos <[email protected]>
  • Loading branch information
tpvasconcelos authored Apr 11, 2022
1 parent 70d4a13 commit d2fb048
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions sdk/python/feast/feature_server.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import json
import traceback
import warnings

import pandas as pd
import uvicorn
from fastapi import FastAPI, HTTPException, Request
from fastapi.logger import logger
from fastapi.params import Depends
from google.protobuf.json_format import MessageToDict, Parse
from pydantic import BaseModel

import feast
from feast import proto_json
from feast.protos.feast.serving.ServingService_pb2 import GetOnlineFeaturesRequest


class WriteToFeatureStoreRequest(BaseModel):
feature_view_name: str
df: dict
allow_registry_cache: bool = True


def get_app(store: "feast.FeatureStore"):
proto_json.patch()

Expand Down Expand Up @@ -58,6 +68,28 @@ def get_online_features(body=Depends(get_body)):
# Raise HTTPException to return the error message to the client
raise HTTPException(status_code=500, detail=str(e))

@app.post("/write-to-online-store")
def write_to_online_store(body=Depends(get_body)):
warnings.warn(
"write_to_online_store is an experimental feature. "
"This API is unstable and it could be changed in the future. "
"We do not guarantee that future changes will maintain backward compatibility.",
RuntimeWarning,
)
try:
request = WriteToFeatureStoreRequest(**json.loads(body))
df = pd.DataFrame(request.df)
store.write_to_online_store(
feature_view_name=request.feature_view_name,
df=df,
allow_registry_cache=request.allow_registry_cache,
)
except Exception as e:
# Print the original exception on the server side
logger.exception(traceback.format_exc())
# Raise HTTPException to return the error message to the client
raise HTTPException(status_code=500, detail=str(e))

return app


Expand Down

0 comments on commit d2fb048

Please sign in to comment.