【问题标题】:Kusto KQL equivalent to LIKE CONCAT column with value (mysql)Kusto KQL 等效于具有值的 LIKE CONCAT 列(mysql)
【发布时间】:2020-01-30 11:30:13
【问题描述】:

我正在尝试翻译以下 MySQL (v5.6) 查询:

SELECT name FROM world WHERE capital LIKE CONCAT(name, '%city')

进入 Kusto KQL,但以下不起作用:

world | where capital matches regex strcat(name,".*city") | project name

可能是因为matches regex 只接受一个字符串值,而concat(name,".*city") 是一个列。

即使以下方法也不起作用:

world | extend a =  strcat(name, ".*City") | where capital matches regex a

关于如何将此查询转换为 KQL 的任何建议?

【问题讨论】:

    标签: mysql azure azure-data-explorer kql


    【解决方案1】:

    matches regex 的参数必须是标量字符串常量,并且可以取决于行上下文。

    如果您可以对实际数据做出任何假设,您可能根本不需要使用正则表达式,并且有多种字符串运算符可供选择(当然取决于数据和要求): https://docs.microsoft.com/en-us/azure/kusto/query/datatypes-string-operators

    例如:

    let world = datatable(capital:string)
    [
        "Belize City",
        "Jeruslam",
        "Mexico City",
        "Tulum",
        "NotARealCity"
    ]
    ;
    world
    | extend _ends_with = capital endswith "city",
                   _has = capital has "city",
              _contains = capital contains "city"
    

    结果:

    | capital      | _ends_with | _has | _contains |
    |--------------|------------|------|-----------|
    | Belize City  | 1          | 1    | 1         |
    | Jeruslam     | 0          | 0    | 0         |
    | Mexico City  | 1          | 1    | 1         |
    | Tulum        | 0          | 0    | 0         |
    | NotARealCity | 1          | 0    | 1         |
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 2016-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多