from hsfs.client.exceptions import RestAPIError
Check if the feature view exists, and create if it does not
try:
# Try to get the feature view
feature_view = feature_store.get_feature_view(
name=config.FEATURE_VIEW_NAME,
version=config.FEATURE_VIEW_VERSION,
)
print(‘Feature view already exists. Skipping creation.’)
except RestAPIError as e:
if ‘Feature view wasn't found’ in str(e):
# Feature view does not exist, so create it
print(f"Feature view ‘{config.FEATURE_VIEW_NAME}’ with version ‘{config.FEATURE_VIEW_VERSION}’ not found. Creating a new feature view.“)
try:
feature_view = feature_store.create_feature_view(
name=config.FEATURE_VIEW_NAME,
version=config.FEATURE_VIEW_VERSION,
query=feature_group.select_all()
)
print(“Feature view created successfully.”)
except RestAPIError as create_error:
print(f"Error creating feature view: {create_error}”)
else:
print(f"An error occurred: {e}")
Feature view ‘time_series_hourly_feature_view’ with version ‘1’ not found. Creating a new feature view.
Error creating feature view: Metadata operation error: (url: https://c.app.hopsworks.ai/hopsworks-api/api/project/101543/featurestores/101462/featureview). Server response:
HTTP code: 404, HTTP reason: Not Found, body: b’{“errorCode”:270046,“usrMsg”:“HOPSFS Connector: NY_taxi_demand_Training_Datasets”,“errorMsg”:“HopsFs Connector not found”}', error code: 270046, error msg: HopsFs Connector not found, user msg: HOPSFS Connector: NY_taxi_demand_Training_Datasets