Skip to content

Commit 79f661b

Browse files
feat: support ADO.NET GetSchema
1 parent 79e3315 commit 79f661b

File tree

14 files changed

+651
-80
lines changed

14 files changed

+651
-80
lines changed

src/Ydb.Sdk/src/Ado/PoolManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ namespace Ydb.Sdk.Ado;
66
internal static class PoolManager
77
{
88
private static readonly SemaphoreSlim SemaphoreSlim = new(1); // async mutex
9-
10-
private static ConcurrentDictionary<string, SessionPool> Pools { get; } = new();
9+
private static readonly ConcurrentDictionary<string, SessionPool> Pools = new();
1110

1211
internal static async Task<Session> GetSession(YdbConnectionStringBuilder connectionString)
1312
{

src/Ydb.Sdk/src/Ado/YdbCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ protected override async Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBeha
181181

182182
var execSettings = CommandTimeout > 0
183183
? new ExecuteQuerySettings { TransportTimeout = TimeSpan.FromSeconds(CommandTimeout) }
184-
: ExecuteQuerySettings.DefaultInstance;
184+
: new ExecuteQuerySettings();
185185

186186
var ydbDataReader = await YdbDataReader.CreateYdbDataReader(YdbConnection.Session.ExecuteQuery(
187187
preparedSql.ToString(), ydbParameters, execSettings, Transaction?.TransactionControl),

src/Ydb.Sdk/src/Ado/YdbConnection.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,39 @@ protected override YdbCommand CreateDbCommand()
164164
return CreateDbCommand();
165165
}
166166

167+
public override DataTable GetSchema()
168+
{
169+
return GetSchemaAsync().GetAwaiter().GetResult();
170+
}
171+
172+
public override DataTable GetSchema(string collectionName)
173+
{
174+
return GetSchemaAsync(collectionName).GetAwaiter().GetResult();
175+
}
176+
177+
public override DataTable GetSchema(string collectionName, string?[] restrictionValues)
178+
{
179+
return GetSchemaAsync(collectionName, restrictionValues).GetAwaiter().GetResult();
180+
}
181+
182+
public override Task<DataTable> GetSchemaAsync(CancellationToken cancellationToken = default)
183+
{
184+
return GetSchemaAsync("MetaDataCollections", cancellationToken);
185+
}
186+
187+
public override Task<DataTable> GetSchemaAsync(string collectionName, CancellationToken cancellationToken = default)
188+
{
189+
return GetSchemaAsync(collectionName, new string[4], cancellationToken);
190+
}
191+
192+
public override Task<DataTable> GetSchemaAsync(
193+
string collectionName,
194+
string?[] restrictionValues,
195+
CancellationToken cancellationToken = default)
196+
{
197+
return YdbSchema.GetSchemaAsync(this, collectionName, restrictionValues, cancellationToken);
198+
}
199+
167200
internal void EnsureConnectionOpen()
168201
{
169202
if (ConnectionState == ConnectionState.Closed)

src/Ydb.Sdk/src/Ado/YdbDataReader.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public sealed class YdbDataReader : DbDataReader, IAsyncEnumerable<YdbDataRecord
1111
private readonly IAsyncEnumerator<ExecuteQueryResponsePart> _stream;
1212
private readonly YdbTransaction? _ydbTransaction;
1313
private readonly RepeatedField<IssueMessage> _issueMessagesInStream = new();
14-
private readonly Action<Status> _onStatus;
14+
private readonly Action<Status> _onNotSuccessStatus;
1515

1616
private int _currentRowIndex = -1;
1717
private long _resultSetIndex = -1;
@@ -51,11 +51,11 @@ private interface IMetadata
5151

5252
private YdbDataReader(
5353
IAsyncEnumerator<ExecuteQueryResponsePart> resultSetStream,
54-
Action<Status> onStatus,
54+
Action<Status> onNotSuccessStatus,
5555
YdbTransaction? ydbTransaction)
5656
{
5757
_stream = resultSetStream;
58-
_onStatus = onStatus;
58+
_onNotSuccessStatus = onNotSuccessStatus;
5959
_ydbTransaction = ydbTransaction;
6060
}
6161

@@ -489,7 +489,7 @@ private async Task<State> NextExecPart()
489489

490490
var status = Status.FromProto(part.Status, _issueMessagesInStream);
491491

492-
_onStatus(status);
492+
_onNotSuccessStatus(status);
493493

494494
throw new YdbException(status);
495495
}
@@ -515,7 +515,7 @@ private async Task<State> NextExecPart()
515515
{
516516
OnFailReadStream();
517517

518-
_onStatus(e.Status);
518+
_onNotSuccessStatus(e.Status);
519519

520520
throw new YdbException(e.Status);
521521
}

src/Ydb.Sdk/src/Ado/YdbException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ public YdbException(Status status) : base(status.ToString())
2222
// TODO: Add SQLSTATE message with order with https://en.wikipedia.org/wiki/SQLSTATE
2323
}
2424

25+
public YdbException(string message, Status status) : base(message + ": " + status)
26+
{
27+
Code = status.StatusCode;
28+
var policy = RetrySettings.DefaultInstance.GetRetryRule(status.StatusCode).Policy;
29+
30+
IsTransient = policy == RetryPolicy.Unconditional;
31+
IsTransientWhenIdempotent = policy != RetryPolicy.None;
32+
// TODO: Add SQLSTATE message with order with https://en.wikipedia.org/wiki/SQLSTATE
33+
}
34+
2535
public override bool IsTransient { get; }
2636

2737
public bool IsTransientWhenIdempotent { get; }

0 commit comments

Comments
 (0)