locked
Best method to Count() in ATS RRS feed

  • Question

  • Hi,

    As per this post - Count() - is not supported in ATS .... The request for the feature is now 8 months old ... 

    1) Is there any hope at all of seeing this feature added this year ?

    2) Regardless of 1) - what is the "best / fastest" way to do this now ?

    Thx

    Friday, September 24, 2010 5:13 AM

Answers

  • If the set of entities is very small, you could certainly query for all of them and do the count locally.  (That's what happens if you do something like .ToList().Count().)

    If the count is going to be large, the typical way to deal with this is to maintain the count as you insert/delete entities.  That means keeping the current count stored somewhere (perhaps in a table) and incrementing/decrementing it with each operation.  Here you have to think about concurrency... depending on how accuarte you need your count to be, you might want to use a queue to serialize updates to the count to ensure you don't have a lot of retries due to optimistic concurrency.  If you don't care that much about the accuracy of the count, you could do an unconditional update and let simultaneous updates simply get lost with last-update-wins.

    Friday, September 24, 2010 5:21 PM

All replies

  • If the set of entities is very small, you could certainly query for all of them and do the count locally.  (That's what happens if you do something like .ToList().Count().)

    If the count is going to be large, the typical way to deal with this is to maintain the count as you insert/delete entities.  That means keeping the current count stored somewhere (perhaps in a table) and incrementing/decrementing it with each operation.  Here you have to think about concurrency... depending on how accuarte you need your count to be, you might want to use a queue to serialize updates to the count to ensure you don't have a lot of retries due to optimistic concurrency.  If you don't care that much about the accuracy of the count, you could do an unconditional update and let simultaneous updates simply get lost with last-update-wins.

    Friday, September 24, 2010 5:21 PM
  • 1) I wish. That was my feature request you linked to. Maybe we can bribe them somehow? Sadly, I'm losing a lot of confidence in this mygreatwindowsazureidea.com site. I know the team isn't just sitting around, but according to the site nothing is being done.

    2) Sorry, unfortunately we had to go the route that Steve mentioned. We had to create a whole system that manages our aggregate states and we hate it. Basically we have a system that manages rolling Counts, GroupBys, Distinct, Averages, etc. as well as concurrency management  on each because we cannot afford to lose a single record. Makes me cry when I think about all the work we had to do. I'd throw it all away in a heartbeat!

    @Steve  - Can we please have at least Count and Distinct added?

    • Edited by IA JBarnes Friday, September 24, 2010 7:48 PM
    Friday, September 24, 2010 6:35 PM
  • @Steve - thanks for the response. Hmm, its a large amount of entities - so if this is the only way to do - seems this is the only way to implement things. Any chance of a blog post around this ? Would be awesome.

    @IActionable - Uggh. I would prefer not to cry - but seems I might have to shed a tear also to create some seperate sub-system for these tasks. Dang. Any chance of some open-source love of your system ? :)

    1) I wish. That was my feature request you linked to. Maybe we can bribe them somehow? Sadly, I'm losing a lot of confidence in this mygreatwindowsazureidea.com site. I know the team isn't just sitting around, but according to the site nothing is being done.

    I'd have to agree with this statement as well unfortunately. The first 2 pages of "mygreatwindowsazureidea" - are filled with requests that are >10-11 months old. Nothing has really changed on that site on pages 1 or 2 in >8 months. I don't really see any point adding to it - considering so many requests already exist and just don't seem to be solved. You only have to look at the "completed" tab - 8 items in >11 months ?

    As @IActionable stated - I know the team isn't just sitting around - but whatever they are doing - doesn't seem to link back to the requests on that site. I seem to get Amazon WebServices emails releasing new features left right and center - and nothing for azure. 

    Friday, September 24, 2010 6:55 PM
  • @SparkCode

    Sorry, I wish I had some time to find a way to share or even explain what we did. Most aspects of it are tied closely to what we need it for. Its one of those things that I'd rather throw away than share. It was never meant to stick around, I really was convinced that the Azure Team would come around and at least add Count and Distinct support.

    Friday, September 24, 2010 10:25 PM
  • @IActionable

    ok thanks - I think we might try steves second approach for now and then implement something like the first. I am assuming - with PDC coming up at the end of October - that hopefully a new SDK update is released in the next few weeks and maybe they will include Count() and Distinct() in this ?

    Can only hope!

    Sunday, September 26, 2010 12:29 PM