Streaming
Flink can continuously write to and read from an append table. New data becomes visible after a snapshot is committed; end-to-end latency depends on checkpointing, commit time, and the reader's discovery interval.
This page uses the default unaware-bucket layout (bucket = -1). For ordering within a fixed bucket, see
Bucketed streaming.
Write a Stream
Run an INSERT INTO from an insert-only source in streaming mode. For example, after creating my_table from the
overview and a source table with the same columns:
SET 'execution.runtime-mode' = 'streaming';
SET 'execution.checkpointing.interval' = '1 min';
INSERT INTO my_table SELECT product_id, price, sales, dt FROM source_table;
Short checkpoint intervals can produce many small data files. Choose a compaction approach together with your checkpoint interval and write parallelism.
Manage Small Files
| Approach | When it runs | How to select it |
|---|---|---|
| Pre-commit compaction | Merges newly written files from the same partition before they enter a snapshot. | Set precommit-compact = true; the default is false. |
| Background compaction in the ingestion job | Plans compaction from files already committed to the table. | Included in a normal Flink streaming sink for an unaware-bucket append table. |
| Dedicated compaction | Merges committed files in a separate job. | Set write-only = true on ingestion jobs and run a dedicated compaction job. |
Pre-Commit Compaction
ALTER TABLE my_table SET ('precommit-compact' = 'true');
This adds a coordinator and workers after the writer to merge newly created data files. The compaction runs before commit, so its work contributes to the time needed to make those files visible. Configure the option before starting the ingestion job.
Background Compaction
For a normal unaware-bucket append table, the writer does not compact files itself. The Flink streaming sink adds a compact coordinator and compact workers. The coordinator discovers committed small files, and the workers rewrite selected files while forwarding ingestion committables to the committer.
The compaction work runs asynchronously, but it still consumes CPU, memory, and storage I/O. Size those resources for
both ingestion and compaction. Setting write-only = true removes the background compaction operators from ingestion;
precommit-compact is configured separately.
For unaware-bucket tables with clustering.incremental = true, the sink does not add this background compaction path.
Schedule incremental clustering to merge small files and maintain
the clustered layout. Bucketed tables use a different compaction path, described in that guide.
Dedicated Compaction
To move background compaction out of the ingestion job, apply write-only to that job. For example, use this insert
instead of the one in Write a stream:
INSERT INTO my_table /*+ OPTIONS('write-only' = 'true') */
SELECT product_id, price, sales, dt FROM source_table;
Then run a dedicated compaction job, or a scheduled clustering job if incremental
clustering is enabled. write-only also skips snapshot expiration in the ingestion job, so the dedicated maintenance
job must handle that work. It does not disable separately configured pre-commit compaction.