簡體   English   中英

將帶有半隨機數據的 JSON 子字符串自動轉換為 KQL?

[英]Automate JSON substrings with semi-random data to KQL?

所以目前我有以下簡單的代碼來為自己構建一個表格並查看數據

azure_devops_work_item_events_CL
| summarize any(WorkItemType_s, TeamProject_s, Title_s, 
      AssignedTo_s, State_s, Reason_s) by WorkItemId_d, Relations_s
| order by WorkItemId_d desc

我的問題是 Relations_s 數據正在拉一個超長字符串,幾乎每個實例的長度都不同,盡管每個實例的格式都相同:

關系_s
[ {“rel”:“System.LinkTypes.Hierarchy-Reverse”,“url”:“https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/197138”, “屬性”:{“isLocked”:假,“名稱”:“父母”}}]
[ {“rel”:“System.LinkTypes.Hierarchy-Reverse”,“url”:“https://dev.azure.com/xxxx/d88804f3-b064-4489-9705/_apis/wit/workItems/234449”, “屬性”:{“isLocked”:假,“名稱”:“父母”}}]
[ {“rel”:“System.LinkTypes.Hierarchy-Forward”,“url”:“https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/247970”, “屬性”:{“isLocked”:假,“名稱”:“孩子”}},{“rel”:“System.LinkTypes.Hierarchy-Forward”,“url”:“https://dev.azure.com /xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/242838", "attributes": { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes .Hierarchy-Forward", "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/242835", "attributes": { "isLocked": false ,“名稱”:“孩子”} },{“rel”:“System.LinkTypes.Hierarchy-Forward”,“url”:“https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254 /_apis/wit/workItems/246163", "attributes": { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": “https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/234839”,“屬性”:{“isLocked”:假,“名稱”:“孩子”}} , { "rel": "System.LinkTypes.Hierarchy-Forwar d", "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/229566", "屬性": { "isLocked": false, "名稱": "子" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/ wit/workItems/228347", "attributes": { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": "https: //dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/240648", "attributes": { "isLocked": false, "name": "Child" } }, { " rel”:“System.LinkTypes.Hierarchy-Forward”,“url”:“https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/234833”,“屬性” : { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": "https://dev.azure.com/xxxx/ a69ffa35-e99f-42ea-a254/_apis/wit/workItems/240647", "attributes": { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-轉發”,“網址”:“https://dev.azure.com/xxxx/a69ffa 35-e99f-42ea-a254/_apis/wit/workItems/242837", "屬性": { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-轉發”,“url”:“https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/234803”,“屬性”:{“isLocked”:false,“名稱": "子" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/ wit/workItems/234801", "attributes": { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": "https: //dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/246352", "attributes": { "isLocked": false, "name": "Child" } }, { " rel”:“System.LinkTypes.Hierarchy-Forward”,“url”:“https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/242839”,“屬性” : { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": "https://dev.azure.com/xxxx/ a69ffa35-e99f-42ea-a254/_apis/wit/workItems/234834" ,“屬性”:{“isLocked”:false,“名稱”:“孩子”}},{“rel”:“System.LinkTypes.Hierarchy-Forward”,“url”:“https://dev.azure。 com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/234838", "屬性": { "isLocked": false, "name": "Child" } }, { "rel": "System. LinkTypes.Hierarchy-Forward”,“url”:“https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/242836”,“屬性”:{“isLocked”:假,“名稱”:“孩子”} },{“rel”:“System.LinkTypes.Hierarchy-Reverse”,“url”:“https://dev.azure.com/xxxx/a69ffa35-e99f-42ea- a254/_apis/wit/workItems/218335", "attributes": { "isLocked": false, "name": "Parent" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url" :“https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/234832”,“屬性”:{“isLocked”:假,“名稱”:“孩子”} }]

這是我查詢表時的一個小示例。 我完全不知道如何以一種能夠自動提取每個鏈接末尾的數字和每個字符串末尾的名稱部分的方式解析表格。 尤其是當表的某些部分在 1 中包含 40 個字符串時。請注意,如果這會影響到這一點,所有數據都是 JSON 的形式。 最終結果需要看起來像這樣

孩子 家長
240241 240541

或這個

物品 關聯
240241 孩子
240541 家長

為格式化道歉我無法將海量數據集正確格式化為表格

如果我正確理解了您的描述,您可以使用mv-applyparse運算符嘗試以下操作:

datatable(d:dynamic)
[
    dynamic([
    {
        "rel": "System.LinkTypes.Hierarchy-Reverse",
        "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/197138",
        "attributes": {
            "isLocked": false,
            "name": "Parent"
        }
    }
]), dynamic([
    {
        "rel": "System.LinkTypes.Hierarchy-Reverse",
        "url": "https://dev.azure.com/xxxx/d88804f3-b064-4489-9705/_apis/wit/workItems/234449",
        "attributes": {
            "isLocked": false,
            "name": "Parent"
        }
    }
]), dynamic([
    {
        "rel": "System.LinkTypes.Hierarchy-Forward",
        "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/247970",
        "attributes": {
            "isLocked": false,
            "name": "Child"
        }
    },
    {
        "rel": "System.LinkTypes.Hierarchy-Forward",
        "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/242838",
        "attributes": {
            "isLocked": false,
            "name": "Child"
        }
    },
    {
        "rel": "System.LinkTypes.Hierarchy-Forward",
        "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/242835",
        "attributes": {
            "isLocked": false,
            "name": "Child"
        }
    }
]),
]
| mv-apply d on (
    parse d with * "/workItems/" item:long *
    | extend link = tostring(d.attributes.name)
)
| project item, link
物品 關聯
197138 家長
234449 家長
247970 孩子
242838 孩子
242835 孩子

根據其名稱, Relations_s可能是一個字符串,因此需要轉換為 JSON(通過使用todynamic() )。

選項1
azure_devops_work_item_events_CL
|   mv-apply todynamic(Relations_s) on
    (
            parse       Relations_s.url with * "/" Item:long
        |   project     Item
                       ,Link = Relations_s.attributes.name
        |   summarize   Parent   = take_anyif   (Item ,Link == "Parent")
                       ,Children = make_list_if (Item ,Link == "Child")
    )
家長 孩子們
197138 []
234449 []
218335 [247970,242838,242835,246163,234839,229566,228347,240648,234833,240647,242837,234803,234801,246352,242839,234834,2324838,242836,]
選項 2
azure_devops_work_item_events_CL
|   mv-apply todynamic(Relations_s) on
    (
            parse       Relations_s.url with * "/" Item:long
        |   project     Item
                       ,Link = Relations_s.attributes.name
        |   summarize   Parent   = take_anyif   (Item ,Link == "Parent")
                       ,Children = make_list_if (Item ,Link == "Child")
        |   mv-expand   Children = iff(array_length(Children) == 0, dynamic(null), Children) to typeof(long)
    )
家長 孩子們
197138
234449
218335 247970
218335 242838
218335 242835
218335 246163
218335 234839
218335 229566
218335 228347
218335 240648
218335 234833
218335 240647
218335 242837
218335 234803
218335 234801
218335 246352
218335 242839
218335 234834
218335 234838
218335 242836
218335 234832

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM