| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
Note: This module is still WIP, and does not have a public data set to use. There is a smaller dataset visible in data/
This is a very similar module to module 1. The key difference is now we'll be using a data warehouse (Snowflake) in combination with dbt + Airflow to ensure that batch features are regularly generated.
Caveats
Architecture
First, we install Feast with Snowflake and Postgres and Redis support:
pip install "feast[snowflake,postgres,redis]"project: feast_demo_local
provider: local
registry:
registry_type: sql
path: postgresql://postgres:mysecretpassword@127.0.0.1:55001/feast
online_store:
type: redis
connection_string: localhost:6379
offline_store:
type: snowflake.offline
account: ${SNOWFLAKE_DEPLOYMENT_URL}
user: ${SNOWFLAKE_USER}
password: ${SNOWFLAKE_PASSWORD}
role: ${SNOWFLAKE_ROLE}
warehouse: ${SNOWFLAKE_WAREHOUSE}
database: TECTON_DEMO_DATA
schema: FRAUD
entity_key_serialization_version: 2We use Docker Compose to spin up the services we need.
Start up the Docker daemon and then use Docker Compose to spin up the services as described above:
$ docker-compose up
Creating network "module_3_default" with the default driver
Creating registry ... done
Creating zookeeper ... done
Creating redis ... done
Creating broker ... done
Creating tx_kafka_events ... done
Creating feast_feature_server ... done
Attaching to zookeeper, redis, registry, broker, kafka_events, feast_feature_server
...TODO(adchia): Generate parquet file to upload for public Snowflake dataset for features
There's already a dbt model that generates batch transformations. You just need to init this:
Note: You'll need to install dbt-snowflake as well! brew tap dbt-labs/dbt and brew install dbt-snowflake
To initialize dbt with your own credentials, do this
cd dbt/feast_demo; dbt init; dbt runThis will create the initial tables we need for Feast
In this example, we're using a test database in Snowflake.
To get started, go ahead and register the feature repository
<!--
Note: first you need to export environment variables
matching the above variables:
export SNOWFLAKE_DEPLOYMENT_URL="[YOUR DEPLOYMENT]
export SNOWFLAKE_USER="[YOUR USER]
export SNOWFLAKE_PASSWORD="[YOUR PASSWORD]
export SNOWFLAKE_ROLE="[YOUR ROLE]
export SNOWFLAKE_WAREHOUSE="[YOUR WAREHOUSE]
export SNOWFLAKE_DATABASE="[YOUR DATABASE]
-->
$ cd feature_repo; feast apply
Created entity user
Created feature view aggregate_transactions_features
Created feature view credit_scores_features
Created feature service model_v1
Created feature service model_v2
Deploying infrastructure for aggregate_transactions_features
Deploying infrastructure for credit_scores_featuresWe setup a standalone version of Airflow to set up the PythonOperator (Airflow now prefers @task for this) and BashOperator which will run incremental dbt models. We use dbt to define batch transformations from Snowflake, and once the incremental model is tested / ran, we run materialization.
The below script will copy the dbt DAGs over. In production, you'd want to use Airflow to sync with version controlled dbt DAGS (e.g. that are sync'd to S3).
# If not already done, export Snowflake related environment variables used above:
# export SNOWFLAKE_DEPLOYMENT_URL="[YOUR DEPLOYMENT]
# export SNOWFLAKE_USER="[YOUR USER]
# export SNOWFLAKE_PASSWORD="[YOUR PASSWORD]
# export SNOWFLAKE_ROLE="[YOUR ROLE]
# export SNOWFLAKE_WAREHOUSE="[YOUR WAREHOUSE]
# export SNOWFLAKE_DATABASE="[YOUR DATABASE]
cd ../airflow_demo; sh setup_airflow.shThe example dag is going to run on a daily basis and materialize all feature views based on the start and end interval. Note that there is a 1 hr overlap in the start time to account for potential late arriving data in the offline store.
With dbt incremental models, the model itself in incremental mode selects overlapping windows of data to account for late arriving data. Feast materialization similarly has a late arriving threshold.
with DAG(
dag_id='feature_dag',
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
description='A dbt + Feast DAG',
schedule="@daily",
catchup=False,
tags=["feast"],
) as dag:
dbt_test = BashOperator(
task_id="dbt_test",
bash_command="""
cd ${AIRFLOW_HOME}; dbt test --models "aggregate_transaction_features"
""",
dag=dag,
)
dbt_run = BashOperator(
task_id="dbt_run",
bash_command="""
cd ${AIRFLOW_HOME}; dbt run --models "aggregate_transaction_features"
""",
dag=dag,
)
@task()
def materialize(data_interval_start=None, data_interval_end=None):
repo_config = RepoConfig(
registry=RegistryConfig(
registry_type="sql",
path="postgresql://postgres:mysecretpassword@127.0.0.1:55001/feast",
),
project="feast_demo_local",
provider="local",
offline_store=SnowflakeOfflineStoreConfig(
account=Variable.get("SNOWFLAKE_DEPLOYMENT_URL"),
user=Variable.get("SNOWFLAKE_USER"),
password=Variable.get("SNOWFLAKE_PASSWORD"),
role=Variable.get("SNOWFLAKE_ROLE"),
warehouse=Variable.get("SNOWFLAKE_WAREHOUSE"),
database=Variable.get("SNOWFLAKE_DATABASE"),
schema_=Variable.get("SNOWFLAKE_SCHEMA"),
),
online_store=RedisOnlineStoreConfig(connection_string="localhost:6379"),
entity_key_serialization_version=2
)
store = FeatureStore(config=repo_config)
store.materialize(data_interval_start.subtract(hours=1), data_interval_end)
# Setup DAG
dbt_test >> dbt_run >> materialize()Now go to localhost:8080, use Airflow's auto-generated admin password to login, and toggle on the DAG. It should run one task automatically. After waiting for a run to finish, you'll see a successful job:
There's no built in mechanism for this, but you could store this logic in the feature view tags (e.g. a batch_schedule).
Then, you can parse these feature view in your Airflow job. You could for example have one DAG that runs all the daily batch_schedule feature views, and another DAG that runs all feature views with an hourly batch_schedule.
To run a backfill (i.e. process previous days of the above while letting Airflow manage state), you can do (from the airflow_demo directory):
Warning: This works correctly with the Redis online store because it conditionally writes. This logic has not been implemented for other online stores yet, and so can result in incorrect behavior
export AIRFLOW_HOME=$(pwd)/airflow_home
airflow dags backfill \
--start-date 2021-07-01 \
--end-date 2021-07-15 \
feature_dagFeast exposes a get_historical_features method to generate training data / run batch scoring and get_online_features method to power model serving.
To achieve fresher features, one might consider using streaming compute.There are two broad approaches with streaming
Feast will help enforce a consistent schema across batch + streaming features as they land in the online store.
Now, Run Jupyter notebook
We don't showcase how this works, but broadly there are many approaches to this. In all the approaches, you'll likely want to generate operational metrics for monitoring (e.g. via StatsD or Prometheus Pushgateway).
To outline a few approaches:
(seven_day_avg
.writeStream
.outputMode("append")
.option("checkpointLocation", "/tmp/feast-workshop/q3/")
.trigger(once=True)
.foreachBatch(send_to_feast)
.start())By the end of this module, you will have learned how to build a full feature platform, with orchestrated batch transformations (using dbt + Airflow), orchestrated materialization (with Feast + Airflow), and pointers on orchestrating streaming transformations.
Feast abstracts away the need to think about data modeling in the online store and helps you:
Once a feature view is in production, best practice is to create a new feature view (+ a separate dbt model) to generate new features or change existing features, so-as not to negatively impact prediction quality.
This means for each new set of features, you'll need to:
Several things change:
| Back | FazBrowse Home | New Git URL |