|
| 1 | +import pytest |
| 2 | +import ydb |
| 3 | + |
| 4 | + |
| 5 | +class TestTableClient: |
| 6 | + @pytest.mark.asyncio |
| 7 | + async def test_create_table(self, driver: ydb.aio.Driver): |
| 8 | + client = driver.table_client |
| 9 | + table_name = "/local/testtableclient" |
| 10 | + try: |
| 11 | + await client.drop_table(table_name) |
| 12 | + except ydb.SchemeError: |
| 13 | + pass |
| 14 | + |
| 15 | + with pytest.raises(ydb.SchemeError): |
| 16 | + await client.describe_table(table_name) |
| 17 | + |
| 18 | + description = ( |
| 19 | + ydb.TableDescription() |
| 20 | + .with_primary_keys("key1", "key2") |
| 21 | + .with_columns( |
| 22 | + ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)), |
| 23 | + ydb.Column("key2", ydb.OptionalType(ydb.PrimitiveType.Uint64)), |
| 24 | + ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)), |
| 25 | + ) |
| 26 | + ) |
| 27 | + |
| 28 | + await client.create_table(table_name, description) |
| 29 | + |
| 30 | + actual_description = await client.describe_table(table_name) |
| 31 | + |
| 32 | + assert actual_description.columns == description.columns |
| 33 | + |
| 34 | + @pytest.mark.asyncio |
| 35 | + async def test_alter_table(self, driver: ydb.aio.Driver): |
| 36 | + client = driver.table_client |
| 37 | + |
| 38 | + table_name = "/local/testtableclient" |
| 39 | + try: |
| 40 | + await client.drop_table(table_name) |
| 41 | + except ydb.SchemeError: |
| 42 | + pass |
| 43 | + |
| 44 | + description = ( |
| 45 | + ydb.TableDescription() |
| 46 | + .with_primary_keys("key1", "key2") |
| 47 | + .with_columns( |
| 48 | + ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)), |
| 49 | + ydb.Column("key2", ydb.OptionalType(ydb.PrimitiveType.Uint64)), |
| 50 | + ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)), |
| 51 | + ) |
| 52 | + ) |
| 53 | + |
| 54 | + await client.create_table(table_name, description) |
| 55 | + |
| 56 | + await client.alter_table(table_name, add_columns=[ |
| 57 | + ydb.Column("value2", ydb.OptionalType(ydb.PrimitiveType.Uint64)), |
| 58 | + ]) |
| 59 | + |
| 60 | + description = await client.describe_table(table_name) |
| 61 | + assert len(description.columns) == 4 |
| 62 | + |
| 63 | + @pytest.mark.asyncio |
| 64 | + async def test_copy_table(self, driver: ydb.aio.Driver): |
| 65 | + client = driver.table_client |
| 66 | + table_name = "/local/testtableclient" |
| 67 | + try: |
| 68 | + await client.drop_table(table_name) |
| 69 | + except ydb.SchemeError: |
| 70 | + pass |
| 71 | + |
| 72 | + description = ( |
| 73 | + ydb.TableDescription() |
| 74 | + .with_primary_keys("key1", "key2") |
| 75 | + .with_columns( |
| 76 | + ydb.Column("key1", ydb.OptionalType(ydb.PrimitiveType.Uint64)), |
| 77 | + ydb.Column("key2", ydb.OptionalType(ydb.PrimitiveType.Uint64)), |
| 78 | + ydb.Column("value", ydb.OptionalType(ydb.PrimitiveType.Utf8)), |
| 79 | + ) |
| 80 | + ) |
| 81 | + |
| 82 | + await client.create_table(table_name, description) |
| 83 | + |
| 84 | + await client.copy_table(table_name, table_name + "_copy") |
| 85 | + |
| 86 | + copied_description = await client.describe_table(table_name + "_copy") |
| 87 | + |
| 88 | + assert description.columns == copied_description.columns |
0 commit comments