SQL in Laminar
Laminar uses SQL as the primary language for defining stream transformations. If you know SQL, you already know how to build streaming pipelines.
All examples in this documentation use the sample data.
The Pattern
Every Laminar pipeline follows a simple pattern:
INSERT INTO destination
SELECT transform(columns)
FROM source
WHERE conditionsThat's it. You read from a source, transform the data with SQL, and write to a destination.
A Complete Example
Let's calculate revenue per region from the orders stream.
INSERT INTO region_metrics
SELECT
region,
TUMBLE(interval '5 minutes') as window,
COUNT(*) as order_count,
SUM(amount) as revenue
FROM orders
WHERE status = 'completed'
GROUP BY region, window| region | window_start | window_end | order_count | revenue |
|---|---|---|---|---|
| us-east | 2024-01-15 10:00:00 | 2024-01-15 10:05:00 | 3 | 364.99 |
| us-west | 2024-01-15 10:00:00 | 2024-01-15 10:05:00 | 2 | 375.50 |
The query filtered to completed orders, grouped by region and 5-minute windows, and computed aggregates.
What Makes Streaming SQL Different?
In traditional SQL, tables are finite. In streaming SQL, data never stops arriving.
-- This would never complete in streaming!
SELECT COUNT(*) FROM events
-- Instead, use time windows:
SELECT
TUMBLE(interval '1 minute') as window,
COUNT(*) as event_count
FROM events
GROUP BY windowResults emit every minute as windows close:
| window_start | window_end | event_count |
|---|---|---|
| 10:00:00 | 10:01:00 | 8 |
| 10:01:00 | 10:02:00 | 12 |
| 10:02:00 | 10:03:00 | 5 |
Key Concepts
Time Windows
Since streams are unbounded, you define time boundaries for aggregations.
SELECT
TUMBLE(interval '1 minute') as window,
SUM(amount) as total
FROM orders
GROUP BY window| window_start | window_end | total |
|---|---|---|
| 10:00:00 | 10:01:00 | 225.50 |
| 10:01:00 | 10:02:00 | 250.00 |
| 10:02:00 | 10:03:00 | 425.00 |
SQL Engine
Laminar's SQL is powered by Apache DataFusion, giving you:
- Standard SQL syntax
- 100+ built-in functions
- High performance Rust execution
- Streaming-specific extensions for windows and time
Next Steps
- Quick Start - Build your first SQL pipeline
- Sample Data - Reference dataset for all examples
- Data Types - Supported types and how to use them
- Time & Windows - Master streaming time concepts
- Functions - All available SQL functions