gpt4 book ai didi

c# - Apache Ignite.NET LINQ 失败

转载 作者:行者123 更新时间:2023-11-30 21:37:02 24 4
gpt4 key购买 nike

使用 Apache Ignite .NET 2.3.0

尝试使用 Linq 扩展 (Apache.Ignite.Linq) 进行搜索。

这是一个 IgniteConfig:

{
ClientMode = false,
JvmInitialMemoryMb = 512,
JvmMaxMemoryMb = 512,
MetricsLogFrequency = TimeSpan.Zero, // disable metrics output
DataStorageConfiguration = new Apache.Ignite.Core.Configuration.DataStorageConfiguration()
{
DefaultDataRegionConfiguration = new DataRegionConfiguration()
{
Name = "DefaultRegion",
PersistenceEnabled = true
},
StoragePath = _config.Value.Ignite.PersistentStoragePath
},
CacheConfiguration = new[]
{
new CacheConfiguration
{
Name = "securitiesItemsCache",
ReadThrough = false,
WriteThrough = false,
CacheMode = CacheMode.Replicated,
DataRegionName = "DefaultRegion",
QueryEntities = new []
{
new QueryEntity(typeof(string), typeof(SecuritiesItem))
}
}

}

获取缓存:

_securitiesCache = _ignite.GetOrCreateCache<string, SecuritiesItem>("securitiesItemsCache");

像这样搜索:

_securitiesCache
.AsCacheQueryable()
.Where(s => s.Value.SearchString.Contains(query))
.ToArray()
.Select(x => x.Value);

在这种情况下收到异常:

Apache.Ignite.Core.Common.IgniteException HResult=0x80131500
Message=Failed to parse query: select _T0._KEY, _T0._VAL from "securitiesItemsCache".SECURITIESITEM as _T0 where (_T0.SearchString like '%' || ? || '%') Source=Apache.Ignite.Core StackTrace: at Apache.Ignite.Core.Impl.Unmanaged.UnmanagedCallbacks.Error(Void* target, Int32 errType, SByte* errClsChars, Int32 errClsCharsLen, SByte* errMsgChars, Int32 errMsgCharsLen, SByte* stackTraceChars, Int32 stackTraceCharsLen, Void* errData, Int32 errDataLen) at Apache.Ignite.Core.Impl.Unmanaged.IgniteJniNativeMethods.TargetInStreamOutObject(Void* ctx, Void* target, Int32 opType, Int64 memPtr) at Apache.Ignite.Core.Impl.PlatformJniTarget.InStreamOutObject(Int32 type, Action1 writeAction) at
Apache.Ignite.Core.Impl.Cache.CacheImpl
2.QueryFields[T](SqlFieldsQuery qry, Func3 readerFunc) at
Remotion.Linq.Clauses.StreamedData.StreamedSequenceInfo.ExecuteQueryModel(QueryModel
queryModel, IQueryExecutor executor) at
Apache.Ignite.Linq.Impl.CacheFieldsQueryProvider.Execute[TResult](Expression
expression) at Remotion.Linq.QueryableBase
1.GetEnumerator() at System.Collections.Generic.LargeArrayBuilder1.AddRange(IEnumerable1 items) at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable1
source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable
1 source) at Core.IgniteServer.SearchSecurities(String query) in C:\development\ISSDPService\Core\IgniteServer.cs:line 138 at WebService.Providers.IgniteProvider.Search(String query, LanguagePrefix lang) in C:\development\ISSDPService\WebService\Providers\IgniteProvider.cs:line 78 at WebService.Controllers.SecuritiesController.Search(String query) in C:\development\ISSDPService\WebService\Controllers\SecuritiesController.cs:line 47 at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext()

