SET Statement
Overview
The SET statement is a session configuration management statement for Flink SQL. It is used to set the value of a specified configuration item. In AI DataLake, you can dynamically adjust job running parameters using the SET statement, affecting the execution behavior of subsequent SQL statements without restarting the job.
Application Scenarios
- Adjusting the parallelism degree: Modifies parallelism.default using the SET statement to control the parallelism degree of a job.
- Switching the running mode: Modifies execution.runtime-mode using the SET statement to switch between stream mode and batch mode.
- Optimizing the state TTL: Modifies table.exec.state.ttl using the SET statement to control the state retention duration, balancing performance and correctness.
- Configuring checkpoints: Modifies the execution.checkpointing.* parameters using the SET statement to control checkpoint behavior.
- Troubleshooting: Views all current configurations using the SET statement to verify whether the parameters have taken effect.
Notes and Constraints
- The SET statement affects only the current session and is not persisted to the global configuration.
- Modifications to some configuration items take effect only for jobs submitted after the modification. Running jobs are not affected.
- The value set by the SET statement automatically becomes invalid after the session ends.
- The support scope of some configuration items on the AI DataLake platform may differ from that of open-source Flink. The actual environment prevails.
Syntax Structure
Modify configurations.
SET ('key' = 'value') Common Configuration Parameters
| Parameter | Default Value | Description |
|---|---|---|
| parallelism.default | 1 | Default job parallelism. |
| execution.runtime-mode | STREAMING | Running mode. The value can be STREAMING or BATCH. |
| table.exec.state.ttl | 0 ms | State time-to-live (TTL). States that are not accessed within this period will be cleaned up. |
| table.exec.source.idle-timeout | 0 ms | Source idle timeout interval. The idle marker is used for watermark advancement. |
| execution.checkpointing.interval | None | Checkpoint triggering interval. |
| execution.checkpointing.mode | EXACTLY_ONCE | Checkpoint mode. The value can be EXACTLY_ONCE or AT_LEAST_ONCE. |
| execution.checkpointing.timeout | 10 min | Checkpoint timeout interval. |
| state.backend | hashmap | State backend type. The value can be hashmap or rocksdb. |
Usage Example
Example 1: Viewing and setting the parallelism degree
-- Create a DataGen source table. CREATE TABLE datagen_source ( id BIGINT, name STRING, amount DECIMAL(10, 2) ) WITH ( 'connector' = 'datagen', 'rows-per-second' = '100', 'fields.id.kind' = 'sequence', 'fields.id.start' = '1', 'fields.id.end' = '10000', 'fields.name.length' = '8' ); -- Create the Print result table. CREATE TABLE print_sink ( id BIGINT, name STRING, amount DECIMAL(10, 2) ) WITH ( 'connector' = 'print', 'print-identifier' = 'set_demo' ); -- Set the parallelism to 4. SET 'parallelism.default' = '4'; -- Submit the job. INSERT INTO print_sink SELECT id, name, amount FROM datagen_source;
Example 2: Setting the checkpoint and running mode
-- Create a DataGen source table. CREATE TABLE datagen_source ( order_id BIGINT, customer_id INT, order_time TIMESTAMP(3), WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND ) WITH ( 'connector' = 'datagen', 'rows-per-second' = '50', 'fields.order_id.kind' = 'sequence', 'fields.order_id.start' = '1', 'fields.order_id.end' = '50000', 'fields.customer_id.min' = '1', 'fields.customer_id.max' = '1000' ); -- Create the Print result table. CREATE TABLE print_sink ( order_id BIGINT, customer_id INT ) WITH ( 'connector' = 'print', 'print-identifier' = 'checkpoint_demo' ); -- Set the checkpoint interval to 30 seconds. SET 'execution.checkpointing.interval' = '30s'; -- Set the checkpoint mode to EXACTLY_ONCE. SET 'execution.checkpointing.mode' = 'EXACTLY_ONCE'; -- Set the state TTL to 1 hour. SET 'table.exec.state.ttl' = '3600000 ms'; -- Submit the job. INSERT INTO print_sink SELECT order_id, customer_id FROM datagen_source;
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot