SomeGuy
SomeGuy

Reputation: 265

Query the ouput and get latest file name

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"

Upvotes: 0

Views: 409

Answers (1)

Yoni L.
Yoni L.

Reputation: 25955

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

Upvotes: 1

Related Questions