This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new e368dc7e84 IGNITE-18609 .NET: Add ContainsKey method to Record API
(#1637)
e368dc7e84 is described below
commit e368dc7e844f176bf83e2793735d9a4f27378955
Author: Pavel Tupitsyn <[email protected]>
AuthorDate: Mon Feb 6 13:31:14 2023 +0200
IGNITE-18609 .NET: Add ContainsKey method to Record API (#1637)
* `IRecordView` does not have `Contains`, and `KeyValueView` has one. Add
the missing method.
* Use `ContainsKey` name to stress the fact that only key part of the
record is checked (which is evident from the signature in `KeyValueView`, but
not in `RecordView`).
---
.../Table/RecordViewBinaryTests.cs | 13 +++++
.../Table/RecordViewPocoTests.cs | 13 +++++
.../Transactions/TransactionsTests.cs | 1 -
.../Apache.Ignite/Internal/Table/KeyValueView.cs | 2 +-
.../Apache.Ignite/Internal/Table/RecordView.cs | 64 ++++++++++------------
.../dotnet/Apache.Ignite/Table/IKeyValueView.cs | 2 +-
.../dotnet/Apache.Ignite/Table/IRecordView.cs | 11 ++++
7 files changed, 67 insertions(+), 39 deletions(-)
diff --git
a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewBinaryTests.cs
b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewBinaryTests.cs
index 553ca549be..c610c300a5 100644
---
a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewBinaryTests.cs
+++
b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewBinaryTests.cs
@@ -584,5 +584,18 @@ namespace Apache.Ignite.Tests.Table
Assert.AreEqual(tuple["Time"], res["Time"]);
Assert.AreEqual(tuple["DateTime"], res["DateTime"]);
}
+
+ [Test]
+ public async Task TestContainsKey()
+ {
+ var keyTuple = GetTuple(1);
+ var tuple = GetTuple(1, "foo");
+
+ await TupleView.UpsertAsync(null, tuple);
+
+ Assert.IsTrue(await TupleView.ContainsKeyAsync(null, keyTuple));
+ Assert.IsTrue(await TupleView.ContainsKeyAsync(null, tuple));
+ Assert.IsFalse(await TupleView.ContainsKeyAsync(null,
GetTuple(-128)));
+ }
}
}
diff --git
a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewPocoTests.cs
b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewPocoTests.cs
index f9d862b738..cd214150ff 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewPocoTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/RecordViewPocoTests.cs
@@ -782,6 +782,19 @@ namespace Apache.Ignite.Tests.Table
ex!.Message);
}
+ [Test]
+ public async Task TestContainsKey()
+ {
+ var keyPoco = GetPoco(1);
+ var poco = GetPoco(1, "foo");
+
+ await PocoView.UpsertAsync(null, poco);
+
+ Assert.IsTrue(await PocoView.ContainsKeyAsync(null, keyPoco));
+ Assert.IsTrue(await PocoView.ContainsKeyAsync(null, poco));
+ Assert.IsFalse(await PocoView.ContainsKeyAsync(null,
GetPoco(-128)));
+ }
+
// ReSharper disable once NotAccessedPositionalProperty.Local
private record UnsupportedByteType(byte Int8);
}
diff --git
a/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
b/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
index 694af4d5f5..f7f8762779 100644
---
a/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
+++
b/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
@@ -18,7 +18,6 @@
namespace Apache.Ignite.Tests.Transactions
{
using System;
- using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using System.Transactions;
diff --git
a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/KeyValueView.cs
b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/KeyValueView.cs
index 00afaa7b62..f05667274f 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/KeyValueView.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/KeyValueView.cs
@@ -72,7 +72,7 @@ internal sealed class KeyValueView<TK, TV> :
IKeyValueView<TK, TV>
/// <inheritdoc/>
public async Task<bool> ContainsAsync(ITransaction? transaction, TK key) =>
- await _recordView.ContainsKey(transaction,
ToKv(key)).ConfigureAwait(false);
+ await _recordView.ContainsKeyAsync(transaction,
ToKv(key)).ConfigureAwait(false);
/// <inheritdoc/>
public async Task PutAsync(ITransaction? transaction, TK key, TV val) =>
diff --git
a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/RecordView.cs
b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/RecordView.cs
index be00e323c2..b5fa21e564 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/RecordView.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/RecordView.cs
@@ -76,6 +76,23 @@ namespace Apache.Ignite.Internal.Table
/// </summary>
public Sql Sql => _sql;
+ /// <inheritdoc/>
+ public IQueryable<T> AsQueryable(ITransaction? transaction = null,
QueryableOptions? options = null)
+ {
+ var executor = new IgniteQueryExecutor(_sql, transaction, options);
+ var provider = new IgniteQueryProvider(IgniteQueryParser.Instance,
executor, _table.Name);
+
+ if (typeof(T).IsKeyValuePair())
+ {
+ throw new NotSupportedException(
+ $"Can't use {typeof(KeyValuePair<,>)} for LINQ queries: " +
+ $"it is reserved for
{typeof(IKeyValueView<,>)}.{nameof(IKeyValueView<int, int>.AsQueryable)}. " +
+ "Use a custom type instead.");
+ }
+
+ return new IgniteQueryable<T>(provider);
+ }
+
/// <inheritdoc/>
public async Task<Option<T>> GetAsync(ITransaction? transaction, T key)
{
@@ -87,6 +104,15 @@ namespace Apache.Ignite.Internal.Table
return _ser.ReadValue(resBuf, resSchema, key);
}
+ /// <inheritdoc/>
+ public async Task<bool> ContainsKeyAsync(ITransaction? transaction, T
key)
+ {
+ IgniteArgumentCheck.NotNull(key, nameof(key));
+
+ using var resBuf = await
DoRecordOutOpAsync(ClientOp.TupleContainsKey, transaction, key, keyOnly:
true).ConfigureAwait(false);
+ return resBuf.GetReader().ReadBoolean();
+ }
+
/// <inheritdoc/>
public async Task<IList<Option<T>>> GetAllAsync(ITransaction?
transaction, IEnumerable<T> keys) =>
await GetAllAsync(
@@ -297,23 +323,6 @@ namespace Apache.Ignite.Internal.Table
public async Task<IList<T>> DeleteAllExactAsync(ITransaction?
transaction, IEnumerable<T> records) =>
await DeleteAllAsync(transaction, records, exact:
true).ConfigureAwait(false);
- /// <inheritdoc/>
- public IQueryable<T> AsQueryable(ITransaction? transaction = null,
QueryableOptions? options = null)
- {
- var executor = new IgniteQueryExecutor(_sql, transaction, options);
- var provider = new IgniteQueryProvider(IgniteQueryParser.Instance,
executor, _table.Name);
-
- if (typeof(T).IsKeyValuePair())
- {
- throw new NotSupportedException(
- $"Can't use {typeof(KeyValuePair<,>)} for LINQ queries: " +
- $"it is reserved for
{typeof(IKeyValueView<,>)}.{nameof(IKeyValueView<int, int>.AsQueryable)}. " +
- "Use a custom type instead.");
- }
-
- return new IgniteQueryable<T>(provider);
- }
-
/// <summary>
/// Deletes multiple records. If one or more keys do not exist, other
records are still deleted.
/// </summary>
@@ -324,7 +333,7 @@ namespace Apache.Ignite.Internal.Table
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains records from <paramref name="records"/>
that did not exist.
/// </returns>
- public async Task<IList<T>> DeleteAllAsync(ITransaction? transaction,
IEnumerable<T> records, bool exact) =>
+ internal async Task<IList<T>> DeleteAllAsync(ITransaction?
transaction, IEnumerable<T> records, bool exact) =>
await DeleteAllAsync(
transaction,
records,
@@ -347,7 +356,7 @@ namespace Apache.Ignite.Internal.Table
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains records from <paramref name="records"/>
that did not exist.
/// </returns>
- public async Task<TRes> DeleteAllAsync<TRes>(
+ internal async Task<TRes> DeleteAllAsync<TRes>(
ITransaction? transaction,
IEnumerable<T> records,
Func<int, TRes> resultFactory,
@@ -383,23 +392,6 @@ namespace Apache.Ignite.Internal.Table
addAction: addAction);
}
- /// <summary>
- /// Determines if the table contains an entry for the specified key.
- /// </summary>
- /// <param name="transaction">Transaction.</param>
- /// <param name="key">Key.</param>
- /// <returns>
- /// A <see cref="Task"/> representing the asynchronous operation.
- /// The task result contains a value indicating whether a record with
the specified key exists in the table.
- /// </returns>
- internal async Task<bool> ContainsKey(ITransaction? transaction, T key)
- {
- IgniteArgumentCheck.NotNull(key, nameof(key));
-
- using var resBuf = await
DoRecordOutOpAsync(ClientOp.TupleContainsKey, transaction, key, keyOnly:
true).ConfigureAwait(false);
- return resBuf.GetReader().ReadBoolean();
- }
-
private async Task<PooledBuffer> DoOutInOpAsync(
ClientOp clientOp,
Transaction? tx,
diff --git a/modules/platforms/dotnet/Apache.Ignite/Table/IKeyValueView.cs
b/modules/platforms/dotnet/Apache.Ignite/Table/IKeyValueView.cs
index 549830fdd6..5b60e08fae 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Table/IKeyValueView.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Table/IKeyValueView.cs
@@ -60,7 +60,7 @@ public interface IKeyValueView<TK, TV>
/// Determines if the table contains an entry for the specified key.
/// </summary>
/// <param name="transaction">The transaction or <c>null</c> to auto
commit.</param>
- /// <param name="key">Keys.</param>
+ /// <param name="key">Key.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result is <c>true</c> if a value exists for the specified
key, and <c>false</c> otherwise.
diff --git a/modules/platforms/dotnet/Apache.Ignite/Table/IRecordView.cs
b/modules/platforms/dotnet/Apache.Ignite/Table/IRecordView.cs
index 40c865bd81..83b17763b6 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Table/IRecordView.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Table/IRecordView.cs
@@ -41,6 +41,17 @@ namespace Apache.Ignite.Table
/// </returns>
Task<Option<T>> GetAsync(ITransaction? transaction, T key);
+ /// <summary>
+ /// Determines if the table contains an entry for the specified key.
+ /// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto
commit.</param>
+ /// <param name="key">A record with key columns set.</param>
+ /// <returns>
+ /// A <see cref="Task"/> representing the asynchronous operation.
+ /// The task result is <c>true</c> if a value exists for the specified
key, and <c>false</c> otherwise.
+ /// </returns>
+ Task<bool> ContainsKeyAsync(ITransaction? transaction, T key);
+
/// <summary>
/// Gets multiple records by keys.
/// </summary>