You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2021/11/02 20:44:01 UTC
[ignite] branch ignite-2.12 updated: IGNITE-15820 .NET: Fix thin
client streamer not creating SQL table entries (#9531)
This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch ignite-2.12
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/ignite-2.12 by this push:
new 046f626 IGNITE-15820 .NET: Fix thin client streamer not creating SQL table entries (#9531)
046f626 is described below
commit 046f626f5d70c53cd22e9007834e5f7e583c394d
Author: timotheuspreisinger <30...@users.noreply.github.com>
AuthorDate: Tue Nov 2 21:35:27 2021 +0100
IGNITE-15820 .NET: Fix thin client streamer not creating SQL table entries (#9531)
* Fix BinaryObject handling in ClientDataStreamerReader.
* Fix BinaryObject hash code calculation in .NET thin client.
(cherry picked from commit 0f3102bb905f94aa978413ec3f3e7fd70768c02f)
---
.../client/streamer/ClientDataStreamerReader.java | 3 +
.../Client/Datastream/DataStreamerClientTest.cs | 72 ++++++++++++++++++++++
.../Dataload/DataStreamerTest.cs | 62 +++++++++++++++++++
.../Impl/Binary/BinaryHashCodeUtils.cs | 5 ++
4 files changed, 142 insertions(+)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/streamer/ClientDataStreamerReader.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/streamer/ClientDataStreamerReader.java
index 028d89e..8acc992 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/streamer/ClientDataStreamerReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/streamer/ClientDataStreamerReader.java
@@ -66,6 +66,9 @@ class ClientDataStreamerReader {
if (obj == null)
return null;
+ if (obj instanceof CacheObject)
+ return (T) obj;
+
int pos1 = in.position();
in.position(pos0);
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Datastream/DataStreamerClientTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Datastream/DataStreamerClientTest.cs
index 06f7ff8..28c0e32 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Datastream/DataStreamerClientTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Datastream/DataStreamerClientTest.cs
@@ -26,8 +26,10 @@ namespace Apache.Ignite.Core.Tests.Client.Datastream
using Apache.Ignite.Core.Binary;
using Apache.Ignite.Core.Cache;
using Apache.Ignite.Core.Cache.Configuration;
+ using Apache.Ignite.Core.Cache.Query;
using Apache.Ignite.Core.Cache.Store;
using Apache.Ignite.Core.Client;
+ using Apache.Ignite.Core.Client.Cache;
using Apache.Ignite.Core.Client.Datastream;
using Apache.Ignite.Core.Common;
using Apache.Ignite.Core.Datastream;
@@ -686,6 +688,76 @@ namespace Apache.Ignite.Core.Tests.Client.Datastream
StringAssert.StartsWith("Cache does not exist", inner.Message);
}
+ /// <summary>
+ /// Tests that streaming binary objects with a thin client results in those objects being
+ /// available through SQL in the cache's table.
+ /// </summary>
+ [Test]
+ public void TestBinaryStreamerCreatesSqlRecord()
+ {
+ var cacheCfg = new CacheClientConfiguration
+ {
+ Name = "TestBinaryStreamerCreatesSqlRecord",
+ SqlSchema = "persons",
+ QueryEntities = new[]
+ {
+ new QueryEntity
+ {
+ KeyTypeName = "PersonKey",
+ ValueTypeName = "Person",
+ Fields = new List<QueryField>
+ {
+ new QueryField
+ {
+ Name = "Id",
+ FieldType = typeof(int),
+ IsKeyField = true
+ },
+ new QueryField
+ {
+ Name = "Name",
+ FieldType = typeof(string),
+ },
+ new QueryField
+ {
+ Name = "Age",
+ FieldType = typeof(int)
+ }
+ }
+ }
+ }
+ };
+
+ var cacheClientBinary = Client.GetOrCreateCache<int, IBinaryObject>(cacheCfg)
+ .WithKeepBinary<int, IBinaryObject>();
+
+ // Prepare a binary object.
+ var personKey = Client.GetBinary().GetBuilder("PersonKey")
+ .SetIntField("Id", 111)
+ .Build();
+
+ var person = Client.GetBinary().GetBuilder("Person")
+ .SetStringField("Name", "Jane")
+ .SetIntField("Age", 43)
+ .Build();
+
+ // Stream the binary object to the server.
+ using (var streamer = Client.GetDataStreamer<IBinaryObject, IBinaryObject>(cacheCfg.Name))
+ {
+ streamer.Add(personKey, person);
+ streamer.Flush();
+ }
+
+ // Check that SQL works.
+ var query = new SqlFieldsQuery("SELECT Id, Name, Age FROM \"PERSONS\".PERSON");
+ var fullResultAfterClientStreamer = cacheClientBinary.Query(query).GetAll();
+ Assert.IsNotNull(fullResultAfterClientStreamer);
+ Assert.AreEqual(1, fullResultAfterClientStreamer.Count);
+ Assert.AreEqual(111, fullResultAfterClientStreamer[0][0]);
+ Assert.AreEqual("Jane", fullResultAfterClientStreamer[0][1]);
+ Assert.AreEqual(43, fullResultAfterClientStreamer[0][2]);
+ }
+
#if NETCOREAPP
/// <summary>
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Dataload/DataStreamerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Dataload/DataStreamerTest.cs
index 3a7b0e2..3c8881f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Dataload/DataStreamerTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Dataload/DataStreamerTest.cs
@@ -25,6 +25,8 @@ namespace Apache.Ignite.Core.Tests.Dataload
using System.Threading.Tasks;
using Apache.Ignite.Core.Binary;
using Apache.Ignite.Core.Cache;
+ using Apache.Ignite.Core.Cache.Configuration;
+ using Apache.Ignite.Core.Cache.Query;
using Apache.Ignite.Core.Datastream;
using NUnit.Framework;
@@ -808,6 +810,66 @@ namespace Apache.Ignite.Core.Tests.Dataload
}
+ /// <summary>
+ /// Tests that streaming binary objects with a thin client results in those objects being
+ /// available through SQL in the cache's table.
+ /// </summary>
+ [Test]
+ public void TestBinaryStreamerCreatesSqlRecord()
+ {
+ var cacheCfg = new CacheConfiguration
+ {
+ Name = "TestBinaryStreamerCreatesSqlRecord",
+ SqlSchema = "persons",
+ QueryEntities = new[]
+ {
+ new QueryEntity
+ {
+ ValueTypeName = "Person",
+ Fields = new List<QueryField>
+ {
+ new QueryField
+ {
+ Name = "Name",
+ FieldType = typeof(string),
+ },
+ new QueryField
+ {
+ Name = "Age",
+ FieldType = typeof(int)
+ }
+ }
+ }
+ }
+ };
+
+ var cacheClientBinary = _grid.GetOrCreateCache<int, IBinaryObject>(cacheCfg)
+ .WithKeepBinary<int, IBinaryObject>();
+
+ // Prepare a binary object.
+ var jane = _grid.GetBinary().GetBuilder("Person")
+ .SetStringField("Name", "Jane")
+ .SetIntField("Age", 43)
+ .Build();
+
+ const int key = 1;
+
+ // Stream the binary object to the server.
+ using (var streamer = _grid.GetDataStreamer<int, IBinaryObject>(cacheCfg.Name))
+ {
+ streamer.Add(key, jane);
+ streamer.Flush();
+ }
+
+ // Check that SQL works.
+ var query = new SqlFieldsQuery("SELECT Name, Age FROM \"PERSONS\".PERSON");
+ var fullResultAfterClientStreamer = cacheClientBinary.Query(query).GetAll();
+ Assert.IsNotNull(fullResultAfterClientStreamer);
+ Assert.AreEqual(1, fullResultAfterClientStreamer.Count);
+ Assert.AreEqual("Jane", fullResultAfterClientStreamer[0][0]);
+ Assert.AreEqual(43, fullResultAfterClientStreamer[0][1]);
+ }
+
#if NETCOREAPP
/// <summary>
/// Tests async streamer usage.
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryHashCodeUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryHashCodeUtils.cs
index d7b5d77..213e90d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryHashCodeUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryHashCodeUtils.cs
@@ -113,6 +113,11 @@ namespace Apache.Ignite.Core.Impl.Binary
return GetArrayHashCode(val, marsh, affinityKeyFieldIds);
}
+ if (type == typeof(BinaryObject))
+ {
+ return val.GetHashCode();
+ }
+
// DateTime, when used as key, is always written as BinaryObject.
return GetComplexTypeHashCode(val, marsh, affinityKeyFieldIds);
}