azure - 使用多个查询条件查询 Windows Azure 表存储

标签 azure azure-table-storage data-partitioning

我正在尝试查询 Windows Azure 存储中的表,最初使用 TableQuery.CombineFiltersTableQuery<RecordEntity>().Where功能如下:

TableQuery.CombineFilters(
    TableQuery.GenerateFilterCondition("PartitionKey",   QueryComparisons.GreaterThanOrEqual, lowDate),
    TableOperators.And,
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThanOrEqual, lowDate),
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, entityId)
));

不幸的是,CombineFilters 最多只允许 2 个查询条件。所以我目前正在这样做:

var tableQuery = new TableQuery<RecordRowEntity>()
            .Where(TableQuery.CombineFilters("PartitionKey", string.Format("(PartitionKey ge '{0}') and (PartitionKey le '{1}') and (RowKey eq '{2}')", low, high, entityId));

还有其他办法吗?我担心我目前的做法很容易受到 Azure Api 工作方式变化的影响。

最佳答案

然后,组合过滤器可以与另一个过滤器组合,根据需要重复多次。请参阅示例“示例 – 查询 PartitionKey=”SamplePK”且 RowKey 大于或等于“5”的所有实体”,地址:https://learn.microsoft.com/en-us/archive/blogs/windowsazurestorage/windows-azure-storage-client-library-2-0-tables-deep-dive#querying .


string pkFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "samplePK");

string rkLowerFilter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, "5");

string rkUpperFilter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThan, "10");

// Note CombineFilters has the effect of "([Expression1]) Operator (Expression2]), as such passing in a complex expression will result in a logical grouping.
string combinedRowKeyFilter = TableQuery.CombineFilters(rkLowerFilter, TableOperators.And, rkUpperFilter);

string combinedFilter = TableQuery.CombineFilters(pkFilter, TableOperators.And, combinedRowKeyFilter);

// OR 
string combinedFilter = string.Format("({0}) {1} ({2}) {3} ({4})", pkFilter, TableOperators.And, rkLowerFilter, TableOperators.And, rkUpperFilter);
TableQuery query = new TableQuery().Where(combinedFilter);

关于azure - 使用多个查询条件查询 Windows Azure 表存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21167680/

相关文章:

algorithm - Jon Bentley 漂亮的快速排序——它是如何工作的?

python - 将第一个 django 测试应用程序部署到任何地方(azure 或 heroku)

bash - GitLab 作业作业成功但未完成(创建/删除 Azure AKS)

azure - 更新 Azure 表存储记录时如何避免竞争条件

Azure 功能 - 从 IoT 中心保存到表存储

powershell - 在Powershell中切片数组(或列表)的更好方法

c - Paho MQTT C 客户端与 Beaglebone Black 上的 azure IoT-Hub 连接

azure - 寻找在 Azure 上部署的 Multi-Tenancy 足迹架构的引用

powershell - 如何使用 PowerShell 从 Azure 函数查询 Azure 表

r - 如何在 R 中划分一组值(向量)