-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 MakeTablePath, CopyTable, CopyTables, Describe…
…Table methods for TableClient
- Loading branch information
Showing
8 changed files
with
834 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using Ydb.Sdk.Client; | ||
using Ydb.Table; | ||
using Ydb.Table.V1; | ||
|
||
namespace Ydb.Sdk.Services.Table; | ||
|
||
public class CopyTableItem | ||
{ | ||
public string SourcePath { get; } | ||
public string DestinationPath { get; } | ||
public bool OmitIndexes { get; } | ||
|
||
public CopyTableItem(string sourcePath, string destinationPath, bool omitIndexes) | ||
{ | ||
SourcePath = sourcePath; | ||
DestinationPath = destinationPath; | ||
OmitIndexes = omitIndexes; | ||
} | ||
|
||
public Ydb.Table.CopyTableItem GetProto(TableClient tableClient) | ||
{ | ||
return new Ydb.Table.CopyTableItem | ||
{ | ||
SourcePath = tableClient.MakeTablePath(SourcePath), | ||
DestinationPath = tableClient.MakeTablePath(DestinationPath), | ||
OmitIndexes = OmitIndexes | ||
}; | ||
} | ||
} | ||
|
||
public class CopyTableSettings : OperationRequestSettings | ||
{ | ||
} | ||
|
||
public class CopyTablesSettings : OperationRequestSettings | ||
{ | ||
} | ||
|
||
public class CopyTableResponse : ResponseBase | ||
{ | ||
internal CopyTableResponse(Status status) : base(status) | ||
{ | ||
} | ||
} | ||
|
||
public class CopyTablesResponse : ResponseBase | ||
{ | ||
internal CopyTablesResponse(Status status) : base(status) | ||
{ | ||
} | ||
} | ||
|
||
public partial class TableClient | ||
{ | ||
public async Task<CopyTableResponse> CopyTable(string sourcePath, string destinationPath, | ||
CopyTableSettings? settings = null) | ||
{ | ||
settings ??= new CopyTableSettings(); | ||
var request = new CopyTableRequest | ||
{ | ||
OperationParams = MakeOperationParams(settings), | ||
SourcePath = MakeTablePath(sourcePath), | ||
DestinationPath = MakeTablePath(destinationPath) | ||
}; | ||
|
||
try | ||
{ | ||
var response = await Driver.UnaryCall( | ||
method: TableService.CopyTableMethod, | ||
request: request, | ||
settings: settings); | ||
|
||
var status = UnpackOperation(response.Data.Operation); | ||
return new CopyTableResponse(status); | ||
} | ||
catch (Driver.TransportException e) | ||
{ | ||
return new CopyTableResponse(e.Status); | ||
} | ||
} | ||
|
||
public async Task<CopyTablesResponse> CopyTables(List<CopyTableItem> tableItems, | ||
CopyTablesSettings? settings = null) | ||
{ | ||
settings ??= new CopyTablesSettings(); | ||
var request = new CopyTablesRequest | ||
{ | ||
OperationParams = MakeOperationParams(settings) | ||
}; | ||
request.Tables.AddRange(tableItems.Select(item => item.GetProto(this))); | ||
|
||
try | ||
{ | ||
var response = await Driver.UnaryCall( | ||
method: TableService.CopyTablesMethod, | ||
request: request, | ||
settings: settings); | ||
|
||
var status = UnpackOperation(response.Data.Operation); | ||
return new CopyTablesResponse(status); | ||
} | ||
catch (Driver.TransportException e) | ||
{ | ||
return new CopyTablesResponse(e.Status); | ||
} | ||
} | ||
} |
Oops, something went wrong.