Created
October 5, 2012 09:30
-
-
Save jesuslpm/3838923 to your computer and use it in GitHub Desktop.
Map reduce indexes that access metadata does not work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Raven.Client.Document; | |
using Raven.Client.Embedded; | |
using Raven.Client.Indexes; | |
using Raven.Client; | |
using Raven.Client.Linq; | |
using Xunit; | |
using Raven.Json.Linq; | |
namespace Raven.Tests | |
{ | |
public class Contact | |
{ | |
public string Id { get; set; } | |
public string Name { get; set; } | |
} | |
public class Contact_ClrTypeStats : AbstractIndexCreationTask<Contact, Contact_ClrTypeStats.ClrTypeStats> | |
{ | |
public class ClrTypeStats | |
{ | |
public string ClrType { get; set; } | |
public int Count { get; set; } | |
} | |
public Contact_ClrTypeStats() | |
{ | |
Map = uses => from use in uses | |
select new | |
{ | |
Count = 1, | |
ClrType = MetadataFor(use).Value<string>("Raven-Clr-Type") | |
}; | |
Reduce = results => from result in results | |
group result by result.ClrType | |
into g | |
select new | |
{ | |
Count = g.Sum( x => x.Count ), | |
ClrType = g.Key | |
}; | |
} | |
} | |
public class MetadataReduceIndex:IDisposable | |
{ | |
DocumentStore store; | |
public MetadataReduceIndex() | |
{ | |
store = new EmbeddableDocumentStore { RunInMemory = true }; | |
store.Initialize(); | |
} | |
[Fact] | |
public void ShouldWork() | |
{ | |
new Contact_ClrTypeStats().Execute(this.store); | |
using (var session = store.OpenSession()) | |
{ | |
session.Store( new Contact { Id = "Contact/1", Name = "Oren" }); | |
session.SaveChanges(); | |
} | |
using (var session = store.OpenSession()) | |
{ | |
var stats = session.Query<Contact_ClrTypeStats.ClrTypeStats, Contact_ClrTypeStats>() | |
.Customize(x => x.WaitForNonStaleResults()) | |
.ToList(); | |
var statistics = RavenJObject.FromObject(store.DatabaseCommands.GetStatistics()).ToString(); | |
Assert.Equal(1, stats.Count); | |
} | |
} | |
public void Dispose() | |
{ | |
if (store != null) store.Dispose(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This are the statistics. It seems that the reduce phase does not start: | |
{ | |
"LastDocEtag": "00000000-0000-0100-0000-000000000001", | |
"LastAttachmentEtag": "00000000-0000-0000-0000-000000000000", | |
"CountOfIndexes": 2, | |
"ApproximateTaskCount": 0, | |
"CountOfDocuments": 1, | |
"StaleIndexes": [], | |
"CurrentNumberOfItemsToIndexInSingleBatch": 256, | |
"CurrentNumberOfItemsToReduceInSingleBatch": 128, | |
"Indexes": [ | |
{ | |
"Name": "Contact/ClrTypeStats", | |
"IndexingAttempts": 1, | |
"IndexingSuccesses": 0, | |
"IndexingErrors": 0, | |
"LastIndexedEtag": "00000000-0000-0100-0000-000000000001", | |
"LastIndexedTimestamp": "2012-10-05T09:31:47.8384962Z", | |
"LastQueryTimestamp": "2012-10-05T09:31:48.2755399Z", | |
"TouchCount": 0, | |
"ReduceIndexingAttempts": 0, | |
"ReduceIndexingSuccesses": 0, | |
"ReduceIndexingErrors": 0, | |
"LastReducedEtag": "00000000-0000-0000-0000-000000000000", | |
"LastReducedTimestamp": "0001-01-01T00:00:00.0000000", | |
"Performance": [ | |
{ | |
"Operation": "Map", | |
"OutputCount": 1, | |
"InputCount": 1, | |
"Duration": "00:00:00.3901203", | |
"DurationMilliseconds": 390.12 | |
} | |
] | |
}, | |
{ | |
"Name": "Raven/UpdateCascadeOperations/ByStatus", | |
"IndexingAttempts": 0, | |
"IndexingSuccesses": 0, | |
"IndexingErrors": 0, | |
"LastIndexedEtag": "00000000-0000-0100-0000-000000000001", | |
"LastIndexedTimestamp": "2012-10-05T09:31:47.8384962Z", | |
"LastQueryTimestamp": "2012-10-05T09:31:47.5314655Z", | |
"TouchCount": 0, | |
"ReduceIndexingAttempts": null, | |
"ReduceIndexingSuccesses": null, | |
"ReduceIndexingErrors": null, | |
"LastReducedEtag": null, | |
"LastReducedTimestamp": null, | |
"Performance": [] | |
} | |
], | |
"Errors": [], | |
"Triggers": [ | |
{ | |
"Type": "Put", | |
"Name": "Raven.Database.Plugins.Builtins.InvalidDocumentNames" | |
}, | |
{ | |
"Type": "Put", | |
"Name": "Raven.Database.Plugins.Builtins.Tenants.ModifiedTenantDatabase" | |
}, | |
{ | |
"Type": "Put", | |
"Name": "Raven.Bundles.UpdateCascade.UpdateCascadeSettingPutTrigger" | |
}, | |
{ | |
"Type": "Put", | |
"Name": "Raven.Bundles.UpdateCascade.UpdateCascadeOperationPutTrigger" | |
}, | |
{ | |
"Type": "Put", | |
"Name": "Raven.Bundles.UpdateCascade.UpdateCascadePutTrigger" | |
}, | |
{ | |
"Type": "Delete", | |
"Name": "Raven.Database.Plugins.Builtins.Tenants.DeletedTenantDatabase" | |
}, | |
{ | |
"Type": "Delete", | |
"Name": "Raven.Database.Plugins.Builtins.Tenants.RemoveTenantDatabase" | |
}, | |
{ | |
"Type": "Delete", | |
"Name": "Raven.Bundles.UpdateCascade.UpdateCascadeSettingDeleteTrigger" | |
}, | |
{ | |
"Type": "Read", | |
"Name": "Raven.Database.Plugins.Builtins.FilterRavenInternalDocumentsReadTrigger" | |
}, | |
{ | |
"Type": "Index Update", | |
"Name": "Raven.Bundles.IndexedProperties.IndexedPropertiesTrigger" | |
} | |
], | |
"Extensions": [ | |
{ | |
"Name": "IStartupTask", | |
"Installed": [ | |
{ | |
"Name": "ValidateLicense", | |
"Assembly": "Raven.Database" | |
}, | |
{ | |
"Name": "RemoveBackupDocumentStartupTask", | |
"Assembly": "Raven.Database" | |
}, | |
{ | |
"Name": "DeleteTemporaryIndexes", | |
"Assembly": "Raven.Database" | |
}, | |
{ | |
"Name": "CreateFolderIcon", | |
"Assembly": "Raven.Database" | |
}, | |
{ | |
"Name": "CleanupOldDynamicIndexes", | |
"Assembly": "Raven.Database" | |
}, | |
{ | |
"Name": "DeleteRemovedIndexes", | |
"Assembly": "Raven.Database" | |
}, | |
{ | |
"Name": "PendingTransactionRecovery", | |
"Assembly": "Raven.Database" | |
}, | |
{ | |
"Name": "UpdateCascadeStartupTask", | |
"Assembly": "Raven.Bundles.UpdateCascade" | |
} | |
] | |
}, | |
{ | |
"Name": "AbstractReadTrigger", | |
"Installed": [ | |
{ | |
"Name": "FilterRavenInternalDocumentsReadTrigger", | |
"Assembly": "Raven.Database" | |
} | |
] | |
}, | |
{ | |
"Name": "AbstractDeleteTrigger", | |
"Installed": [ | |
{ | |
"Name": "DeletedTenantDatabase", | |
"Assembly": "Raven.Database" | |
}, | |
{ | |
"Name": "RemoveTenantDatabase", | |
"Assembly": "Raven.Database" | |
}, | |
{ | |
"Name": "UpdateCascadeSettingDeleteTrigger", | |
"Assembly": "Raven.Bundles.UpdateCascade" | |
} | |
] | |
}, | |
{ | |
"Name": "AbstractPutTrigger", | |
"Installed": [ | |
{ | |
"Name": "InvalidDocumentNames", | |
"Assembly": "Raven.Database" | |
}, | |
{ | |
"Name": "ModifiedTenantDatabase", | |
"Assembly": "Raven.Database" | |
}, | |
{ | |
"Name": "UpdateCascadeSettingPutTrigger", | |
"Assembly": "Raven.Bundles.UpdateCascade" | |
}, | |
{ | |
"Name": "UpdateCascadeOperationPutTrigger", | |
"Assembly": "Raven.Bundles.UpdateCascade" | |
}, | |
{ | |
"Name": "UpdateCascadePutTrigger", | |
"Assembly": "Raven.Bundles.UpdateCascade" | |
} | |
] | |
}, | |
{ | |
"Name": "AbstractDynamicCompilationExtension", | |
"Installed": [ | |
{ | |
"Name": "SpatialDynamicCompilationExtension", | |
"Assembly": "Raven.Database" | |
} | |
] | |
}, | |
{ | |
"Name": "AbstractIndexUpdateTrigger", | |
"Installed": [ | |
{ | |
"Name": "IndexedPropertiesTrigger", | |
"Assembly": "Raven.Database" | |
} | |
] | |
} | |
] | |
} |
Author
jesuslpm
commented
Oct 5, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment