Skip to content

Commit 1a06f3e

Browse files
committed
add type hints & docstrings to TableClient
1 parent b57e947 commit 1a06f3e

File tree

2 files changed

+243
-57
lines changed

2 files changed

+243
-57
lines changed

ydb/aio/table.py

Lines changed: 121 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
import time
44
import typing
55

6+
from typing import (
7+
Any,
8+
Dict,
9+
List,
10+
Optional,
11+
Tuple,
12+
)
13+
614
import ydb
715

816
from ydb import issues, settings as settings_impl, table
@@ -172,16 +180,16 @@ async def create_table(
172180
self,
173181
path: str,
174182
table_description: TableDescription,
175-
settings: typing.Optional[settings_impl.BaseRequestSettings] = None,
176-
):
183+
settings: Optional[settings_impl.BaseRequestSettings] = None,
184+
) -> ydb.Operation:
177185
"""
178186
Create a YDB table.
179187
180188
:param path: A table path
181-
:param table_description: A description of table to create. An instance TableDescription
182-
:param settings: An instance of BaseRequestSettings that describes how rpc should invoked.
189+
:param table_description: TableDescription instanse.
190+
:param settings: An instance of BaseRequestSettings that describes how rpc should be invoked.
183191
184-
:return: A description of created scheme entry or error otherwise.
192+
:return: Operation or YDB error otherwise.
185193
"""
186194

187195
async def callee(session: Session):
@@ -192,32 +200,63 @@ async def callee(session: Session):
192200
async def drop_table(
193201
self,
194202
path: str,
195-
settings: typing.Optional[settings_impl.BaseRequestSettings] = None,
196-
):
203+
settings: Optional[settings_impl.BaseRequestSettings] = None,
204+
) -> ydb.Operation:
205+
"""
206+
Drop a YDB table.
207+
208+
:param path: A table path
209+
:param settings: An instance of BaseRequestSettings that describes how rpc should be invoked.
210+
211+
:return: Operation or YDB error otherwise.
212+
"""
213+
197214
async def callee(session: Session):
198215
return await session.drop_table(path=path, settings=settings)
199216

200217
return await self._pool.retry_operation(callee)
201218

