Using a dynamic table as a queue
To implement a queue using dynamic tables, use ordered dynamic tables. Such tables are a sequence of ordered rows, with no key columns.
CLI
Python
-
Create a table:
yt create table //path/to/table --attributes \ '{dynamic=%true;schema=[{name=first_name;type=string};{name=last_name;type=string}]}'
-
Mount a table:
yt mount-table //path/to/table
-
Write data:
echo '{first_name=Ivan;last_name=Ivanov}' | yt insert-rows //path/to/table --format yson
-
Read data:
yt select-rows '* from [//path/to/table]' --format json {"first_name":"Ivan","last_name":"Ivanov"}
-
Create a table:
import yt.wrapper as yt schema = [ { 'name': 'first_name', 'type': 'string' }, { 'name': 'last_name', 'type': 'string' } ] yt.create('table', '//path/to/table', attributes = {'dynamic': True, 'schema': schema})
-
Mount a table:
yt.mount_table('//path/to/table')
-
Write data:
data = [{ 'first_name': 'Ivan', 'last_name': 'Ivanov' }] client.insert_rows('//path/to/table', data)
-
Read data:
for d in client.select_rows('* FROM [//path/to/table]'): print(d) {'$tablet_index': 0L, 'first_name': 'Ivan', '$row_index': 0L, 'last_name': 'Ivanov'}
For more information about cleaning up and splitting ordered dynamic tables into tablets, see Ordered dynamic tables.