ryanheath / RavenDB-NodaTime

Noda Time support for RavenDB
Other
20 stars 14 forks source link

Can't figure out a way to use ZonedDateTime in Reduce part of the index #7

Closed chester89 closed 8 years ago

chester89 commented 9 years ago

I recently had a task to calculate max value of a field in a collection. That field is represented by ZonedDateTime in .NET code. I tried putting .FieldName.AsZonedDateTime().ToOffsetDateTime().Resolve() in Map part of the index, in the Reduce part of them - but I can't manage to get the result. Any ideas?

chester89 commented 9 years ago

Also, when trying to create an index, I'm getting Raven.Abstractions.Exceptions.IndexCompilationException 'Assuming assembly reference 'NodaTime, Version=1.1.0.0' error - which is weird since I use 1.2.0 across solution and have redirected previous versions to 1.2.0. RavenDb server has redirects in the config, and Bundle dll is copied to the plugin folder

mattjohnsonpint commented 9 years ago

See the unit test I added. It maps an OffsetDateTime, then reduces to get the max. The test passes. If you're doing something significantly different, post a GIST please.

Not sure about the assembly error, but that's probably the cause of the problem. If it can't load the bundle then it won't understand the extension methods in the index definition.

mattjohnsonpint commented 9 years ago

I just realized the wiki page referenced NodaTime 1.2.0, but the last build of the project used 1.3.0. The current build of NodaTime is 1.3.1, but I see no need to recompile at this time.

I updated the wiki page to show the right version numbers in the binding redirect, but check your versions carefully. The version number in the binding redirect should match that of the NodaTime.dll in your plugins folder.

chester89 commented 9 years ago

Will try that, thanks

chester89 commented 9 years ago

When I enter your index into Raven Studio, it compiles fine, but I get back an empty value. It's really odd, my collection is quite large

mattjohnsonpint commented 9 years ago

If you can, please create a simplified version of the problem and post it somewhere so I can look at it. Or we can Skype this weekend sometime if you like.

chester89 commented 9 years ago

Here's a gist of an index I enter, and I get back an empty value. Even if I get rid of reduce part and try to filter on, let's say, month, that does not change the outcome

chester89 commented 9 years ago

I'll post variations of an index I tried later today. Also, I haven't tried creating and querying index from inside VS - I'll give it a try. I suppose WaitForNonStale results call is strictly for combination of embedded db and unit tests?

mattjohnsonpint commented 9 years ago

Yes, it's just for unit tests.

The gist you posted looks pretty much like the index I added to the project, which worked for me. Perhaps this issue only happens in server mode? Were you able to get the bundle loaded?

chester89 commented 9 years ago

Bundle is present in plugins folder, server recognizes it - meaning no exceptions on startup. Both bundle and my code reference NodaTime 1.2.0, assembly redirect to 1.2.0 is present in RavenDb config file

chester89 commented 8 years ago

Well, what can I say - I failed to find a solution. Tried about 4-6 different index definitions without any luck. I figured I don't really need timezone info in my Raven queries - and removed the library from the project.