Apache Ignite Linq Sql 无法解析 java class

Apache Ignite Linq over Sql Failed to resolve java class

我正在对使用 sql api.api 创建的 tables 进行 linq

我创建了 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();

我放了一些种子数据:

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();

这是我的 linq 查询:

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);
}

这是我用于映射的 C# class:

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; }
}

这是我在尝试遍历 things:

时遇到的错误

Apache.Ignite.Core.Client.IgniteClientException:
'Failed to resolve Java class 'consoleappserver.Thing' in .NET [platformId=1, typeId=298456301].'

这是记录的完整错误:

[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.body(GridNioAsyncNotifyFilter.java:135) at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:119) at org.apache.ignite.internal.util.worker.GridWorkerPool.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

由于 table 是用 SQL 定义的,Thing 类型对于 Ignite 是未知的。在查询之前使用以下调用强制注册二进制类型:

cli.GetBinary().GetBinaryType(typeof(Thing));

此调用可以在 Ignition.StartClient 之后对每个客户端实例执行一次。