Skip to content

Commit ed55987

Browse files
committed
Update sql-create-stream.md
update TTL
1 parent fffc7ec commit ed55987

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

docs/sql-create-stream.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
[Stream](/working-with-streams) is a key [concept](/glossary) in Timeplus. All data lives in streams, no matter static data or data in motion. We don't recommend you to create or manage `TABLE` in Timeplus.
44

5-
Syntax:
5+
## Syntax
6+
7+
### Append Stream
68

79
```sql
810
CREATE STREAM [IF NOT EXISTS] [db.]<stream_name>
911
(
1012
<col_name1> <col_type_1> [DEFAULT <col_expr_1>] [compression_codec_1],
1113
<col_name1> <col_type_2> [DEFAULT <col_expr_2>] [compression_codec_2]
1214
)
13-
SETTINGS <event_time_column>='<col>', <key1>=<value1>, <key2>=<value2>, ...
15+
[TTL expr]
16+
[SETTINGS <event_time_column>='<col>', <key1>=<value1>, <key2>=<value2>, ...]
1417
```
1518

1619
:::info
@@ -21,6 +24,10 @@ Stream creation is an async process.
2124

2225
If you omit the database name, `default` will be used. Stream name can be any utf-8 characters and needs backtick quoted if there are spaces in between. Column name can be any utf-8 characters and needs backtick quoted if there are spaces in between.
2326

27+
### Mutable Stream
28+
29+
Mutable Streams are available in Timeplus Enterprise. Guide: [CREATE MUTABLE STREAM](/sql-create-mutable-stream)
30+
2431
### Versioned Stream
2532

2633
[Versioned Stream](/versioned-stream) allows you to specify the primary key(s) and focus on the latest value. For example:
@@ -45,10 +52,6 @@ SETTINGS mode='changelog_kv', version_column='i';
4552

4653
The default `version_column` is `_tp_time`. For the data with same primary key(s), Proton will use the ones with maximum value of `version_column`. So by default, it tracks the most recent data for same primary key(s). If there are late events, you can use specify other column to determine the end state for your live data.
4754

48-
### Mutable Stream
49-
50-
[CREATE MUTABLE STREAM](/sql-create-mutable-stream)
51-
5255
## SETTINGS
5356
#### mode
5457
Type: string
@@ -131,3 +134,25 @@ This is an advanced setting. Default value is `hybrid` to use both a streaming s
131134
It can be:
132135
* `streaming`: Use only streaming storage, together with settings `logstore_codec`, `logstore_retention_bytes`, `logstore_retention_ms`.
133136
* `memory`: put data in memory only, mainly for testing.
137+
138+
## TTL (Time-To-Live) {#ttl}
139+
140+
The [logstore_retention_bytes](#logstore_retention_bytes) and [logstore_retention_ms](#logstore_retention_ms) settings control the maximum size and time to keep the streaming storage. The historical storage for the stream is controlled by the TTL expression.
141+
142+
Syntax:
143+
```sql
144+
TTL time_column + interval
145+
```
146+
147+
For example, `TTL _tp_time + INTERVAL 1 DAY` will delete rows older than one day, `TTL _tp_time + INTERVAL 7 DAY` will delete rows older than one week.
148+
149+
For [S3 Tried Storage](/tiered-storage#create-a-stream-with-the-policy), you can also specify when the cold data will be moved to S3. For example:
150+
```sql
151+
CREATE STREAM my_stream (
152+
id uint32,
153+
name string,
154+
age uint8
155+
)
156+
TTL to_start_of_day(_tp_time) + interval 7 day to volume 'cold'
157+
SETTINGS storage_policy = 'hcs';
158+
```

0 commit comments

Comments
 (0)