visit
Also, you would need to make sure that you have dbt
(v0.18.1+) installed:
As a side note here, you would be perfectly fine using Kafka instead of Redpanda. I just like the simplicity that Redpanda brings to the table, as you can run a single Redpanda instance instead of all of the Kafka components.
git clone //github.com/bobbyiliev/materialize-tutorials.git
After that, you can access the directory:
cd materialize-tutorials/mz-user-reviews-dbt-demo
Let's start by running the Redpanda container:
docker-compose up -d redpanda
Build the images:
docker-compose build
Then pull all of the other Docker images:
docker-compose pull
Finally, start all of the services:
docker-compose up -d
In order to launch the Materialize CLI, you can run the following command:
docker-compose run mzcli
As soon as the demo is running, the mock service will start generating reviews and users.This is just a shortcut to a Docker container with a compatible CLI pre-installed; if you already have
psql
installed, you could instead connect to the running Materialize instance using that:psql -U materialize -h localhost -p 6875 materialize
.
First, we will need to install the dbt-materialize
plugin:
python3 -m venv dbt-venv
source dbt-venv/bin/activate
pip install dbt-materialize
After that, with your favorite text editor, open the ~/.dbt/project.yml
file and add the following lines:
user_reviews:
outputs:
dev:
type: materialize
threads: 1
host: localhost
port: 6875
user: materialize
pass: pass
dbname: materialize
schema: analytics
target: dev
After that, to make sure that the connection to the Materialize container is working, run:
dbt debug
Finally, we can use dbt to create materialized views on top of the 3 Redpanda/Kafka topics. To do so just run the following dbt command:
dbt run
This command generates executable SQL from our model files (found in the models
directory of this project) and executes that SQL against the target database, creating our materialized views.
Finally, you can run your dbt tests:Note: If you installed
dbt-materialize
in a virtual environment, make sure it's activated. If you don't have it installed, please revisit the setup above.
dbt test
You can check the columns of the reviews
source by running the following statement:
SHOW COLUMNS FROM analytics.reviews_raw;
You'll see that, as Materialize is pulling the message schema from the , it knows the column types to use for each attribute:
name | nullable | type
---------------+----------+-----------
id | f | bigint
user_id | t | bigint
review_text | t | text
review_rating | t | integer
created_at | t | text
updated_at | t | timestamp
You can verify the views were created from your psql shell connected to Materialize:
SHOW VIEWS FROM analytics;
Output:
name
--------------------
badreviews
vipusers
vipusersbadreviews
You can also verify the data is being pulled from Redpanda by running the following query a few times:
SELECT COUNT(*) FROM analytics.vipusersbadreviews;
You will be able to see that the result changes each time you run the query, meaning that the data is being incrementally updated without you having to run dbt run
again.
dbt docs generate
After that you can serve the docs by running the following command:
dbt docs serve
Then visit the docs at . There, you will have a list of all the views that were created and you can click on any of them to see the SQL that was generated. You would also see some nice Lineage Graphs that show the relationships between the views:
In order to access the instance, visit //localhost:3030
if you are running the demo locally or //your_server_ip:3030
if you are running the demo on a server. Then follow the steps to complete the Metabase setup.
Field | Value |
---|---|
Database | PostgreSQL |
Name | user_reviews |
Host |
materialized |
Port |
6875 |
Database name |
materialize |
Database username |
materialize |
Database password | Leave empty |
docker-compose down
CREATE SOURCE
CREATE MATERIALIZED VIEW
SELECT