"The UTC time represented when the offset is applied must be between year 0 and 10,000" in multimap/reduce

1,864 views
Skip to first unread message

Anders

unread,
Oct 7, 2011, 8:26:00 AM10/7/11
to rav...@googlegroups.com
I'm getting the above exception with a multimap/reduce index
Site.ActiveUntil is a nullable DateTime.

There seems to be a bug in .NET (https://connect.microsoft.com/VisualStudio/feedback/details/565313/breaking-problem-with-datetimeoffset-that-affects-multiple-framework-classes), is there any way to work around this issue?

    public class SiteStatistics : AbstractMultiMapIndexCreationTask<SiteStatistics.ReduceResult>
    {
        public SiteStatistics()
        {
            AddMap<Site>(sites =>
                from site in sites
                select new
                {
                    Id = site.Id,
                    Name = site.Name,
                    ActiveUntil = site.ActiveUntil ?? DateTime.MinValue,
                    SurveyCount = site.Surveys,
                    ViewCount = 0,
                    ResponseCount = 0
                });

            AddMap<View>(views =>
                from view in views
                select new
                {
                    Id = view.SiteId,
                    Name = (string)null,
                    ActiveUntil = DateTime.MinValue,
                    SurveyCount = 0,
                    ViewCount = 1,
                    ResponseCount = 0
                });
                       
            AddMap<Response>(responses =>
                from response in responses
                select new
                {
                    Id = response.SiteId,
                    Name = (string)null,
                    ActiveUntil = DateTime.MinValue,
                    SurveyCount = 0,
                    ViewCount = 0,
                    ResponseCount = 1
                });

            Reduce = results =>
                from result in results
                group result by result.Id into g
                select new
                {
                    Id = g.Key,
                    Name = g.Select(x => x.Name).Where(x => x != null).FirstOrDefault(),
                    ActiveUntil = g.Select(x => x.ActiveUntil).Where(x => x != DateTime.MinValue).FirstOrDefault(),
                    SurveyCount = g.Sum(x => x.SurveyCount),
                    ViewCount = g.Sum(x => x.ViewCount),
                    ResponseCount = g.Sum(x => x.ResponseCount)
                };

            Index(x => x.Name, FieldIndexing.Analyzed);
        }

        public class ReduceResult
        {
            public string Id { get; set; }
            public string Name { get; set; }
            public DateTime ActiveUntil { get; set; }
            public int SurveyCount { get; set; }
            public int ViewCount { get; set; }
            public int ResponseCount { get; set; }
        }
    }

Matt Warren

unread,
Oct 7, 2011, 3:46:33 PM10/7/11
to ravendb
You should be able to replace DateTime.MinValue with null and use that
to indicate a missing field. The just use a nullable DateTime in your
model. This means you shouldn't encounter that pretty nasty bug
in .NET. Nullable types are a slightly cleaner way of representing "no
value" than DateTime.MinValue anyway.

public class SiteStatistics :
AbstractMultiMapIndexCreationTask<SiteStatistics.ReduceResult>
{
public SiteStatistics()
{
AddMap<Site>(sites =>
from site in sites
select new
{
Id = site.Id,
Name = site.Name,
ActiveUntil = site.ActiveUntil,
SurveyCount = site.Surveys,
ViewCount = 0,
ResponseCount = 0
});

AddMap<View>(views =>
from view in views
select new
{
Id = view.SiteId,
Name = (string)null,
ActiveUntil = (DateTime)null,
SurveyCount = 0,
ViewCount = 1,
ResponseCount = 0
});

AddMap<Response>(responses =>
from response in responses
select new
{
Id = response.SiteId,
Name = (string)null,
ActiveUntil = (DateTime)null,
SurveyCount = 0,
ViewCount = 0,
ResponseCount = 1
});

Reduce = results =>
from result in results
group result by result.Id into g
select new
{
Id = g.Key,
Name = g.Select(x => x.Name).Where(x => x !=
null).FirstOrDefault(),
ActiveUntil = g.Select(x => x.ActiveUntil).Where(x
=> x != null).FirstOrDefault(),
SurveyCount = g.Sum(x => x.SurveyCount),
ViewCount = g.Sum(x => x.ViewCount),
ResponseCount = g.Sum(x => x.ResponseCount)
};

Index(x => x.Name, FieldIndexing.Analyzed);
}

public class ReduceResult
{
public string Id { get; set; }
public string Name { get; set; }
public DateTime? ActiveUntil { get; set; }
> There seems to be a bug in .NET (https://connect.microsoft.com/VisualStudio/feedback/details/565313/br...),

Ayende Rahien

unread,
Oct 9, 2011, 4:01:56 AM10/9/11
to rav...@googlegroups.com
Fixed in the next build, thanks
Reply all
Reply to author
Forward
0 new messages