Skip to content

Commit

Permalink
Merge pull request #45 MakeTablePath, CopyTable, CopyTables, Describe…
Browse files Browse the repository at this point in the history
…Table methods for TableClient
  • Loading branch information
rekby committed Dec 15, 2023
2 parents 037f303 + 54a5d69 commit ae6e18f
Show file tree
Hide file tree
Showing 8 changed files with 834 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Added MakeTablePath, CopyTable, CopyTables, DescribeTable methods for TableClient
- Add logging for transactions

## v0.1.5
Expand Down
2 changes: 2 additions & 0 deletions src/Ydb.Sdk/src/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class Driver : IDisposable, IAsyncDisposable
private readonly ChannelsCache _channels;
private bool _disposed;

internal string Database => _config.Database;

public Driver(DriverConfig config, ILoggerFactory? loggerFactory = null)
{
LoggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
Expand Down
107 changes: 107 additions & 0 deletions src/Ydb.Sdk/src/Services/Table/CopyTable.cs
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);
}
}
}
Loading

0 comments on commit ae6e18f

Please sign in to comment.