202219
async def alter_table(
203220
self,
204-
path,
205-
add_columns=None,
206-
drop_columns=None,
207-
settings=None,
208-
alter_attributes=None,
209-
add_indexes=None,
210-
drop_indexes=None,
211-
set_ttl_settings=None,
212-
drop_ttl_settings=None,
213-
add_column_families=None,
214-
alter_column_families=None,
215-
alter_storage_settings=None,
216-
set_compaction_policy=None,
217-
alter_partitioning_settings=None,
218-
set_key_bloom_filter=None,
219-
set_read_replicas_settings=None,
220-
):
221+
path: str,
222+
add_columns: Optional[List[ydb.Column]] = None,
223+
drop_columns: Optional[List[str]] = None,
224+
settings: Optional[settings_impl.BaseRequestSettings] = None,
225+
alter_attributes: Optional[Optional[Dict[str, str]]] = None,
226+
add_indexes: Optional[List[ydb.TableIndex]] = None,
227+
drop_indexes: Optional[List[str]] = None,
228+
set_ttl_settings: Optional[ydb.TtlSettings] = None,
229+
drop_ttl_settings: Optional[Any] = None,
230+
add_column_families: Optional[List[ydb.ColumnFamily]] = None,
231+
alter_column_families: Optional[List[ydb.ColumnFamily]] = None,
232+
alter_storage_settings: Optional[ydb.StorageSettings] = None,
233+
set_compaction_policy: Optional[str] = None,
234+
alter_partitioning_settings: Optional[ydb.PartitioningSettings] = None,
235+
set_key_bloom_filter: Optional[ydb.FeatureFlag] = None,
236+
set_read_replicas_settings: Optional[ydb.ReadReplicasSettings] = None,
237+
) -> ydb.Operation:
238+
"""
239+
Alter a YDB table.
240+
241+
:param path: A table path
242+
:param add_columns: List of ydb.Column to add
243+
:param drop_columns: List of column names to drop
244+
:param settings: An instance of BaseRequestSettings that describes how rpc should be invoked.
245+
:param alter_attributes: Dict of attributes to alter
246+
:param add_indexes: List of ydb.TableIndex to add
247+
:param drop_indexes: List of index names to drop
248+
:param set_ttl_settings: ydb.TtlSettings to set
249+
:param drop_ttl_settings: Any to drop
250+
:param add_column_families: List of ydb.ColumnFamily to add
251+
:param alter_column_families: List of ydb.ColumnFamily to alter
252+
:param alter_storage_settings: ydb.StorageSettings to alter
253+
:param set_compaction_policy: Compaction policy
254+
:param alter_partitioning_settings: ydb.PartitioningSettings to alter
255+
:param set_key_bloom_filter: ydb.FeatureFlag to set key bloom filter
256+
257+
:return: Operation or YDB error otherwise.
258+
"""
259+
221260
async def callee(session: Session):
222261
return await session.alter_table(
223262
path=path,
@@ -240,13 +279,41 @@ async def callee(session: Session):
240279

241280
return await self._pool.retry_operation(callee)
242281

243-
async def describe_table(self, path, settings=None):
282+
async def describe_table(
283+
self,
284+
path: str,
285+
settings: Optional[settings_impl.BaseRequestSettings] = None,
286+
) -> ydb.TableSchemeEntry:
287+
"""
288+
Describe a YDB table.
289+
290+
:param path: A table path
291+
:param settings: An instance of BaseRequestSettings that describes how rpc should be invoked.
292+
293+
:return: TableSchemeEntry or YDB error otherwise.
294+
"""
295+
244296
async def callee(session: Session):
245297
return await session.describe_table(path=path, settings=settings)
246298

247299
return await self._pool.retry_operation(callee)
248300

249-
async def copy_table(self, source_path, destination_path, settings=None):
301+
async def copy_table(
302+
self,
303+
source_path: str,
304+
destination_path: str,
305+
settings: Optional[settings_impl.BaseRequestSettings] = None,
306+
) -> ydb.Operation:
307+
"""
308+
Copy a YDB table.
309+
310+
:param source_path: A table path
311+
:param destination_path: Destination table path
312+
:param settings: An instance of BaseRequestSettings that describes how rpc should be invoked.
313+
314+
:return: Operation or YDB error otherwise.
315+
"""
316+
250317
async def callee(session: Session):
251318
return await session.copy_table(
252319
source_path=source_path,
@@ -256,13 +323,39 @@ async def callee(session: Session):
256323

257324
return await self._pool.retry_operation(callee)
258325

259-
async def copy_tables(self, source_destination_pairs, settings=None):
326+
async def copy_tables(
327+
self,
328+
source_destination_pairs: List[Tuple[str, str]],
329+
settings: Optional[settings_impl.BaseRequestSettings] = None
330+
) -> ydb.Operation:
331+
"""
332+
Copy a YDB tables.
333+
334+
:param source_destination_pairs: List of tuples (source_path, destination_path)
335+
:param settings: An instance of BaseRequestSettings that describes how rpc should be invoked.
336+
337+
:return: Operation or YDB error otherwise.
338+
"""
339+
260340
async def callee(session: Session):
261341
return await session.copy_tables(source_destination_pairs=source_destination_pairs, settings=settings)
262342

263343
return await self._pool.retry_operation(callee)
264344

265-
async def rename_tables(self, rename_items, settings=None):
345+
async def rename_tables(
346+
self,
347+
rename_items: List[Tuple[str, str]],
348+
settings=None
349+
) -> ydb.Operation:
350+
"""
351+
Rename a YDB tables.
352+
353+
:param rename_items: List of tuples (current_name, desired_name)
354+
:param settings: An instance of BaseRequestSettings that describes how rpc should be invoked.
355+
356+
:return: Operation or YDB error otherwise.
357+
"""
358+
266359
async def callee(session: Session):
267360
return await session.rename_tables(rename_items=rename_items, settings=settings)
268361

0 commit comments

Comments
 (0)