【问题标题】:Azure Table Storage - Search on RowKey that ends with a particular stringAzure 表存储 - 搜索以特定字符串结尾的 RowKey
【发布时间】:2018-08-24 15:40:17
【问题描述】:

我正在使用 Azure 表存储,它提供的查询表存储的选项非常少。我通过以下方式将我的 RowKey 作为组合键:

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

第一部分是Guid,分隔符(_)之后的第二部分是时间标记。

我想使用其运算符在 Azure 存储上搜索以“2518908336099522182”结尾的行键

这里没有可以提供帮助的“包含”运算符,我该怎么做才能使其适用于“EndsWith”类型的过滤?

【问题讨论】:

    标签: string azure azure-storage azure-table-storage string-operations


    【解决方案1】:

    注意事项:PartitionKey 和RowKey 属性都是String 类型,您可以通过使用$filter 来过滤内容,或者通过在PartitionKey 上进行过滤和Rowkey如下:

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

    另一个注意事项:常量值必须与属性的数据类型相同,过滤器才能返回有效结果。有关支持的属性类型的更多信息,请参阅了解表服务数据模型。

    就您而言,据我所知,对 Rowkey 进行分段然后对其进行过滤不是受支持的运算符的选项。我建议您查看此 link 以获取支持查询的完整文档。

    【讨论】:

      【解决方案2】:

      我假设您想按日期时间搜索,因此您可以将日期时间值放在您的 GUID 前面,以使行键如下所示:

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

      接下来,当您的搜索可以表述为:

      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);
      

      希望对你有帮助

      【讨论】:

      • 我无法按照您所说的方式更改顺序,因为在当前形式下,它正在按照您在代码中显示的方式使用。如果我更改顺序,现有代码将失效。我需要“endswith”逻辑,我已经实现了“startswith”
      • @Toan Nguyen 在查询大于或小于时会忽略 guid 吗?
      • @Rusty 是的。比较是基于文本的,因此匹配从头开始
      猜你喜欢
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      • 2015-11-03
      • 2017-08-05
      • 2013-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多