I am doing linq over tables I created using sql api.
I created the table:
var cfg = new CacheClientConfiguration(
"PUBLIC",
new QueryEntity(typeof(object), typeof(object)))
{
SqlSchema = "PUBLIC",
CacheMode = CacheMode.Partitioned
};
var cache = cli.GetOrCreateCache<object, object>(cfg);
cache.Query(new SqlFieldsQuery(@"
CREATE TABLE IF NOT EXISTS Things
(
Id UUID,
Name VARCHAR,
EffectiveDate TIMESTAMP,
PRIMARY KEY(Id)
)
WITH ""TEMPLATE = PARTITIONED,
CACHE_NAME = consoleappserver.Thing,
VALUE_TYPE = consoleappserver.Thing""
")).GetAll();
I put some seed data:
cache.Query(new SqlFieldsQuery(@"
INSERT INTO Things (Id, Name, EffectiveDate) VALUES (?,?,?)",
Guid.NewGuid(), "Test Name 1", DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Utc))).GetAll();
cache.Query(new SqlFieldsQuery(@"
INSERT INTO Things (Id, Name, EffectiveDate) VALUES (?,?,?)",
Guid.NewGuid(), "Test Name 2", DateTime.SpecifyKind(DateTime.Today.AddDays(1), DateTimeKind.Utc))).GetAll();
cache.Query(new SqlFieldsQuery(@"
INSERT INTO Things (Id, Name, EffectiveDate) VALUES (?,?,?)",
Guid.NewGuid(), "Test Name 3", DateTime.SpecifyKind(DateTime.Today.AddDays(2), DateTimeKind.Utc))).GetAll();
Here is my linq query:
var cache = cli.GetCache<Guid, Thing>("consoleappserver.Thing");
var things = cache.AsCacheQueryable();
var effectiveDate = DateTime.SpecifyKind(DateTime.Today, DateTimeKind.Utc);
things = things.Where(t => t.Value.EffectiveDate <= effectiveDate);
foreach (var kv in things)
{
Console.WriteLine("Things #{0} '{1}'", kv.Value.Id, kv.Value.Name);
}
Here is the C# class I use for mapping:
public class Thing
{
[QuerySqlField(Name = "ID")]
public Guid Id { get; set; }
[QuerySqlField(Name = "NAME")]
public string Name { get; set; }
[QuerySqlField(Name = "EFFECTIVEDATE")]
public DateTime EffectiveDate { get; set; }
}
And here is the error I get when I try to iterate over things:
Apache.Ignite.Core.Client.IgniteClientException:
'Failed to resolve Java class 'consoleappserver.Thing' in .NET [platformId=1, typeId=298456301].'
Here is the full error logged:
[11:00:18,731][SEVERE][client-connector-#110][ClientListenerNioListener] Failed to process client request [req=o.a.i.i.processors.platform.client.binary.ClientBinaryTypeNameGetRequest@250d2f65] class org.apache.ignite.IgniteException: Failed to resolve Java class 'consoleappserver.Thing' in .NET [platformId=1, typeId=298456301]. at org.apache.ignite.internal.processors.platform.client.binary.ClientBinaryTypeNameGetRequest.process(ClientBinaryTypeNameGetRequest.java:57) at org.apache.ignite.internal.processors.platform.client.ClientRequestHandler.handle(ClientRequestHandler.java:93) at org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:202) at org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:58) at org.apache.ignite.internal.util.nio.GridNioFilterChain$TailFilter.onMessageReceived(GridNioFilterChain.java:278) at org.apache.ignite.internal.util.nio.GridNioFilterAdapter.proceedMessageReceived(GridNioFilterAdapter.java:108) at org.apache.ignite.internal.util.nio.GridNioAsyncNotifyFilter$3.body(GridNioAsyncNotifyFilter.java:135) at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:119) at org.apache.ignite.internal.util.worker.GridWorkerPool$1.run(GridWorkerPool.java:69) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.lang.ClassNotFoundException: Failed to resolve Java class 'consoleappserver.Thing' in .NET [platformId=1, typeId=298456301]. at org.apache.ignite.internal.MarshallerContextImpl.getClassName(MarshallerContextImpl.java:400) at org.apache.ignite.internal.MarshallerContextImpl.getClassName(MarshallerContextImpl.java:333) at org.apache.ignite.internal.processors.platform.client.binary.ClientBinaryTypeNameGetRequest.process(ClientBinaryTypeNameGetRequest.java:52) ... 11 more
CodePudding user response:
Since the table is defined with SQL, Thing
type is not known to Ignite. Use the following call before the query to force binary type registration:
cli.GetBinary().GetBinaryType(typeof(Thing));
This call can be done once per client instance after Ignition.StartClient
.