Apache.Ignite.LINQ如何查询密钥

时间:2018-03-16 20:00:27

标签: .net apache ignite

是否可以查询缓存并在where条件下限制密钥?以下示例已简化:

using (var ignite = Ignition.Start())
{
    var cache = ignite.GetOrCreateCache<int, string>(new CacheConfiguration("test-cache", typeof(string)));

    cache.Put(1, "abc");
    cache.Put(2, "abc2");

    // The next line works
    var resultOnValue = cache.AsCacheQueryable().Where(m => m.Value.EndsWith("2")).ToArray();
    // The next line throws an exception
    var resultOnKey = cache.AsCacheQueryable().Where(m => m.Key > 1).ToArray();
}

javax.cache。 CacheException 无法远程运行地图查询。     at org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor.query(GridReduceQueryExecutor.java:748)     在org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing $ 8.iterator(IgniteH2Indexing.java:1212)     在org.apache.ignite.internal.processors.cache.QueryCursorImpl.iterator(QueryCursorImpl.java:95)     在org.apache.ignite.internal.processors.platform.cache.query.PlatformAbstractQueryCursor.processInLongOutLong(PlatformAbstractQueryCursor.java:147)     在org.apache.ignite.internal.processors.platform.PlatformTargetProxyImpl.inLongOutLong(PlatformTargetProxyImpl.java:55) 引发者:javax.cache.CacheException:无法在节点上执行映射查询:5917e973-9eb8-4ae6-8dc7-69788d29c518,类org.apache.ignite.IgniteCheckedException:无法执行SQL查询。     在org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor.fail(GridReduceQueryExecutor.java:274)     at org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor.onFail(GridReduceQueryExecutor.java:264)     在org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor.onMessage(GridReduceQueryExecutor.java:243)     at org.apache.ignite.internal.processors.query.h2.twostep.GridMapQueryExecutor.sendError(GridMapQueryExecutor.java:854)     at org.apache.ignite.internal.processors.query.h2.twostep.GridMapQueryExecutor.onQueryRequest0(GridMapQueryExecutor.java:731)     at org.apache.ignite.internal.processors.query.h2.twostep.GridMapQueryExecutor.onQueryRequest(GridMapQueryExecutor.java:516)     at org.apache.ignite.internal.processors.query.h2.twostep.GridMapQueryExecutor.onMessage(GridMapQueryExecutor.java:214)     在org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor $ 1.applyx(GridReduceQueryExecutor.java:153)     在org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor $ 1.applyx(GridReduceQueryExecutor.java:151)     在org.apache.ignite.internal.util.lang.IgniteInClosure2X.apply(IgniteInClosure2X.java:38)     在org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.send(IgniteH2Indexing.java:2191)     在org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor.send(GridReduceQueryExecutor.java:1420)     在org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor.query(GridReduceQueryExecutor.java:733)     ......还有4个

1 个答案:

答案 0 :(得分:3)

解决方案:使用QueryEntity并定义密钥和值的类型。

var cache = ignite.GetOrCreateCache<int, string>
    (new CacheConfiguration("test-cache", 
        new QueryEntity(typeof(int), typeof(string))));