aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralextarazanov <alextarazanov@yandex-team.com>2022-08-01 09:07:56 +0300
committeralextarazanov <alextarazanov@yandex-team.com>2022-08-01 09:07:56 +0300
commit9ce3db1a8055e7d17f073139a3c7684442efb860 (patch)
tree8c625e47b34639ef89fbf84957f1622ef4abcab7
parentdb2f39e5c3ec6e0a17ed8372f1b4ac5cf6cd950a (diff)
downloadydb-9ce3db1a8055e7d17f073139a3c7684442efb860.tar.gz
Check TTL-column interpretation translate
-rw-r--r--ydb/docs/en/core/concepts/_includes/ttl.md222
-rw-r--r--ydb/docs/ru/core/concepts/_includes/ttl.md2
2 files changed, 126 insertions, 98 deletions
diff --git a/ydb/docs/en/core/concepts/_includes/ttl.md b/ydb/docs/en/core/concepts/_includes/ttl.md
index eaddee5faa6..644c96c6e6c 100644
--- a/ydb/docs/en/core/concepts/_includes/ttl.md
+++ b/ydb/docs/en/core/concepts/_includes/ttl.md
@@ -29,7 +29,7 @@ Data is deleted by the *Background Removal Operation* (*BRO*), consisting of two
1. Checking the values in the TTL column.
1. Deleting expired data.
-*The BRO* has the following properties:
+The *BRO* has the following properties:
* The concurrency unit is a [table partition](../datamodel.md#partitioning).
* For tables with [secondary indexes](../secondary_indexes.md), the delete stage is a [distributed transaction](../transactions.md#distributed-tx).
@@ -43,17 +43,18 @@ Data is deleted by the *Background Removal Operation* (*BRO*), consisting of two
## Limitations {#restrictions}
* The TTL column must be of one of the following types:
- * `Date`
- * `Datetime`
- * `Timestamp`
- * `Uint32`
- * `Uint64`
- * `DyNumber`
-* The value in the TTL column with a numeric type (`Uint32`, `Uint64`, `DyNumber`) is interpreted as a [Unix-time]{% if lang == "en" %}(https://en.wikipedia.org/wiki/Unix_time){% endif %}{% if lang == "ru" %}(https://ru.wikipedia.org/wiki/Unix-время){% endif %} value specified in:
- * Seconds
- * Milliseconds
- * Microseconds
- * Nanoseconds
+ * `Date`.
+ * `Datetime`.
+ * `Timestamp`.
+ * `Uint32`.
+ * `Uint64`.
+ * `DyNumber`.
+* The value in the TTL column with a numeric type (`Uint32`, `Uint64`, or `DyNumber`) is interpreted as a [Unix time]{% if lang == "en" %}(https://en.wikipedia.org/wiki/Unix_time){% endif %}{% if lang == "ru" %}(https://ru.wikipedia.org/wiki/Unix-время){% endif %} value. The following units are supported (set in the TTL settings):
+ * Seconds.
+ * Milliseconds.
+ * Microseconds.
+ * Nanoseconds.
+* TTL setup using [YQL](../../yql/reference/index.md) is only possible for the `Date`, `Datetime`, and `Timestamp` columns.
* You can't specify multiple TTL columns.
* You can't delete the TTL column. However, if this is required, you should first [disable TTL](#disable) for the table.
@@ -65,12 +66,6 @@ Currently, you can manage TTL settings using:
* [{{ ydb-short-name }} console client](../../reference/ydb-cli/index.md).
* {{ ydb-short-name }} {% if oss %}C++ and{% endif %} Python [SDK](../../reference/ydb-sdk/index.md).
-{% note info %}
-
-TTL setup using YQL is possible for the `Date`, `Datetime`, and `Timestamp` columns.
-
-{% endnote %}
-
### Enabling TTL for an existing table {#enable-on-existent-table}
In the example below, the items of the `mytable` table will be deleted an hour after the time set in the `created_at` column:
@@ -79,46 +74,80 @@ In the example below, the items of the `mytable` table will be deleted an hour a
- YQL
- ```yql
- ALTER TABLE `mytable` SET (TTL = Interval("PT1H") ON created_at);
- ```
+ ```yql
+ ALTER TABLE `mytable` SET (TTL = Interval("PT1H") ON created_at);
+ ```
- CLI
- ```bash
- $ {{ ydb-cli }} -e <endpoint> -d <database> table ttl set --column created_at --expire-after 3600 mytable
- ```
+ ```bash
+ $ {{ ydb-cli }} -e <endpoint> -d <database> table ttl set --column created_at --expire-after 3600 mytable
+ ```
{% if oss == true %}
- C++
- ```c++
- session.AlterTable(
- "mytable",
- TAlterTableSettings()
- .BeginAlterTtlSettings()
- .Set("created_at", TDuration::Hours(1))
- .EndAlterTtlSettings()
- );
- ```
+ ```c++
+ session.AlterTable(
+ "mytable",
+ TAlterTableSettings()
+ .BeginAlterTtlSettings()
+ .Set("created_at", TDuration::Hours(1))
+ .EndAlterTtlSettings()
+ );
+ ```
{% endif %}
- Python
- ```python
- session.alter_table('mytable', set_ttl_settings=ydb.TtlSettings().with_date_type_column('created_at', 3600))
- ```
+ ```python
+ session.alter_table('mytable', set_ttl_settings=ydb.TtlSettings().with_date_type_column('created_at', 3600))
+ ```
{% endlist %}
{% note tip %}
-When setting up TTL using YQL, the `Interval` is created from a string literal in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601).
+When setting up TTL using YQL, an `Interval` is created from a string literal in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
{% endnote %}
+The example below shows how to use the `modified_at` column with a numeric type (`Uint32`) as a TTL column. The column value is interpreted as the number of seconds since the Unix epoch:
+
+{% list tabs %}
+
+- CLI
+
+ ```bash
+ $ {{ ydb-cli }} -e <endpoint> -d <database> table ttl set --column modified_at --expire-after 3600 --unit seconds mytable
+ ```
+
+{% if oss == true %}
+
+- C++
+
+ ```c++
+ session.AlterTable(
+ "mytable",
+ TAlterTableSettings()
+ .BeginAlterTtlSettings()
+ .Set("modified_at", TTtlSettings::EUnit::Seconds, TDuration::Hours(1))
+ .EndAlterTtlSettings()
+ );
+ ```
+
+{% endif %}
+
+- Python
+
+ ```python
+ session.alter_table('mytable', set_ttl_settings=ydb.TtlSettings().with_value_since_unix_epoch('modified_at', UNIT_SECONDS, 3600))
+ ```
+
+{% endlist %}
+
### Enabling TTL for a newly created table {#enable-for-new-table}
For a newly created table, you can pass TTL settings along with the table description:
@@ -127,46 +156,46 @@ For a newly created table, you can pass TTL settings along with the table descri
- YQL
- ```yql
- CREATE TABLE `mytable` (
- id Uint64,
- expire_at Timestamp,
- PRIMARY KEY (id)
- ) WITH (
- TTL = Interval("PT0S") ON expire_at
- );
- ```
+ ```yql
+ CREATE TABLE `mytable` (
+ id Uint64,
+ expire_at Timestamp,
+ PRIMARY KEY (id)
+ ) WITH (
+ TTL = Interval("PT0S") ON expire_at
+ );
+ ```
{% if oss == true %}
- C++
- ```c++
- session.CreateTable(
- "mytable",
- TTableBuilder()
- .AddNullableColumn("id", EPrimitiveType::Uint64)
- .AddNullableColumn("expire_at", EPrimitiveType::Timestamp)
- .SetPrimaryKeyColumn("id")
- .SetTtlSettings("expire_at")
- .Build()
- );
- ```
+ ```c++
+ session.CreateTable(
+ "mytable",
+ TTableBuilder()
+ .AddNullableColumn("id", EPrimitiveType::Uint64)
+ .AddNullableColumn("expire_at", EPrimitiveType::Timestamp)
+ .SetPrimaryKeyColumn("id")
+ .SetTtlSettings("expire_at")
+ .Build()
+ );
+ ```
{% endif %}
- Python
- ```python
- session.create_table(
- 'mytable',
- ydb.TableDescription()
- .with_column(ydb.Column('id', ydb.OptionalType(ydb.DataType.Uint64)))
- .with_column(ydb.Column('expire_at', ydb.OptionalType(ydb.DataType.Timestamp)))
- .with_primary_key('id')
- .with_ttl(ydb.TtlSettings().with_date_type_column('expire_at'))
- )
- ```
+ ```python
+ session.create_table(
+ 'mytable',
+ ydb.TableDescription()
+ .with_column(ydb.Column('id', ydb.OptionalType(ydb.DataType.Uint64)))
+ .with_column(ydb.Column('expire_at', ydb.OptionalType(ydb.DataType.Timestamp)))
+ .with_primary_key('id')
+ .with_ttl(ydb.TtlSettings().with_date_type_column('expire_at'))
+ )
+ ```
{% endlist %}
@@ -176,37 +205,37 @@ For a newly created table, you can pass TTL settings along with the table descri
- YQL
- ```yql
- ALTER TABLE `mytable` RESET (TTL);
- ```
+ ```yql
+ ALTER TABLE `mytable` RESET (TTL);
+ ```
- CLI
- ```bash
- $ {{ ydb-cli }} -e <endpoint> -d <database> table ttl drop mytable
- ```
+ ```bash
+ $ {{ ydb-cli }} -e <endpoint> -d <database> table ttl drop mytable
+ ```
{% if oss == true %}
- C++
- ```c++
- session.AlterTable(
- "mytable",
- TAlterTableSettings()
- .BeginAlterTtlSettings()
- .Drop()
- .EndAlterTtlSettings()
- );
- ```
+ ```c++
+ session.AlterTable(
+ "mytable",
+ TAlterTableSettings()
+ .BeginAlterTtlSettings()
+ .Drop()
+ .EndAlterTtlSettings()
+ );
+ ```
{% endif %}
- Python
- ```python
- session.alter_table('mytable', drop_ttl_settings=True)
- ```
+ ```python
+ session.alter_table('mytable', drop_ttl_settings=True)
+ ```
{% endlist %}
@@ -218,27 +247,26 @@ The current TTL settings can be obtained from the table description:
- CLI
- ```bash
- $ {{ ydb-cli }} -e <endpoint> -d <database> scheme describe mytable
- ```
+ ```bash
+ $ {{ ydb-cli }} -e <endpoint> -d <database> scheme describe mytable
+ ```
{% if oss == true %}
- C++
- ```c++
- auto desc = session.DescribeTable("mytable").GetValueSync().GetTableDescription();
- auto ttl = desc.GetTtlSettings();
- ```
+ ```c++
+ auto desc = session.DescribeTable("mytable").GetValueSync().GetTableDescription();
+ auto ttl = desc.GetTtlSettings();
+ ```
{% endif %}
- Python
- ```python
- desc = session.describe_table('mytable')
- ttl = desc.ttl_settings
- ```
+ ```python
+ desc = session.describe_table('mytable')
+ ttl = desc.ttl_settings
+ ```
{% endlist %}
-
diff --git a/ydb/docs/ru/core/concepts/_includes/ttl.md b/ydb/docs/ru/core/concepts/_includes/ttl.md
index a928c581f9a..574095e92d1 100644
--- a/ydb/docs/ru/core/concepts/_includes/ttl.md
+++ b/ydb/docs/ru/core/concepts/_includes/ttl.md
@@ -64,7 +64,7 @@ expiration_time = valueof(ttl_column) + expire_after_seconds
* [YQL](../../yql/reference/index.md).
* [Консольного клиента {{ ydb-short-name }}](../../reference/ydb-cli/index.md).
-* {{ ydb-short-name }} {% if oss %}C++ и{% endif %} Python [SDK](../../reference/ydb-sdk/index.md).
+* {{ ydb-short-name }} {% if oss %}C++ и{% endif %} Python [SDK](../../reference/ydb-sdk/index.md).
### Включение TTL для существующей таблицы {#enable-on-existent-table}