Re: [RavenDB] Exception with System.Threading.Thread.CurrentThread.CurrentCulture in a AbstractIndexCreationTask

82 views
Skip to first unread message

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 1:31:46 AM8/3/12
to rav...@googlegroups.com
You cannot use  System.Threading.Thread.  in indexes
Currently this is only partly blocked, it is fully blocked in 1.2

On Fri, Aug 3, 2012 at 3:29 AM, J Healy <extco...@gmail.com> wrote:
I am able to create and run this index just fine in Raven Studio / Indexes:

------------------------------------------------------------------
  Index: UpdateMessagesCountByTypeWeek  

            from msg in docs.UpdateMessages
            where msg.msgtype != "perf"

    let c = System.Threading.Thread.CurrentThread.CurrentCulture
    let w = c.Calendar.GetWeekOfYear(msg.timestamp, c.DateTimeFormat.CalendarWeekRule, c.DateTimeFormat.FirstDayOfWeek)

            select new
            {
                week = w,
                type = msg.msgtype,
                count = 1
            }

            from result in results
       group result by new {
                               result.week,
                               result.type,
                           }
           into g
           select new
           {
                g.Key.week,
               g.Key.type,
               count = g.Sum(x => x.count)
           }


------------------------------------------------------------------

But when I do the following in code:

------------------------------------------------------------------

    public class UpdateMessagesCountByTypeWeek : AbstractIndexCreationTask<UpdateMessage, UpdateMessageCountByTypeWeek>
    {
        public UpdateMessagesCountByTypeWeek()
        {
            Map = msgs =>   from msg in msgs
                            where msg.msgtype != "perf"
 
                    let c = System.Threading.Thread.CurrentThread.CurrentCulture
                            let w = c.Calendar.GetWeekOfYear(msg.timestamp, c.DateTimeFormat.CalendarWeekRule, c.DateTimeFormat.FirstDayOfWeek)

                            select new
                            {
                                week = w,
                                type = msg.msgtype,
                                count = 1
                            };
 
            Reduce = results => from result in results
                                group result by new {
                 result.week,
                 result.type,
                         }
                                 into g
                                 select new
                                 {
                                     g.Key.week,
                                     g.Key.type,
                                     count = g.Sum(x => x.count)
                                 };
        }
    }

------------------------------------------------------------------

I get this error:

------------------------------------------------------------------

e:\_IntelProjects\UT\UtRepository\Data\Test\Tenants\IndexTests\IndexDefinitions\TemporaryIndexDefinitionsAsSource\ikqs2ytf.0.cs(28,359) : error CS0103: The name 'Thread' does not exist in the current context

   at Raven.Database.Linq.QueryParsingUtils.Compile(String source, String name, String queryText, OrderedPartCollection`1 extensions, String basePath) in c:\Builds\RavenDB-Stable\Raven.Database\Linq\QueryParsingUtils.cs:line 273

------------------------------------------------------------------

Off the top of my head this seems like something I ought to be able to do...thanks.


J Healy

unread,
Aug 3, 2012, 2:00:58 AM8/3/12
to rav...@googlegroups.com
I understand on one hand, but, despite the security implications, I still find it somewhat lamentable not being able to match index definitions from studio to code given the utility of the function...

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 2:02:23 AM8/3/12
to rav...@googlegroups.com
Use CultureInfo.InvariantCulture instead, it is the same thing anyway

J Healy

unread,
Aug 3, 2012, 2:50:06 AM8/3/12
to rav...@googlegroups.com
Damned if that didn't work! Should have been able to do that lateral shift myself - thanks for snapping me back to it...
Message has been deleted

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 3:01:32 AM8/3/12
to rav...@googlegroups.com
Just to verify, everything works now, right?

On Fri, Aug 3, 2012 at 10:00 AM, J Healy <extco...@gmail.com> wrote:
docs.UpdateMessages
.Where(msg => msg.msgtype != "perf") 
.Select(msg => new {msg = msg, c = CultureInfo.InvariantCulture})
.Select(__h__TransparentIdentifier0 => new {__h__TransparentIdentifier0 = __h__TransparentIdentifier0, 
  w = __h__TransparentIdentifier0.c.Calendar.GetWeekOfYear(__h__TransparentIdentifier0.msg.timestamp, __h__TransparentIdentifier0.c.DateTimeFormat.CalendarWeekRule, __h__TransparentIdentifier0.c.DateTimeFormat.FirstDayOfWeek)})
.Select(__h__TransparentIdentifier1 => new {week = __h__TransparentIdentifier1.w, type = __h__TransparentIdentifier1.__h__TransparentIdentifier0.msg.msgtype, Count = 1})

J Healy

unread,
Aug 3, 2012, 3:02:51 AM8/3/12
to rav...@googlegroups.com
Yeah, thanks - interesting code it gens...

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 3:10:57 AM8/3/12
to rav...@googlegroups.com
Yeah, it is.
The formatting is a bit off, as well.
Reply all
Reply to author
Forward
0 new messages