1

I am using Azure table storage which provides very less options to query the table storage. I have my RowKey as a composed key in the following way:

"b844be0d-2280-49f7-9ad7-58c36da80d22_2518908336099522182"
,"b844be0d-2280-49f7-9ad7-58c36da80d22_2518908336099522183"
,"b844be0d-2280-49f7-9ad7-58c36da80d22_2518908336099522184"
,"b844be0d-2280-49f7-9ad7-58c36da80d22_2518908336099522185"

The first part is a Guid, and the second part after the separator(_) is the timeticks.

I want to search on azure storage using its operators for rowkeys ending with "2518908336099522182"

There is no "Contains" operator that can help here, What do i do to get it working for "EndsWith" kind of filtering?

puneet
  • 492
  • 1
  • 8
  • 25

2 Answers2

0

Things to note: Both the PartitionKey and RowKey properties are of type String, you could filter the content through the use of $filter, or by Filtering on the PartitionKey and Rowkey as follows:

https://myaccount.table.core.windows.net/Customers(PartitionKey='MyPartition',RowKey='MyRowKey1')

another note: The constant value must be of the same data type as the property in order for the filter to return valid results. For more information about supported property types, see Understanding the Table Service Data Model.

In your case, as far as I know, the segmenting of a Rowkey then filtering on that is not an option of the supported operators. I'd recommend checking this link for the full documentation of supported queries.

0

I assume that you want to search by date time, so you can put the date time value in front of your GUID to make the row key like this:

2518908336099522182_b844be0d-2280-49f7-9ad7-58c36da80d22

Next, when your search can be formulated like:

var filters = TableQuery.CombineFilters(
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Smith"),
    TableOperators.And,
    TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, "2518908336099522182")
);

filters = TableQuery.CombineFilters(
    filters,
    TableOperators.And,
    TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, "2518908336099522182")
);

TableQuery<CustomerEntity> rangeQuery = new TableQuery<CustomerEntity>().Where(filters);

Hope this helps

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Toan Nguyen
  • 11,263
  • 5
  • 43
  • 59
  • 1
    I cannot change the order the way you have stated, because in its current form it is being utilized the way you have shown in your code. If I change the order, the existing code would invalidate. I need the "endswith" logic, I already have the 'startswith' implemented – puneet Mar 19 '18 at 07:16
  • @Toan Nguyen will it ignore the guid when querying with greater than or less than? – Rusty Feb 03 '20 at 08:32
  • 1
    @Rusty Yes. The comparison is text-based so the matching starts from the beginning – Toan Nguyen Feb 03 '20 at 10:25