Insert Idempotency
Since Timeplus Enterprise v2.4 there are new settings idempotent_id
and enable_idempotent_processing
:
- INSERT INTO .. SETTINGS idempotent_id='..' VALUES ..
- 选择... FROM .. SETTINGS enable_idempotent_processing=true
These settings allow you to define a unique ID for each batch INSERT. Sending the data with the same value of idempotent_id won't result in duplicated data in the target stream. You can retry safely with those settings.
Here is an example.
Create a stream for testing
Let's create a stream with 2 columns:
CREATE STREAM test_stream(`i` int, `v` string)
This is an append-only stream. You can insert duplicated data, e.g.
INSERT INTO test43_stream (i, v) VALUES (1, 'a') (1, 'a')
Insert with idempotent_id
Recreate the stream if you have inserted any data. You can run the following SQL multiple times:
INSERT INTO test_stream (i, v) SETTINGS idempotent_id = 'batch1' VALUES (1, 'a') (2, 'b');
Then run
SELECT count() FROM table(test_stream)