4
4
from abc import abstractmethod
5
5
import logging
6
6
import enum
7
+ import typing
7
8
8
9
from . import (
9
10
issues ,
@@ -1193,6 +1194,11 @@ def bulk_upsert(self, table_path, rows, column_types, settings=None):
1193
1194
1194
1195
1195
1196
class TableClient (BaseTableClient ):
1197
+ def __init__ (self , driver , table_client_settings = None ):
1198
+ # type:(ydb.Driver, ydb.TableClientSettings) -> None
1199
+ super ().__init__ (driver = driver , table_client_settings = table_client_settings )
1200
+ self ._pool : SessionPool = SessionPool (self ._driver , 10 )
1201
+
1196
1202
def async_scan_query (self , query , parameters = None , settings = None ):
1197
1203
# type: (ydb.ScanQuery, tuple, ydb.BaseRequestSettings) -> ydb.AsyncResponseIterator
1198
1204
request = _scan_query_request_factory (query , parameters , settings )
@@ -1219,6 +1225,105 @@ def async_bulk_upsert(self, table_path, rows, column_types, settings=None):
1219
1225
(),
1220
1226
)
1221
1227
1228
+ def create_table (
1229
+ self ,
1230
+ path : str ,
1231
+ table_description : TableDescription ,
1232
+ settings : typing .Optional [settings_impl .BaseRequestSettings ] = None ,
1233
+ ):
1234
+ """
1235
+ Create a YDB table.
1236
+
1237
+ :param path: A table path
1238
+ :param table_description: A description of table to create. An instance TableDescription
1239
+ :param settings: An instance of BaseRequestSettings that describes how rpc should invoked.
1240
+
1241
+ :return: A description of created scheme entry or error otherwise.
1242
+ """
1243
+ def callee (session : Session ):
1244
+ return session .create_table (path = path , table_description = table_description , settings = settings )
1245
+
1246
+ return self ._pool .retry_operation_sync (callee )
1247
+
1248
+ def drop_table (
1249
+ self ,
1250
+ path : str ,
1251
+ settings : typing .Optional [settings_impl .BaseRequestSettings ] = None ,
1252
+ ):
1253
+ def callee (session : Session ):
1254
+ return session .drop_table (path = path , settings = settings )
1255
+
1256
+ return self ._pool .retry_operation_sync (callee )
1257
+
1258
+ def alter_table (
1259
+ self ,
1260
+ path ,
1261
+ add_columns = None ,
1262
+ drop_columns = None ,
1263
+ settings = None ,
1264
+ alter_attributes = None ,
1265
+ add_indexes = None ,
1266
+ drop_indexes = None ,
1267
+ set_ttl_settings = None ,
1268
+ drop_ttl_settings = None ,
1269
+ add_column_families = None ,
1270
+ alter_column_families = None ,
1271
+ alter_storage_settings = None ,
1272
+ set_compaction_policy = None ,
1273
+ alter_partitioning_settings = None ,
1274
+ set_key_bloom_filter = None ,
1275
+ set_read_replicas_settings = None ,
1276
+ ):
1277
+ def callee (session : Session ):
1278
+ return session .alter_table (
1279
+ path = path ,
1280
+ add_columns = add_columns ,
1281
+ drop_columns = drop_columns ,
1282
+ settings = settings ,
1283
+ alter_attributes = alter_attributes ,
1284
+ add_indexes = add_indexes ,
1285
+ drop_indexes = drop_indexes ,
1286
+ set_ttl_settings = set_ttl_settings ,
1287
+ drop_ttl_settings = drop_ttl_settings ,
1288
+ add_column_families = add_column_families ,
1289
+ alter_column_families = alter_column_families ,
1290
+ alter_storage_settings = alter_storage_settings ,
1291
+ set_compaction_policy = set_compaction_policy ,
1292
+ alter_partitioning_settings = alter_partitioning_settings ,
1293
+ set_key_bloom_filter = set_key_bloom_filter ,
1294
+ set_read_replicas_settings = set_read_replicas_settings ,
1295
+ )
1296
+
1297
+ return self ._pool .retry_operation_sync (callee )
1298
+
1299
+ def describe_table (self , path , settings = None ):
1300
+ def callee (session : Session ):
1301
+ return session .describe_table (path = path , settings = settings )
1302
+
1303
+ return self ._pool .retry_operation_sync (callee )
1304
+
1305
+ def copy_table (self , source_path , destination_path , settings = None ):
1306
+ def callee (session : Session ):
1307
+ return session .copy_table (
1308
+ source_path = source_path ,
1309
+ destination_path = destination_path ,
1310
+ settings = settings ,
1311
+ )
1312
+
1313
+ return self ._pool .retry_operation_sync (callee )
1314
+
1315
+ def copy_tables (self , source_destination_pairs , settings = None ):
1316
+ def callee (session : Session ):
1317
+ return session .copy_tables (source_destination_pairs = source_destination_pairs , settings = settings )
1318
+
1319
+ return self ._pool .retry_operation_sync (callee )
1320
+
1321
+ def rename_tables (self , rename_items , settings = None ):
1322
+ def callee (session : Session ):
1323
+ return session .rename_tables (rename_items = rename_items , settings = settings )
1324
+
1325
+ return self ._pool .retry_operation_sync (callee )
1326
+
1222
1327
1223
1328
def _make_index_description (index ):
1224
1329
result = TableIndex (index .name ).with_index_columns (* tuple (col for col in index .index_columns ))
0 commit comments