My problem is as follows, I have an Azure Table Storage that is set up like this:
I want to make a query such that given a number X, I want to return the highest number Row Key that is less than X for each Partition Key. That is kind of confusingly worded, so here is an example:
Partition Key, Row Key
"hello", 7
"hello", 9
"hello", 12
"other", 6
If I queried with the number 10, I want to return a list like [("hello", 9), ("other", 6)]. Note that I want only unique partition keys and the highest number that is less than 10.
I can do this for a particular name with something like (leaving some stuff out for brevity):
string orderFilter = TableQuery.GenerateFilterConditionForLong("RowKey", "le", 10);
string nameFilter = TableQuery.GenerateFilterCondition("PartitionKey", "eq", "hello");
TableQuery query = new TableQuery().Where(TableQuery.CombineFilters(orderFilter, "and", nameFilter));
IEnumerable<NameEntity> names = await nameTable.ExecuteQuerySegmentedAsync<NameEntity>(query, entityResolver, continuationToken);
// Get newest name
NameEntity newestName = names.Last();
But I can't seem to figure out how to do this with all the different Partition Keys. Is this possible in a single query? Thanks for any help!
There is no way to enumerate partition keys (without doing a table scan), so you can either:
With the latter, the other answer suggests writing the max-value for that partition key, at the same time. Certainly viable. But you'll need to remember that you need to maintain this bit of metadata.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With