Can PartitionKey be queried using StartsWith?

In Azure Table Storage, you can query PartitionKey using StartsWith or some other statement, for example. Contains etc.

I know I can do this with RowKeys, but can this be done with PartitionKeys?

The next question: even if it is doable, is it appropriate? Should PartitionKey always be an exact match - say, for performance reasons?

+5
source share
3 answers

Well, the good news is that you can perform partial matches and you will get β€œgood” performance if the number of partitions deleted is small. If you have many partition keys, performance will suffer.

I could try to summarize an excellent review of this, but it is already written, so if you point your browser to the following link, you should find out everything you need to know about sections, string lines and expected executions:

https://msdn.microsoft.com/en-us/library/azure/hh508997.aspx

-1
source

Here is an example of using the GreaterThanOrEqual and LessThan operators as an extension of the target column name.

The filter combines two parts:

  • anything that is greater than or equal to your start with a prefix,
  • add the last character of your prefix and find something less.

For example, the prefix startsWith "CAR" will prepare something like s >= "CAR" && s < "CAS" .

  public static string GetStartsWithFilter(this string columnName, string startsWith) { var length = startsWith.Length - 1; var nextChar = startsWith[length] + 1; var startWithEnd = startsWith.Substring(0, length) + (char)nextChar; var filter = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition(columnName, QueryComparisons.GreaterThanOrEqual, startsWith), TableOperators.And, TableQuery.GenerateFilterCondition(columnName, QueryComparisons.LessThan, startWithEnd)); return filter; } 

Using:

 var query = new TableQuery<MyTableEntity>().Where(myColumnName.GetStartsWithFilter(prefix)); 

Based on Alexandre B Blog

+8
source

In Azure Table Storage, you can query PartitionKey using Starts with some other statement, for example. Contains etc.

No, it is not possible to execute queries using StartsWith or Contains a query statement with Azure tables. To simulate StartsWith , you will need to use a combination of the Greater Than Equal To and Less Than statements. You cannot use the Contains operator. You will need to first extract all the data on the client side, and then use Contains to filter data only on the client side.

For a list of supported query operators, see this link: https://msdn.microsoft.com/en-us/library/azure/dd135725.aspx .

I know I can do this with RowKeys, but can this be done with PartitionKeys?

I do not think that's possible. I am curious to know why you are saying this.

The next question: even if it is doable, is it appropriate? Should PartitionKey always be an exact match - say, for performance reasons?

I would highly recommend reading this excellent guide for this: https://azure.microsoft.com/en-in/documentation/articles/storage-table-design-guide/ .

+3
source

Source: https://habr.com/ru/post/1244458/


All Articles