Work in Progress: This page is under development. Use the feedback button on the bottom right to help us improve it.

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 conditions

That'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
regionwindow_startwindow_endorder_countrevenue
us-east2024-01-15 10:00:002024-01-15 10:05:003364.99
us-west2024-01-15 10:00:002024-01-15 10:05:002375.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 window

Results emit every minute as windows close:

window_startwindow_endevent_count
10:00:0010:01:008
10:01:0010:02:0012
10:02:0010:03:005

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_startwindow_endtotal
10:00:0010:01:00225.50
10:01:0010:02:00250.00
10:02:0010:03:00425.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