Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select a RowKey range with Azure Table Storage?

I would like to query my azure tablestorage using PrimaryKey plus I would like to check my RowKey is within a range. For example the range 02001 to 02999

Can someone tell me how I can do this? I understand how to query the PK with a simple:

where fooEntiy.PartitionKey == partition

but I don't know how I can query fooEntity.RowKey.

Also if I do this by specifying a range then will it still retrieve all the entries for that partition and then check to see if they match the range?

Thank you for your advice,

Mariko

like image 666
john wagner Avatar asked May 09 '11 05:05

john wagner


People also ask

What is RowKey in Azure Table Storage?

The row key is a unique identifier for an entity within a given partition. Together the PartitionKey and RowKey uniquely identify every entity within a table. The row key is a string value that may be up to 1 KiB in size. You must include the RowKey property in every insert, update, and delete operation.

What are the default properties of Azure Storage Table?

By default a property is created as type String , unless you specify a different type. To explicitly type a property, specify its data type by using the appropriate OData data type for an Insert Entity or Update Entity operation. For more information, see Inserting and Updating Entities.

Does Azure Table storage supports multiple write regions?

Azure Table Storage supports a single region with an optional read-only secondary region for availability. Cosmos DB supports distribution from 1 to more than 30 regions with automatic failovers worldwide.


2 Answers

Your query could look something like this:

where fooEntity.PartitionKey == partionKey
    && fooEntity.RowKey.CompareTo(lowerBoundRowKey) >= 0
    && fooEntity.RowKey.CompareTo(upperBoundRowKey) <= 0

This should return all of the items between the lowerBoundRowKey and the upperBoundRowKey including those values (if you don't want it to be inclusive, just use > and < rather than >= and <=).

You will not need to do any other filtering than this.

It looks like you're already padding your numbers that you're storing in the RowKey with leading zeros which is a good thing as this range will be a lexical range, not a numeric range.

e.g. running this query with lowerBoundKey = 10 and upperBoundKey = 100 will not return an item with a RowKey of 20.

If you pad it with zeros however lowerBoundKey = 00010 and upperBoundKey = 00100 will return an item with a RowKey of 00020.

like image 108
knightpfhor Avatar answered Nov 02 '22 23:11

knightpfhor


This will bring entities using the specified range of RowKey values with specified PartitionKey:

" PartitionKey eq 'your partitonKey value' and (RowKey gt '02001' and RowKey lt '02999') "

Find more information here and here. Hope this helps.

like image 44
Amit Jain Avatar answered Nov 02 '22 22:11

Amit Jain