Introduces how SQLMesh simplifies managing RisingWave streaming SQL pipelines.
timestamp
, event_type
, and value
.
It aims to calculate a rolling 5-minute count and sum of value
for each event_type
using a tumbling window. Then, the logic will be modified to calculate an average, showcasing how SQLMesh handles the change.
RisingWave standalone mode is ready
means that RisingWave has started successfully.
psql
(or another Postgres-compatible SQL client) and prepare the data.
psql
, run the following:
config.yaml
file (created by init
). Ensure the following matches or update your config.yaml
.
models/event_summary_tumbling.sql
:
reporting.event_summary_tumbling
) and show a plan to create it in the prod environment (which maps to a schema like sqlmesh_prod
or prod
in RisingWave, often including the model name itself, e.g., sqlmesh__reporting
). It will also detect the default models created by init; you can choose to apply changes only for your new model if desired, or apply all.
CREATE MATERIALIZED VIEW
statement(s) in RisingWave.
psql
.
The exact schema and MV name includes a hash for versioning. You can use SHOW
to find it. Since reporting
is used as model schema, the materialized view should be in the sqlmesh__reporting
schema.
models/event_summary_tumbling.sql
to calculate the average value and distinct count:
sqlmesh plan
again to see the impact.
SQLMesh detects the change in the definition of reporting.event_summary_tumbling
. Because the logic changed, it plans to:
psql
:
distinct_event_count
and average_value columns
, reflecting the v2 logic. The original v1 MV still exists momentarily. This demonstrates SQLMesh’s safe, versioned deployment approach.
click_events
table in RisingWave for simplicity. However, SQLMesh provides pre- and post-statements within model definitions, allowing you to embed DDL statements that run before or after the main model logic executes.
For example, you could place a CREATE SOURCE IF NOT EXISTS ...
statement in pre-statement (that is, an SQL query prior to the SELECT
statement), and / or a CREATE SINK IF NOT EXISTS ...
in a post-statement. This approach keeps the setup/teardown logic closer to the relevant transformation step within your SQLMesh project.
SQLMesh’s core focus is managing the transformation logic (the SELECT
statements) and dependencies across your entire pipeline (often multiple models). While pre- and post-statements offer integration points, managing complex CREATE SOURCE/SINK
statements with intricate connector configurations might still be cleaner handled outside the model definitions (e.g., separate setup scripts or specialized infrastructure tools) to maintain clarity.