Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performing an Azure table storage case-insenstive query

This may be somewhat related to this SO question How to perform a case-sensitive LINQ query in Azure?. However I'm using Storage Client 3.0, not the linq queries and the TableStorageContext in that question.

I have a table storage entity called Account that has a string property for email address. The email property is not a partition key or a row key.

I want to search for an entity with a matching email address in a case-insensitive way, such that a search for "[email protected]" returns "[email protected]", etc.

My code looks something like this:

TableQuery<Account> rangeQuery = new TableQuery<Account>().Where(
    TableQuery.CombineFilters(
        TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "account"),
        TableOperators.And,
        TableQuery.GenerateFilterCondition("Email", QueryComparisons.Equal, email)));

var results = accountsTable.ExecuteQuery(rangeQuery).ToList();

Is there a way to perform a case insensitive query using the tableQuery class, or is there another approach? Should I just concentrate on data grooming and ensure that all data is forced to a consistent case?

like image 364
ChrisW Avatar asked Dec 20 '13 01:12

ChrisW


People also ask

Is Azure Table storage being deprecated?

Azure table storage is being deprecated in favor of Azure Cosmos DB. Azure Cosmos DB offers many advantages over Azure table storage, such as: -Azure Cosmos DB is scalable.

Which of the below queries are supported by Table API?

Yes, the API for Table supports OData query and LINQ query.

What is partition key and RowKey in Azure Table storage?

The key in an Azure Table Storage table comprises two elements. The partition key that identifies the partition containing the row, and a row key that is unique to each row in the same partition. Items in the same partition are stored in row key order. Rows that share the same partition key will be stored together.


2 Answers

To answer your question about doing case-insensitive search, it is not possible to do so with Windows Azure Table Storage.

One way is the one you suggested i.e. doing data grooming and store all in either lower or upper case.

Other approach would be to download the data on the client side and then doing case sensitive search on the data which is fetched on the client. 2nd approach may be feasible for smaller data sets but would not be practical if the data set is much bigger.

like image 176
Gaurav Mantri Avatar answered Sep 28 '22 12:09

Gaurav Mantri


Searching for anything that is not the leftmost part of the partition+row key would result in a table scan.

One approach would be to store, in another table, the email in lower or upper case so that it can be searched without doing a table scan.

In your example say,

Partition key = test.com 
Row key = bob 

would work quite well and give you many querying options.

like image 33
hocho Avatar answered Sep 28 '22 13:09

hocho