【问题标题】:Kusto Query Language: semantic error on user-defined functionsKusto 查询语言:用户定义函数的语义错误
【发布时间】:2023-01-20 23:24:02
【问题描述】:

你好 StackOverflow 社区。

我最近想出了一个关于 KQL 的有趣教程/游戏,我正在尝试解决网站上提出的难题。 其中之一使用以下功能来显示地图

.create-or-alter function with (docstring = "Virtual tour starts here", skipvalidation = "true") VirtualTourLink(lat:real, lon:real) { 
    print Link=strcat('https://www.google.com/maps/@', lat, ',', lon, ',4a,75y,32.0h,79.0t/data=!3m7!1e1!3m5!1s-1P!2e0!5s20191101T000000!7i16384!8i8192')}

我正在尝试将此函数与一些已知值一起使用(请参见下面的示例)

nyc_trees
| invoke VirtualTourLink(lat=40.6777207, lon=-73.86205414)

但是,KQL 编译器提示错误,指出该函数只接受两个参数。 你知道为什么会这样吗?

【问题讨论】:

    标签: azure azure-data-explorer kql


    【解决方案1】:

    函数体基本上是一个打印陈述。
    打印是表格运算符(产生单行);因此,您应该将该函数视为一个表:

    VirtualTourLink(lat=40.6777207, lon=-73.86205414)
    

    附言 如果你想在表的行上执行函数,你可以像这样重新定义它(删除打印所以该函数将返回一个标量):

    .create-or-alter function with (docstring = "Virtual tour starts here", skipvalidation = "true") VirtualTourLink(lat:real, lon:real) { 
        strcat('https://www.google.com/maps/@', lat, ',', lon, ',4a,75y,32.0h,79.0t/data=!3m7!1e1!3m5!1s-1P!2e0!5s20191101T000000!7i16384!8i8192')}
    

    用法将如下所示:

    nyc_trees
    | sample 5
    | project tree_id
             ,latitude
             ,longitude
             ,VTL = VirtualTourLink(lat=latitude, lon=longitude)
    

    Fiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      相关资源
      最近更新 更多