Prerequisites
- Basic knowledge of SQL (
SELECT,GROUP BY,CREATE TABLE) - A running Flink cluster — follow the Local Installation guide first
Steps
Start the SQL Client
The SQL Client is an interactive CLI that submits SQL statements to your Flink cluster and displays results.You should see the Flink SQL Client banner and a prompt:To exit at any time, type
- Docker
- Local installation
exit; and press Enter.Run your first query
Start with a simple expression to confirm the SQL Client is working:The result is displayed in a result table in the terminal:You can also query the current timestamp:To see all available built-in functions:
Create a source table
Flink does not store data locally. Instead, queries operate on top of external tables backed by connectors. Source tables produce rows from an external system (Kafka, filesystem, DataGen, etc.).Create a source table using the DataGen connector, which generates random rows automatically — no external system required:This creates a table that produces 10 new employee records per second with:
emp_id: sequential integers from 1 to 1,000,000name: random 8-character stringsdept_id: random integers between 1 and 5
Query the streaming source
Run a simple continuous query to see rows as they are generated:The result table updates in real time as new rows arrive. Press
Q to exit the result view and return to the SQL prompt.This query runs continuously and will keep producing results until you press
Q. It does not terminate on its own because employee_information is an unbounded stream.Write a continuous aggregation
Compute a running count of employees per department. This query maintains state across all incoming rows and continuously updates the result:As new rows arrive, the
emp_count values update. You will see +I (insert) and -U/+U (retract and upsert) row kinds in changelog mode, reflecting how the aggregation result changes over time.Press Q to exit the result view.Create a sink table and persist results
The interactive result view is read-only. To persist query results for reporting or downstream consumption, write them to a sink table using Now submit the aggregation as a persistent streaming job:Flink responds with a job ID and runs the query as a background job:To see the output rows written by the You should see output like:Each line is one changelog record written by the
INSERT INTO.First, create the sink table. This example uses the print connector, which writes each result row to the TaskManager’s log — suitable for development and testing:print connector:- Docker
- Local installation
print connector. +I means a new row was inserted, -U is a retract of the previous value, and +U is the updated value.Use a production-grade sink connector
The
print connector is only for development. In production you would write results to an external system. Here are examples for common sinks:Key concepts recap
| Concept | Description |
|---|---|
| Source table | Reads from an external system (Kafka, filesystem, DataGen). Produces an unbounded or bounded stream of rows. |
| Sink table | Writes results to an external system. Referenced in INSERT INTO. |
| Continuous query | A SQL query that runs indefinitely, processing new rows as they arrive. |
| Dynamic table | Flink’s internal abstraction for a table whose content changes over time. Every streaming source is a dynamic table. |
| Changelog | The stream of row insertions, updates, and deletions that represents changes to a dynamic table. |
| Watermark | A timestamp marker that tells Flink how far event time has progressed, enabling late data handling and window closing. |
Common DDL patterns
Create a Kafka source with JSON format and event-time watermarks
Tumbling window aggregation
Sliding window aggregation
Join two streams
What’s next
- SQL reference — Complete DDL and DML syntax, all supported operators, and configuration options in the SQL reference documentation.
- Built-in functions — String, math, date/time, aggregation, and table-generating functions in the built-in functions reference.
- Connectors — Connect to Kafka, JDBC, Elasticsearch, Hive, and more in the connectors documentation.
- Dynamic tables — Understand how Flink maps streams to tables in dynamic tables concepts.
- Table API Quickstart — Build the same kind of aggregation programmatically using the Table API.

