Reputation: 11
I have an Azure storage table in which each partition stores some information about my custom data class. Each partition row is more like a history of that class and only the latest record is supported to get returned when queried.
When I know which partition I want to look up, then it is very easy to get the latest record like this:
string pkFilter = TableQuery<MyEntity>.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionkeyvalue);
var query = new TableQuery<MyEntity>().Where(pkFilter).Take(1);
Now the scenario is to get the top record from all partitions. How do I retrieve the top record of each partition in a single call in an efficient way?
Upvotes: 0
Views: 1380
Reputation: 5249
You are essentially trying to apply a group by operation; that's a tough one because no-sql doesn't do well with database concepts.
So your only options are limited to workarounds; if you have a dozen or so PKs, then a parallel operation on your table may make sense. If you have a large number of PKs, you may need to create another table that only contains the latest information and gets updated as part of a Batch operation at the same time as your original table. This way your secondary table always contains the correct data (since batch operations succeed or fail as a whole).
Upvotes: 2