【问题标题】:What is the azure table storage query equivalent of T-sql's LIKE command?与 T-sql 的 LIKE 命令等效的天蓝色表存储查询是什么?
【发布时间】:2013-03-17 14:48:03
【问题描述】:

我正在使用 Azure 存储资源管理器查询 Azure 表存储。我想查找包含给定文本的所有消息,就像在 T-SQL 中这样:

message like '%SysFn%'

执行 T-SQL 给出“处理此请求时发生错误”

此查询在 Azure 中的等效项是什么?

【问题讨论】:

    标签: azure azure-sql-database azure-storage azure-table-storage


    【解决方案1】:

    没有直接的等价物,因为没有通配符搜索。所有支持的操作都列在here 中。您会看到 eq、gt、ge、lt、le 等。也许您可以利用这些来查找特定范围。

    根据您的分区方案,您可以根据特定的分区键选择实体子集,然后扫描每个实体,检查 message 以找到您需要的特定实体(基本上是部分分区扫描) .

    【讨论】:

      【解决方案2】:

      虽然在 Azure 表存储中不能严格执行高级通配符搜索,但您可以结合使用“ge”和“lt”运算符来实现“前缀”搜索。这个过程在 Scott Helme here 的博客文章中进行了解释。

      本质上,此方法使用 ASCII 递增来查询 Azure 表存储以查找其属性以特定文本字符串开头的任何行。我编写了一个小型 Powershell 函数,它生成执行前缀搜索所需的自定义过滤器。

      Function Get-AzTableWildcardFilter {
          param (
              [Parameter(Mandatory=$true)]
              [string]$FilterProperty,
      
              [Parameter(Mandatory=$true)]
              [string]$FilterText
          )
      
          Begin {}
      
          Process {
              $SearchArray = ([char[]]$FilterText)
              $SearchArray[-1] = [char](([int]$SearchArray[-1]) + 1)
              $SearchString = ($SearchArray -join '')
          }
      
          End {
              Write-Output "($($FilterProperty) ge '$($FilterText)') and ($($FilterProperty) lt '$($SearchString)')"
          }
      }
      

      然后您可以像这样将这个函数与Get-AzTableRow 一起使用(其中$CloudTable 是您的Microsoft.Azure.Cosmos.Table.CloudTable 对象):

      Get-AzTableRow -Table $CloudTable -CustomFilter (Get-AzTableWildcardFilter -FilterProperty 'RowKey' -FilterText 'foo')
      

      【讨论】:

        【解决方案3】:

        另一种选择是将日志从 Azure 表存储导出到 csv。获得 csv 文件后,您可以在 excel 或任何其他应用程序中打开它并搜索文本。

        您可以使用 TableXplorer (http://clumsyleaf.com/products/tablexplorer) 导出表存储数据。这里有一个选项可以将过滤后的数据导出到 csv。

        【讨论】:

          猜你喜欢
          • 2012-11-17
          • 1970-01-01
          • 2016-12-11
          • 2020-10-21
          • 2019-06-07
          • 2011-01-07
          • 1970-01-01
          • 1970-01-01
          • 2012-08-23
          相关资源
          最近更新 更多