Package: feast-snowflake
Feast Snowflake Offline & Online Store SupportQuickstartInstall feast-snowflakepipinstallfeast-snowflakeCreate a feature repositoryfeastinitfeature_repocdfeature_repoEditfeature_store.yamlsetoffline_storetype to befeast_snowflake.SnowflakeOfflineStoresetonline_storetype to befeast_snowflake.SnowflakeOnlineStoreproject:...registry:...provider:localoffline_store:type:feast_snowflake.SnowflakeOfflineStoreaccount:SNOWFLAKE_DEPLOYMENT_URL#drop .snowflakecomputing.comuser:USERNAMEpassword:PASSWORDrole:ROLE_NAME#remember cap sensitivewarehouse:WAREHOUSE_NAME#remember cap sensitivedatabase:DATABASE_NAME#remember cap sensitiveonline_store:type:feast_snowflake.SnowflakeOnlineStoreaccount:SNOWFLAKE_DEPLOYMENT_URL#drop .snowflakecomputing.comuser:USERNAMEpassword:PASSWORDrole:ROLE_NAME#remember cap sensitivewarehouse:WAREHOUSE_NAME#remember cap sensitivedatabase:DATABASE_NAME#remember cap sensitiveUpload sample data to Snowflakefromfeast_snowflake.snowflake_utilsimportcreate_new_snowflake_table,get_snowflake_connfromsnowflake.connector.pandas_toolsimportwrite_pandasfromfeastimportFeatureStoreimportpandasaspdfs=FeatureStore(repo_path=".")withget_snowflake_conn(fs.config.offline_store)asconn:create_new_snowflake_table(conn,pd.read_parquet('data/driver_stats.parquet'),'DRIVER_STATS')write_pandas(conn,pd.read_parquet('data/driver_stats.parquet'),'DRIVER_STATS')Replace the current text inexample.pywith the following:# This is an example feature definition filefromdatetimeimporttimedeltafromfeastimportEntity,Feature,FeatureView,ValueTypefromfeast_snowflakeimportSnowflakeSourceimportyaml# Read data from Snowflake table# Here we use a Table to reuse the original parquet data,# but you can replace to your own Table or Query.database=yaml.safe_load(open("feature_store.yaml"))["offline_store"]["database"]driver_hourly_stats=SnowflakeSource(table=f'"{database}"."PUBLIC"."DRIVER_STATS"',#query = """ """,event_timestamp_column="event_timestamp",created_timestamp_column="created",)# Define an entity for the driver.driver=Entity(name="driver_id",value_type=ValueType.INT64,description="driver id",)# Define FeatureViewdriver_hourly_stats_view=FeatureView(name="driver_hourly_stats",entities=["driver_id"],ttl=timedelta(weeks=4),features=[Feature(name="conv_rate",dtype=ValueType.FLOAT),Feature(name="acc_rate",dtype=ValueType.FLOAT),Feature(name="avg_daily_trips",dtype=ValueType.INT64),],online=True,batch_source=driver_hourly_stats,tags={},)Work with your Offline & Online Snowflake Feature Storefromexampleimportdriver,driver_hourly_stats_viewfromdatetimeimportdatetime,timedeltaimportpandasaspdfromfeastimportFeatureStorefs=FeatureStore(repo_path=".")fs.apply([driver,driver_hourly_stats_view])# Select featuresfeatures=["driver_hourly_stats:conv_rate","driver_hourly_stats:acc_rate","driver_hourly_stats:avg_daily_trips"]# Create an entity dataframe. This is the dataframe that will be enriched with historical featuresentity_df=pd.DataFrame({"event_timestamp":[pd.Timestamp(dt,unit="ms",tz="UTC").round("ms")fordtinpd.date_range(start=datetime.now()-timedelta(days=3),end=datetime.now(),periods=3,)],"driver_id":[1001,1002,1003],})# Retrieve historical features by joining the entity dataframe to the Snowflake table sourceprint("Retrieving training data...")training_df=fs.get_historical_features(features=features,entity_df=entity_df).to_df()print(training_df)print("Loading features into the online store...")fs.materialize_incremental(end_date=datetime.now())# Retrieve features from the online storeprint("Retrieving online features...")online_features=fs.get_online_features(features=features,entity_rows=[{"driver_id":1001},{"driver_id":1002}],).to_dict()print(online_features)