Index compilation fails when result result has a collection of custom type.

37 views
Skip to first unread message

Josh Buedel

unread,
Mar 16, 2018, 2:52:15 PM3/16/18
to RavenDB - 2nd generation document database
I've found that I get index compilation errors on a map/reduce index when the index result type has a member that is a list of some custom type.  Say I have a list of  `LineItem`s on my `Job` object. That will cause a compilation error (type or namespace not found). If I change it from a collection to a single object, the index will compile. 

Attached is some code that reproduces the problem. Comment/uncomment the #define at the top to see the different behavior.

This is on Raven 3.5.

Thanks,
Josh


TestIndex.cs

Oren Eini (Ayende Rahien)

unread,
Mar 18, 2018, 3:40:10 AM3/18/18
to ravendb
Yes, that is correct.
The issue is that your custom type does not exists on the server side, so it fails.
We do some type erasure at the top level, but we don't erase all types, so this errors. 
You can use an anonymous array new [] { ... } instead.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Josh Buedel

unread,
Mar 19, 2018, 10:47:35 AM3/19/18
to rav...@googlegroups.com
Using an array of anonymous objects means I could not then do a `GroupBy` against those objects in the reducer. Because the type information will not be carried from the maps to the reducer.

--
You received this message because you are subscribed to a topic in the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/Ivmi6OBKH5k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ravendb+unsubscribe@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Mar 19, 2018, 11:52:37 AM3/19/18
to ravendb
You don't actually have to have the same type , only the same shape.
In other words, this is fine

public class TestIndex : AbstractMultiMapIndexCreationTask<IndexState>
{
   public TestIndex()
   {
      AddMap<JobProductionEvent>(productionEvents =>
         from pe in productionEvents
         select new IndexState
         {
            OrdId = pe.OrdId,
            LineItems = new []
            {
               new 
               {
                  ItmId = pe.ItmId,
                  TotalFt = 0,
                  GoodFt = pe.GoodIn / 12,
                  QuantityDone = pe.Quantity,
                  Quantity = 0
               }
            }
               OneLine = new StateLine()
         });


      AddMap<Job>(jobDetails =>
         from job in jobDetails
         select new IndexState
         {
            OrdId = job.OrdId,

            LineItems = job.Items.Select(i => new StateLine()
            {
              ItmId = i.ItmId,
              GoodFt = 0m,
            TotalFt = i.Length * i.Quantity / 12,
               QuantityDone = 0,
               Quantity = i.Quantity
            }

         });

      Reduce = jobStates =>
         from js in jobStates
         group js by new {js.OrdId}
         into g
         select new IndexState
         {
            OrdId = g.Key.OrdId,

            LineItems = g.SelectMany(x => x.LineItems)
               .GroupBy(x => x.ItmId)
               .Select(gx => new StateLine()
               {
                  ItmId = gx.Key,
                  GoodFt = gx.Sum(x => x.GoodFt),
                  TotalFt = gx.Sum(x => x.Length) * gx.Sum(x => x.Quantity) / 12,
                  QuantityDone = gx.Sum(x => x.QuantityDone),
                  Quantity = gx.Sum(x => x.Quantity)
               }
               )
               OneLine = new StateLine()
         };
   }

Josh Buedel

unread,
Mar 21, 2018, 2:37:46 PM3/21/18
to rav...@googlegroups.com
That was the trick. I knew that only the shape mattered. But it didn't occur to me that maps could be anonymous objects and the reducer a concrete type. Thanks!
Reply all
Reply to author
Forward
0 new messages