Inner Exception 1: JavaException: class org.apache.ignite.IgniteCheckedException: Failed to parse query: select _T0._KEY, _T0._VAL from "securitiesItemsCache".SECURITIESITEM as _T0 where (_T0.SearchString like '%' || ? || '%') at org.apache.ignite.internal.processors.platform.utils.PlatformUtils.unwrapQueryException(PlatformUtils.java:519) at org.apache.ignite.internal.processors.platform.cache.PlatformCache.runFieldsQuery(PlatformCache.java:1240) at org.apache.ignite.internal.processors.platform.cache.PlatformCache.processInStreamOutObject(PlatformCache.java:877) at org.apache.ignite.internal.processors.platform.PlatformTargetProxyImpl.inStreamOutObject(PlatformTargetProxyImpl.java:79) Caused by: javax.cache.CacheException: class org.apache.ignite.internal.processors.query.IgniteSQLException: Failed to parse query: select _T0._KEY, _T0._VAL from "securitiesItemsCache".SECURITIESITEM as _T0 where (_T0.SearchString like '%' || ? || '%') at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.query(IgniteCacheProxyImpl.java:597) at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.query(GatewayProtectedCacheProxy.java:368) at org.apache.ignite.internal.processors.platform.cache.PlatformCache.runFieldsQuery(PlatformCache.java:1234) ... 2 more Caused by: class org.apache.ignite.internal.processors.query.IgniteSQLException: Failed to parse query: select _T0._KEY, _T0._VAL from "securitiesItemsCache".SECURITIESITEM as _T0 where (_T0.SearchString like '%' || ? || '%') at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryDistributedSqlFields(IgniteH2Indexing.java:1385) at org.apache.ignite.internal.processors.query.GridQueryProcessor$5.applyx(GridQueryProcessor.java:1909) at org.apache.ignite.internal.processors.query.GridQueryProcessor$5.applyx(GridQueryProcessor.java:1907) at org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:36) at org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:2445) at org.apache.ignite.internal.processors.query.GridQueryProcessor.querySqlFields(GridQueryProcessor.java:1914) at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.query(IgniteCacheProxyImpl.java:585) ... 4 more Caused by: org.h2.jdbc.JdbcSQLException: Столбец "_T0.SEARCHSTRING" не найден Column "_T0.SEARCHSTRING" not found; SQL statement: select _T0._KEY, _T0._VAL from "securitiesItemsCache".SECURITIESITEM as _T0 where (_T0.SearchString like '%' || ? || '%') [42122-195] at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) at org.h2.message.DbException.get(DbException.java:179) at org.h2.message.DbException.get(DbException.java:155) at org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:147) at org.h2.expression.CompareLike.optimize(CompareLike.java:93) at org.h2.command.dml.Select.prepare(Select.java:842) at org.h2.command.Parser.prepareCommand(Parser.java:262) at org.h2.engine.Session.prepareLocal(Session.java:573) at org.h2.engine.Session.prepareCommand(Session.java:514) at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1204) at org.h2.jdbc.JdbcPreparedStatement.(JdbcPreparedStatement.java:73) at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:288) at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.prepareStatement(IgniteH2Indexing.java:402) at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryDistributedSqlFields(IgniteH2Indexing.java:1365) ... 10 more

它说:

Column "_T0.SEARCHSTRING" not found; SQL statement:

但是 new QueryEntity(typeof(string), typeof(SecuritiesItem)) 还不够吗?

已解决

以编程方式添加字段说明:

Fields = new []
{
new QueryField { Name = "SearchString", FieldType = typeof(string)}
}

另一个问题

如果查询仅包含英文字母,则搜索效果很好。但是,如果我输入俄语字符,则什么也找不到。我应该将文本转换为特定的编码吗?

最佳答案

Column "_T0.SEARCHSTRING" not found

您应该使用 [QuerySqlField] 标记 SearchString 属性。

SQL 是可选的,您应该明确配置哪些字段应该在查询中可用。参见 https://apacheignite-sql.readme.io/docs/net-schema-and-indexes .

关于c# - Apache Ignite.NET LINQ 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47694635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com