13
13
_scan_query_request_factory ,
14
14
_wrap_scan_query_response ,
15
15
BaseTxContext ,
16
+ TableDescription ,
16
17
)
17
18
from . import _utilities
18
19
from ydb import _apis , _session_impl
@@ -139,6 +140,11 @@ async def rename_tables(self, rename_items, settings=None): # pylint: disable=W
139
140
140
141
141
142
class TableClient (BaseTableClient ):
143
+ def __init__ (self , driver , table_client_settings = None ):
144
+ # type:(ydb.Driver, ydb.TableClientSettings) -> None
145
+ super ().__init__ (driver = driver , table_client_settings = table_client_settings )
146
+ self ._pool : SessionPool = SessionPool (self ._driver , 10 )
147
+
142
148
def session (self ):
143
149
return Session (self ._driver , self ._table_client_settings )
144
150
@@ -158,6 +164,125 @@ async def scan_query(self, query, parameters=None, settings=None): # pylint: di
158
164
lambda resp : _wrap_scan_query_response (resp , self ._table_client_settings ),
159
165
)
160
166
167
+ async def create_table (
168
+ self ,
169
+ path : str ,
170
+ table_description : TableDescription ,
171
+ settings : typing .Optional [settings_impl .BaseRequestSettings ] = None ,
172
+ ):
173
+ """
174
+ Create a YDB table.
175
+
176
+ :param path: A table path
177
+ :param table_description: A description of table to create. An instance TableDescription
178
+ :param settings: An instance of BaseRequestSettings that describes how rpc should invoked.
179
+
180
+ :return: A description of created scheme entry or error otherwise.
181
+ """
182
+ async def callee (session : Session ):
183
+ return await session .create_table (path = path , table_description = table_description , settings = settings )
184
+
185
+ return await self ._pool .retry_operation (callee )
186
+
187
+ async def create_table (
188
+ self ,
189
+ path : str ,
190
+ table_description : TableDescription ,
191
+ settings : typing .Optional [settings_impl .BaseRequestSettings ] = None ,
192
+ ):
193
+ """
194
+ Create a YDB table.
195
+
196
+ :param path: A table path
197
+ :param table_description: A description of table to create. An instance TableDescription
198
+ :param settings: An instance of BaseRequestSettings that describes how rpc should invoked.
199
+
200
+ :return: A description of created scheme entry or error otherwise.
201
+ """
202
+ async def callee (session : Session ):
203
+ return await session .create_table (path = path , table_description = table_description , settings = settings )
204
+
205
+ return await self ._pool .retry_operation (callee )
206
+
207
+ async def drop_table (
208
+ self ,
209
+ path : str ,
210
+ settings : typing .Optional [settings_impl .BaseRequestSettings ] = None ,
211
+ ):
212
+ async def callee (session : Session ):
213
+ return await session .drop_table (path = path , settings = settings )
214
+
215
+ return await self ._pool .retry_operation (callee )
216
+
217
+ async def alter_table (
218
+ self ,
219
+ path ,
220
+ add_columns = None ,
221
+ drop_columns = None ,
222
+ settings = None ,
223
+ alter_attributes = None ,
224
+ add_indexes = None ,
225
+ drop_indexes = None ,
226
+ set_ttl_settings = None ,
227
+ drop_ttl_settings = None ,
228
+ add_column_families = None ,
229
+ alter_column_families = None ,
230
+ alter_storage_settings = None ,
231
+ set_compaction_policy = None ,
232
+ alter_partitioning_settings = None ,
233
+ set_key_bloom_filter = None ,
234
+ set_read_replicas_settings = None ,
235
+ ):
236
+ async def callee (session : Session ):
237
+ return await session .alter_table (
238
+ path = path ,
239
+ add_columns = add_columns ,
240
+ drop_columns = drop_columns ,
241
+ settings = settings ,
242
+ alter_attributes = alter_attributes ,
243
+ add_indexes = add_indexes ,
244
+ drop_indexes = drop_indexes ,
245
+ set_ttl_settings = set_ttl_settings ,
246
+ drop_ttl_settings = drop_ttl_settings ,
247
+ add_column_families = add_column_families ,
248
+ alter_column_families = alter_column_families ,
249
+ alter_storage_settings = alter_storage_settings ,
250
+ set_compaction_policy = set_compaction_policy ,
251
+ alter_partitioning_settings = alter_partitioning_settings ,
252
+ set_key_bloom_filter = set_key_bloom_filter ,
253
+ set_read_replicas_settings = set_read_replicas_settings ,
254
+ )
255
+
256
+ return await self ._pool .retry_operation (callee )
257
+
258
+ async def describe_table (self , path , settings = None ):
259
+ async def callee (session : Session ):
260
+ return await session .describe_table (path = path , settings = settings )
261
+
262
+ return await self ._pool .retry_operation (callee )
263
+
264
+ async def copy_table (self , source_path , destination_path , settings = None ):
265
+ async def callee (session : Session ):
266
+ return await session .copy_table (
267
+ source_path = source_path ,
268
+ destination_path = destination_path ,
269
+ settings = settings ,
270
+ )
271
+
272
+ return await self ._pool .retry_operation (callee )
273
+
274
+ async def copy_tables (self , source_destination_pairs , settings = None ):
275
+ async def callee (session : Session ):
276
+ return await session .copy_tables (source_destination_pairs = source_destination_pairs , settings = settings )
277
+
278
+ return await self ._pool .retry_operation (callee )
279
+
280
+ async def rename_tables (self , rename_items , settings = None ):
281
+ async def callee (session : Session ):
282
+ return await session .rename_tables (rename_items = rename_items , settings = settings )
283
+
284
+ return await self ._pool .retry_operation (callee )
285
+
161
286
162
287
class TxContext (BaseTxContext ):
163
288
async def __aenter__ (self ):
0 commit comments