Map/Reduce 上的 RavenDb,NullReferenceException
RavenDb, NullReferenceException on Map/Reduce
我正在使用最新版本的 RavenDb .Net Core 客户端和最新的服务器分发。
我正在尝试添加此索引:
this.Map = persons => from person in persons
let company = this.LoadDocument(person.ExternalEmployeeData.CompanyId)
select new
{
CompanyName = company != null ? company.Name : string.Empty,
CompanyRegisteredName = company != null ? company.RegisteredName : string.Empty,
person.FirstName,
person.Id,
person.LastName,
person.NationalInsuranceNumber
};
this.Reduce = models => from model in models
select new
{
model.CompanyName,
model.CompanyRegisteredName,
model.FirstName,
model.Id,
model.LastName,
model.NationalInsuranceNumber
};
如果我在没有 "Reduce" 块的情况下添加它,它会被添加但是在查询它时,输出中的 "CompanyName" 和 "CompanyRegisteredName" 属性始终为 null,尽管我可以过滤正确地超过他们。所以我想我需要 "Reduce" 函数。但是添加它会给我以下 NullReferenceException:
Raven.Client.Exceptions.Documents.Compilation.IndexCompilationException
HResult=0x80131500
Message=IndexCompilationException: Object reference not set to an instance of an object., IndexDefinitionProperty='Reduce', ProblematicText='results.Select(model => new {
CompanyName = model.CompanyName,
CompanyRegisteredName = model.CompanyRegisteredName,
FirstName = model.FirstName,
Id = model.Id,
LastName = model.LastName,
NationalInsuranceNumber = model.NationalInsuranceNumber
})' ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Raven.Server.Documents.Indexes.Static.IndexCompiler.HandleReduce(String reduce, FieldNamesValidator fieldNamesValidator, MethodDetectorRewriter methodsDetector, String[]& groupByFields) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 392
--- End of inner exception stack trace ---
at Raven.Server.Documents.Indexes.Static.IndexCompiler.HandleReduce(String reduce, FieldNamesValidator fieldNamesValidator, MethodDetectorRewriter methodsDetector, String[]& groupByFields) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 404
at Raven.Server.Documents.Indexes.Static.IndexCompiler.CreateClass(String name, IndexDefinition definition) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 267
at Raven.Server.Documents.Indexes.Static.IndexCompiler.Compile(IndexDefinition definition) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 73
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Raven.Server.Documents.Indexes.Static.IndexCompilationCache.GetIndexInstance(IndexDefinition definition) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompilationCache.cs:line 46
at Raven.Server.Documents.Indexes.IndexStore.d__23.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\IndexStore.cs:line 355
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Server.Documents.Handlers.Admin.AdminIndexHandler.d__0.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Handlers\Admin\AdminIndexHandler.cs:line 50
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Server.Routing.RequestRouter.d__7.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Routing\RequestRouter.cs:line 116
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Raven.Server.RavenServerStartup.d__11.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\RavenServerStartup.cs:line 161
Source=Raven.Client
StackTrace:
at Raven.Client.Exceptions.ExceptionDispatcher.d__3.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Exceptions\ExceptionDispatcher.cs:line 117
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.d__90`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 1014
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.d__75`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 806
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Raven.Client.Http.RequestExecutor.d__75`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 806
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.d__68`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 417
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Documents.Operations.MaintenanceOperationExecutor.d__13`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Documents\Operations\MaintenanceOperationExecutor.cs:line 64
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Util.AsyncHelpers.RunSync(Func`1 task) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Util\AsyncHelpers.cs:line 79
at MyProject.DataAccess.RavenDb.ServiceCollectionExtensions.ConfigureStore(IDocumentStore store) in C:\Sviluppo\steelchihuahua\MyProject.DataAccess.RavenDb\ServiceCollectionExtensions.cs:line 65
at MyProject.DataAccess.RavenDb.ServiceCollectionExtensions.InitializeDocumentStore(IServiceCollection services, Boolean isDevelopment, Boolean isStaging, Boolean isProduction, String contentRootPath, String certificatePath, String certificatePassword, String databaseName, String databaseUrl) in C:\Sviluppo\steelchihuahua\MyProject.DataAccess.RavenDb\ServiceCollectionExtensions.cs:line 45
at MyProject.RealTimeApi.Startup.ConfigureServices(IServiceCollection services) in C:\Sviluppo\steelchihuahua\MyProject.RealTimeApi\Startup.cs:line 41
对于这种异常,我不确定是我做错了什么,还是库中有错误,或者两者都有。
有人知道吗?
谢谢。
编辑:进一步试验我发现了更多问题。我一直在尝试添加一个非常简单的 map/reduce,但我遇到了一种新的(毫无意义的)错误,因为我已经返回了一个匿名对象。此外,如果我删除 "groupby" 语句(实际上并不需要),我将返回到 NullReferenceException:
不需要 Map-Reduce 索引。
Map-Reduce 用于执行数据聚合。
只需查看 company.Name(而不是仅查看 公司)如下:
this.Map = persons => from person in persons
let company = this.LoadDocument<T>(person.ExternalEmployeeData.CompanyId)
select new
{
// check on company.Name
CompanyName = company.Name != null ? company.Name : string.Empty,
CompanyRegisteredName = company.Name != null ? company.RegisteredName : string.Empty,
person.FirstName,
person.Id,
person.LastName,
person.NationalInsuranceNumber
};
事实证明,在 Map 定义之后,我所需要的是:
this.StoreAllFields(FieldStorage.Yes);
这会保留索引中的数据。然后我必须显式地投影我的查询,即使我已经使用索引输出作为我的 IQueryable 的类型 T:
var items = await pagedQuery.ProjectInto<TIndexOutput>()
不过,服务器报告的奇怪错误消息应该得到解决。 "NullReferenceException" 表示不应该出现的场景,RavenDB 单元测试未涵盖该场景。另外,当我已经这样做时,说我需要输出匿名类型的消息非常具有误导性。
我正在使用最新版本的 RavenDb .Net Core 客户端和最新的服务器分发。
我正在尝试添加此索引:
this.Map = persons => from person in persons
let company = this.LoadDocument(person.ExternalEmployeeData.CompanyId)
select new
{
CompanyName = company != null ? company.Name : string.Empty,
CompanyRegisteredName = company != null ? company.RegisteredName : string.Empty,
person.FirstName,
person.Id,
person.LastName,
person.NationalInsuranceNumber
};
this.Reduce = models => from model in models
select new
{
model.CompanyName,
model.CompanyRegisteredName,
model.FirstName,
model.Id,
model.LastName,
model.NationalInsuranceNumber
};
如果我在没有 "Reduce" 块的情况下添加它,它会被添加但是在查询它时,输出中的 "CompanyName" 和 "CompanyRegisteredName" 属性始终为 null,尽管我可以过滤正确地超过他们。所以我想我需要 "Reduce" 函数。但是添加它会给我以下 NullReferenceException:
Raven.Client.Exceptions.Documents.Compilation.IndexCompilationException
HResult=0x80131500
Message=IndexCompilationException: Object reference not set to an instance of an object., IndexDefinitionProperty='Reduce', ProblematicText='results.Select(model => new {
CompanyName = model.CompanyName,
CompanyRegisteredName = model.CompanyRegisteredName,
FirstName = model.FirstName,
Id = model.Id,
LastName = model.LastName,
NationalInsuranceNumber = model.NationalInsuranceNumber
})' ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Raven.Server.Documents.Indexes.Static.IndexCompiler.HandleReduce(String reduce, FieldNamesValidator fieldNamesValidator, MethodDetectorRewriter methodsDetector, String[]& groupByFields) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 392
--- End of inner exception stack trace ---
at Raven.Server.Documents.Indexes.Static.IndexCompiler.HandleReduce(String reduce, FieldNamesValidator fieldNamesValidator, MethodDetectorRewriter methodsDetector, String[]& groupByFields) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 404
at Raven.Server.Documents.Indexes.Static.IndexCompiler.CreateClass(String name, IndexDefinition definition) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 267
at Raven.Server.Documents.Indexes.Static.IndexCompiler.Compile(IndexDefinition definition) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 73
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Raven.Server.Documents.Indexes.Static.IndexCompilationCache.GetIndexInstance(IndexDefinition definition) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompilationCache.cs:line 46
at Raven.Server.Documents.Indexes.IndexStore.d__23.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\IndexStore.cs:line 355
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Server.Documents.Handlers.Admin.AdminIndexHandler.d__0.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Handlers\Admin\AdminIndexHandler.cs:line 50
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Server.Routing.RequestRouter.d__7.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Routing\RequestRouter.cs:line 116
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Raven.Server.RavenServerStartup.d__11.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\RavenServerStartup.cs:line 161
Source=Raven.Client
StackTrace:
at Raven.Client.Exceptions.ExceptionDispatcher.d__3.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Exceptions\ExceptionDispatcher.cs:line 117
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.d__90`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 1014
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.d__75`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 806
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Raven.Client.Http.RequestExecutor.d__75`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 806
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.d__68`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 417
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Documents.Operations.MaintenanceOperationExecutor.d__13`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Documents\Operations\MaintenanceOperationExecutor.cs:line 64
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Util.AsyncHelpers.RunSync(Func`1 task) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Util\AsyncHelpers.cs:line 79
at MyProject.DataAccess.RavenDb.ServiceCollectionExtensions.ConfigureStore(IDocumentStore store) in C:\Sviluppo\steelchihuahua\MyProject.DataAccess.RavenDb\ServiceCollectionExtensions.cs:line 65
at MyProject.DataAccess.RavenDb.ServiceCollectionExtensions.InitializeDocumentStore(IServiceCollection services, Boolean isDevelopment, Boolean isStaging, Boolean isProduction, String contentRootPath, String certificatePath, String certificatePassword, String databaseName, String databaseUrl) in C:\Sviluppo\steelchihuahua\MyProject.DataAccess.RavenDb\ServiceCollectionExtensions.cs:line 45
at MyProject.RealTimeApi.Startup.ConfigureServices(IServiceCollection services) in C:\Sviluppo\steelchihuahua\MyProject.RealTimeApi\Startup.cs:line 41
对于这种异常,我不确定是我做错了什么,还是库中有错误,或者两者都有。
有人知道吗?
谢谢。
编辑:进一步试验我发现了更多问题。我一直在尝试添加一个非常简单的 map/reduce,但我遇到了一种新的(毫无意义的)错误,因为我已经返回了一个匿名对象。此外,如果我删除 "groupby" 语句(实际上并不需要),我将返回到 NullReferenceException:
不需要 Map-Reduce 索引。
Map-Reduce 用于执行数据聚合。
只需查看 company.Name(而不是仅查看 公司)如下:
this.Map = persons => from person in persons
let company = this.LoadDocument<T>(person.ExternalEmployeeData.CompanyId)
select new
{
// check on company.Name
CompanyName = company.Name != null ? company.Name : string.Empty,
CompanyRegisteredName = company.Name != null ? company.RegisteredName : string.Empty,
person.FirstName,
person.Id,
person.LastName,
person.NationalInsuranceNumber
};
事实证明,在 Map 定义之后,我所需要的是:
this.StoreAllFields(FieldStorage.Yes);
这会保留索引中的数据。然后我必须显式地投影我的查询,即使我已经使用索引输出作为我的 IQueryable 的类型 T:
var items = await pagedQuery.ProjectInto<TIndexOutput>()
不过,服务器报告的奇怪错误消息应该得到解决。 "NullReferenceException" 表示不应该出现的场景,RavenDB 单元测试未涵盖该场景。另外,当我已经这样做时,说我需要输出匿名类型的消息非常具有误导性。