问题
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