|
| 1 | +using Ydb.Sdk.Client; |
| 2 | +using Ydb.Table; |
| 3 | +using Ydb.Table.V1; |
| 4 | + |
| 5 | +namespace Ydb.Sdk.Services.Table; |
| 6 | + |
| 7 | +public class CopyTableItem |
| 8 | +{ |
| 9 | + public string SourcePath { get; } |
| 10 | + public string DestinationPath { get; } |
| 11 | + public bool OmitIndexes { get; } |
| 12 | + |
| 13 | + public CopyTableItem(string sourcePath, string destinationPath, bool omitIndexes) |
| 14 | + { |
| 15 | + SourcePath = sourcePath; |
| 16 | + DestinationPath = destinationPath; |
| 17 | + OmitIndexes = omitIndexes; |
| 18 | + } |
| 19 | + |
| 20 | + public Ydb.Table.CopyTableItem GetProto(TableClient tableClient) |
| 21 | + { |
| 22 | + return new Ydb.Table.CopyTableItem |
| 23 | + { |
| 24 | + SourcePath = tableClient.MakeTablePath(SourcePath), |
| 25 | + DestinationPath = tableClient.MakeTablePath(DestinationPath), |
| 26 | + OmitIndexes = OmitIndexes |
| 27 | + }; |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +public class CopyTableSettings : OperationRequestSettings |
| 32 | +{ |
| 33 | +} |
| 34 | + |
| 35 | +public class CopyTablesSettings : OperationRequestSettings |
| 36 | +{ |
| 37 | +} |
| 38 | + |
| 39 | +public class CopyTableResponse : ResponseBase |
| 40 | +{ |
| 41 | + internal CopyTableResponse(Status status) : base(status) |
| 42 | + { |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +public class CopyTablesResponse : ResponseBase |
| 47 | +{ |
| 48 | + internal CopyTablesResponse(Status status) : base(status) |
| 49 | + { |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +public partial class TableClient |
| 54 | +{ |
| 55 | + public async Task<CopyTableResponse> CopyTable(string sourcePath, string destinationPath, |
| 56 | + CopyTableSettings? settings = null) |
| 57 | + { |
| 58 | + settings ??= new CopyTableSettings(); |
| 59 | + var request = new CopyTableRequest |
| 60 | + { |
| 61 | + OperationParams = MakeOperationParams(settings), |
| 62 | + SourcePath = MakeTablePath(sourcePath), |
| 63 | + DestinationPath = MakeTablePath(destinationPath) |
| 64 | + }; |
| 65 | + |
| 66 | + try |
| 67 | + { |
| 68 | + var response = await Driver.UnaryCall( |
| 69 | + method: TableService.CopyTableMethod, |
| 70 | + request: request, |
| 71 | + settings: settings); |
| 72 | + |
| 73 | + var status = UnpackOperation(response.Data.Operation); |
| 74 | + return new CopyTableResponse(status); |
| 75 | + } |
| 76 | + catch (Driver.TransportException e) |
| 77 | + { |
| 78 | + return new CopyTableResponse(e.Status); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + public async Task<CopyTablesResponse> CopyTables(List<CopyTableItem> tableItems, |
| 83 | + CopyTablesSettings? settings = null) |
| 84 | + { |
| 85 | + settings ??= new CopyTablesSettings(); |
| 86 | + var request = new CopyTablesRequest |
| 87 | + { |
| 88 | + OperationParams = MakeOperationParams(settings) |
| 89 | + }; |
| 90 | + request.Tables.AddRange(tableItems.Select(item => item.GetProto(this))); |
| 91 | + |
| 92 | + try |
| 93 | + { |
| 94 | + var response = await Driver.UnaryCall( |
| 95 | + method: TableService.CopyTablesMethod, |
| 96 | + request: request, |
| 97 | + settings: settings); |
| 98 | + |
| 99 | + var status = UnpackOperation(response.Data.Operation); |
| 100 | + return new CopyTablesResponse(status); |
| 101 | + } |
| 102 | + catch (Driver.TransportException e) |
| 103 | + { |
| 104 | + return new CopyTablesResponse(e.Status); |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments