Skip to content

Commit 6478818

Browse files
feat: support ADO.NET GetSchema & dev: fixes (#247)
- Supported in ADO.NET GetSchema(Async). CollectionNames: * Tables * TablesWithCollections * DataSourceInformation * MetaDataCollections * Restrictions - Rename field _onStatus -> _onNotSuccessStatus in YdbDataReader - If session is not active, do not invoke DeleteSession(session) - AttachStream: connect stream using NodeId - PoolManager: change pool properties on field - Delete *Settings.DefaultInstance because it's a singleton object that's changed by tasks when NodeId is set - DbConnection.Session.OnStatus(status) in YdbTransaction
1 parent cf223c3 commit 6478818

File tree

13 files changed

+649
-80
lines changed

13 files changed

+649
-80
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
- Supported in ADO.NET GetSchema(Async). CollectionNames:
2+
* Tables
3+
* TablesWithCollections
4+
* DataSourceInformation
5+
* MetaDataCollections
6+
* Restrictions
7+
- Rename field _onStatus -> _onNotSuccessStatus in YdbDataReader
8+
- If session is not active, do not invoke DeleteNotActiveSession(session)
9+
- AttachStream: connect stream using NodeId
10+
- PoolManager: change pool properties on field
11+
- Delete *Settings.DefaultInstance because it's a singleton object that's changed by tasks when NodeId is set
12+
- DbConnection.Session.OnStatus(status) in YdbTransaction
13+
114
## v0.9.4
215
- Do not pessimize the node on Grpc.Core.StatusCode.Cancelled and Grpc.Core.StatusCode.DeadlineExceeded.
316
- Dispose of WriterSession using dispose CancellationToken.

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
}

0 commit comments

Comments
 (0)