Query the ouput and get latest file name

自古美人都是妖i 提交于 2019-12-24 18:46:57

问题


Below is the kusto query:

ADFActivityRun
| where PipelineName contains "MyPipeline" 
| where OperationName == "Failed" 
| order by TimeGenerated desc
| take 1

The Output column gives below result:

    "{
  ""name"": ""varFileNames"",
  ""value"": [
    {
      ""name"": ""Z400_EEE_20191110_ERR.txt"",
      ""type"": ""File""
    },
    {
      ""name"": ""Z400_CCC_20191119_ERR.txt"",
      ""type"": ""File""
    },
    {
      ""name"": ""Z400_DDD_20191121_ERR.txt"",
      ""type"": ""File""
    },
    {
      ""name"": ""Z400_EEE_20191122_ERR.txt"",
      ""type"": ""File""
    },
    {
      ""name"": ""Z400_AAA_20191202_ERR.txt"",
      ""type"": ""File""
    }
  ]
}"

File names has yyyymmdd in it. I want to get only the text file name which is latest. In above case - Z400_AAA_20191202_ERR.txt

Intent is to send alert that - "The above error file is available, please check this file"


回答1:


you could use mv-apply for achieving that.

for example:

print d = dynamic({
    "name": "varFileNames",
    "value": [
        {
            "name": "Z400_EEE_20191110_ERR.txt",
            "type": "File"
        },
        {
            "name": "Z400_CCC_20191119_ERR.txt",
            "type": "File"
        },
        {
            "name": "Z400_DDD_20191121_ERR.txt",
            "type": "File"
        },
        {
            "name": "Z400_EEE_20191122_ERR.txt",
            "type": "File"
        },
        {
            "name": "Z400_AAA_20191202_ERR.txt",
            "type": "File"
        }
    ]
})
| mv-apply value = d.value on (
    parse value.name with * "_" * "_" dt:datetime "_" *
    | top 1 by dt desc
    | project name = value.name
)
| project name


来源:https://stackoverflow.com/questions/59423885/query-the-ouput-and-get-latest-file-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!