Skip to content

Instantly share code, notes, and snippets.

@asapostolov
Created July 15, 2020 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asapostolov/e7f2c3c148be5107a1e44753b1bf7de2 to your computer and use it in GitHub Desktop.
Save asapostolov/e7f2c3c148be5107a1e44753b1bf7de2 to your computer and use it in GitHub Desktop.
Failed to execute mapping function on contracts-8314. Exception: System.InvalidOperationException: The output of the mapping function does not contain all fields that the index is supposed to group by.
Output: { AccountId = accounts-994, ContractId = contracts-8314, DateCreated = 04/02/2019 15:03:47, DateLastModified = 02/24/2020 09:13:05 }
Group by fields: AccountId,ContractId
Compiled index def:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using Lucene.Net.Documents;
using Raven.Client.Documents.Indexes;
using Raven.Server.Documents.Indexes.Static;
using Raven.Server.Documents.Indexes.Static.Linq;
using Raven.Server.Documents.Indexes.Static.Extensions;
namespace Raven.Server.Documents.Indexes.Static.Generated
{
public class Index_Contracts_RefreshStats : StaticIndexBase
{
IEnumerable Map_0(IEnumerable<dynamic> docs)
{
foreach (var contract in docs)
{
yield return new
{
AccountId = contract.AccountId,
ContractId = Id(contract),
DateCreated = contract.DateCreated,
DateLastModified = contract.DateLastModified
}
;
}
}
IEnumerable Map_1(IEnumerable<dynamic> docs)
{
foreach (var row in docs)
{
if (((bool)(row.ContractId != null) && (bool)(row.IsManagementRow == false)) == false)
continue;
yield return new
{
AccountId = row.AccountId,
ContractId = row.ContractId,
DateCreated = row.DateCreated,
DateLastModified = row.DateLastModified
}
;
}
}
public Index_Contracts_RefreshStats()
{
this.AddMap("Contracts", this.Map_0);
this.AddMap("IncomeRows", this.Map_1);
this.Reduce = results => results.GroupBy((Func<dynamic, dynamic>)(item => new
{
AccountId = item.AccountId,
ContractId = item.ContractId
}
)).Select((Func<IGrouping<dynamic, dynamic>, dynamic>)(gr => new
{
AccountId = gr.Key.AccountId,
ContractId = gr.Key.ContractId,
DateCreated = DynamicEnumerable.Max(gr, (Func<dynamic, DateTime>)(x => ((DateTime)x.DateCreated))),
DateLastModified = DynamicEnumerable.Max(gr, (Func<dynamic, DateTime>)(x0 => ((DateTime)x0.DateLastModified)))
}
));
this.GroupByFields = new Raven.Server.Documents.Indexes.CompiledIndexField[] { new Raven.Server.Documents.Indexes.SimpleField("AccountId"), new Raven.Server.Documents.Indexes.SimpleField("ContractId") };
this.OutputFields = new System.String[] { "AccountId", "ContractId", "DateCreated", "DateLastModified" };
}
}
}
at Raven.Server.Documents.Indexes.MapReduce.Static.MapReduceIndex.AnonymousObjectToBlittableMapResultsEnumerableWrapper.Enumerator.ThrowMissingGroupByFieldsInMapOutput(Object output, HashSet`1 groupByFields, StaticIndexBase compiledIndex) in C:\Builds\RavenDB-Stable-4.2\42009\src\Raven.Server\Documents\Indexes\MapReduce\Static\MapReduceIndex.cs:line 486
at Raven.Server.Documents.Indexes.MapReduce.Static.MapReduceIndex.AnonymousObjectToBlittableMapResultsEnumerableWrapper.Enumerator.MoveNext() in C:\Builds\RavenDB-Stable-4.2\42009\src\Raven.Server\Documents\Indexes\MapReduce\Static\MapReduceIndex.cs:line 459
at Raven.Server.Documents.Indexes.MapReduce.MapReduceIndexBase`2.PutMapResults(LazyStringValue lowerId, LazyStringValue id, IEnumerable`1 mappedResults, TransactionOperationContext indexContext, IndexingStatsScope stats) in C:\Builds\RavenDB-Stable-4.2\42009\src\Raven.Server\Documents\Indexes\MapReduce\MapReduceIndexBase.cs:line 121
at Raven.Server.Documents.Indexes.MapReduce.Static.MapReduceIndex.HandleMap(LazyStringValue lowerId, LazyStringValue id, IEnumerable mapResults, IndexWriteOperation writer, TransactionOperationContext indexContext, IndexingStatsScope stats) in C:\Builds\RavenDB-Stable-4.2\42009\src\Raven.Server\Documents\Indexes\MapReduce\Static\MapReduceIndex.cs:line 287
at Raven.Server.Documents.Indexes.Workers.MapDocuments.Execute(DocumentsOperationContext databaseContext, TransactionOperationContext indexContext, Lazy`1 writeOperation, IndexingStatsScope stats, CancellationToken token) in C:\Builds\RavenDB-Stable-4.2\42009\src\Raven.Server\Documents\Indexes\Workers\MapDocuments.cs:line 110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment