用半随机数据自动化JSON子字符串到KQL?

发布于 2025-02-10 16:34:02 字数 4770 浏览 3 评论 0原文

因此,目前,我有以下简单的代码,仅为我自己构建一个表并查看数据

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

我的问题是REMATIGHT_S数据正在拉一个超长字符串,每个实例的长度几乎都不同,尽管每个ex的格式都是相同的:

resseady_s
[{“ rel”:“ system.linktypes.erhierarchy-reverse”,“ url”:“ https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-42ea-42ea-42ea-a254/_apis/_apis/withit/workitems/197138 “,”属性“:{” ISLOCKED“:false”,“名称”:“ parent”}}]
[{“ rel”:“ system.linktypes.hierarchy-reverse”,“ url”:“ https:// dev。 azure.com/xxxx/d888804f3-b064-4489-9705/_apis/wit/workitems/234449“,”属性“:{” islocked':islocked“:false”:false,“ name” name'name':“ parent”}}}}}}]
[ }}] “ system.linktypes.hierarchy-forward”,“ url”:“ https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-42ea-a254/_apis/_apis/wit/workitems/workitems/workitems/247970”,“ Islocked“:false,” name”:“ child”}},{“ rel”:“ system.linktypes.hierarchy-forward”,“ url”:“ https://dev.azure.com/xxxxx/a69ffa355-e999f -42EA-A254/_APIS/WIT/WORKITEMS/242838“,“属性”:{“ Islocked”:false,“ name”:“ child”}},{“ rel”:“ system.linktypes.linktypes.hierarchy-forward”, “ url”:“ https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/with/workitems/242835”,“属性”,“属性”:儿童“}},{“ rel”:“ system.linktypes.hierarchy-forward”,“ url”:“ https://dev.azure.com/xxxxx/a69ffa35-e99f-e99f-42ea-42ea-42ea-42ea-a254/_apis/_apis/workitems/workitems /246163“,“属性”:{“ Islocked”:false,“ name”:“ child”}},{“ rel”:“ system.linktypes.hierarchy-forward”,“ url”,“ url”:“ https:// https:// 。 “ system.linktypes.hierarchy-forward”,“ url”:“ https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-42ea-a254/_apis/_apis/wit/workitems/workitems/229566” Islocked“:false,” name”:“ child”}},{“ rel”:“ system.linktypes.hierarchy-forward”,“ url”:“ https://dev.azure.com/xxxxx/a69ffa355-e999f -42EA-A254/_APIS/WIT/WORKITEMS/228347“,“属性”:{“ Islocked”:false,“ name”:“ child”}},{“ rel”:“ system.linktypes.linktypes.linktypes.hierarchy-forward”, “ url”:“ https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workitems/workitems/240648”,“属性”,“属性”:儿童“}},{“ rel”:“ system.linktypes.hierarchy-forward”,“ url”:“ https://dev.azure.com/xxxxx/a69ffa35-e99f-e99f-42ea-42ea-42ea-42ea-a254/_apis/_apis/workitems/workitems /234833“,“属性”:{“ Islocked”:false,“ name”:“ child”}},{“ rel”:“ system.linktypes.hierarchy-forward”,“ url”,“ url”:“ https:// https:// 。 “ system.linktypes.hierarchy-forward”,“ url”:“ https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-42ea-a254/_apis/_apis/wits/workitems/workitems/workitems/242837” Islocked“:false,” name”:“ child”}},{“ rel”:“ system.linktypes.hierarchy-forward”,“ url”:“ https://dev.azure.com/xxxxx/a69ffa355-e999f -42EA-A254/_APIS/WIT/WORKITEMS/234803“,“属性”:{“ Islocked”:false,“ name”:“ child”}},{“ rel”:“ system.linktypes.linktypes.hierarchy-forward”, “ url”:“ https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workitems/workitems/234801”,“属性”,“属性”:儿童“}},{“ rel”:“ system.linktypes.hierarchy-forward”,“ url”:“ https://dev.azure.com/xxxxx/a69ffa35-e99f-e99f-42ea-42ea-42ea-42ea-a254/_apis/_apis/workitems/workitems /246352“,“属性”:{“ Islocked”:false,“ name”:“ child”}},{“ rel”:“ system.linktypes.hierarchy-forward”,“ url”,“ url”:“ https:// 。 “ system.linktypes.hierarchy-forward”,“ url”:“ https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-42ea-a254/_apis/_apis/_apis/withet/workitems/workitems/234834”,“ Islocked“:false,” name”:“ child”}},{“ rel”:“ system.linktypes.hierarchy-forward”,“ url”:“ https://dev.azure.com/xxxxx/a69ffa355-e999f -42EA-A254/_APIS/WIT/WORKITEMS/234838“,“属性”:{“ Islocked”:false,“ name”:“ child”}},{“ rel”:“ system.linktypes.linktypes.hierarchy-forward”,hierarchy-ford-forward”, “ url”:“ https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/with/workitems/242836”,“属性”,“属性”:儿童“}},{“ rel”:“ system.linktypes.hierarchy-resverse”,“ url”:“ https://dev.azure.com/xxxxxxxx x/a69ffa35-e99f-42eaf-42ea-42ea-42ea-42ea-a254/_apis/_apis/wwit/workitemss /218335“,“属性”:{“ Islocked”:false,“ name”:“ parent”}},{“ rel”:“ system.linktypes.hierarchy-forward”,“ url”,“ url”:“ https:// 。

​当我询问我的桌子时的样子。我完全失去了如何以一种方式来解析表,使我能够自动化每个链接末尾的数字以及每个字符串末端的名称部分。尤其是当表的某些部分在1中有40个字符串时。请注意,如果完全影响这一点,请注意所有数据均以JSON的形式进行。最终结果需要看起来像这个

孩子父母
240241240541

或此

项目链接
240241儿童
240541父母

对格式道歉,我无法将大量数据设置为正确地格式化到表中

So currently I have the following simple code to just build out a table for myself and look at data

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

My problem is the Relations_s data is pulling a super long string that's different in length pretty much every instance although the format is the same for each one ex:

Relations_s
[ { "rel": "System.LinkTypes.Hierarchy-Reverse", "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/197138", "attributes": { "isLocked": false, "name": "Parent" } } ]
[ { "rel": "System.LinkTypes.Hierarchy-Reverse", "url": "https://dev.azure.com/xxxx/d88804f3-b064-4489-9705/_apis/wit/workItems/234449", "attributes": { "isLocked": false, "name": "Parent" } } ]
[ { "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" } }, { "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", "attributes": { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/229566", "attributes": { "isLocked": false, "name": "Child" } }, { "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", "attributes": { "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-Forward", "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/242837", "attributes": { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/234803", "attributes": { "isLocked": false, "name": "Child" } }, { "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", "attributes": { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/234834", "attributes": { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/234838", "attributes": { "isLocked": false, "name": "Child" } }, { "rel": "System.LinkTypes.Hierarchy-Forward", "url": "https://dev.azure.com/xxxx/a69ffa35-e99f-42ea-a254/_apis/wit/workItems/242836", "attributes": { "isLocked": false, "name": "Child" } }, { "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", "attributes": { "isLocked": false, "name": "Child" } } ]

This is a small sample of what my table looks like when I query it. I'm completely lost on how I can parse the table in such a way that I'm able to automate pulling the number at the end of every link and the name portion at the end of each string. Especially when some parts of the table have 40 strings in 1. Note all the data is in the form of a JSON if that impacts this at all. The end result needs to look something like this

ChildParent
240241240541

Or this

ItemLink
240241Child
240541Parent

Apologies for the formatting I can't get the massive data set to properly format into a table

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

救星 2025-02-17 16:34:02

根据其名称Ressection_s可能是一个字符串,因此需要转换为JSON(通过使用todynamic())。

Option 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")
    )
ParentChildren
197138[]
234449[]
218335[247970,242838,242835,246163,234839,229566,228347,240648,234833,240647,242837,234803,234801,246352,242839,234834,234838,242836,234832]
Option 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)
    )
ParentChildren
197138
234449
218335247970
218335242838
218335242835
218335246163
218335234839
218335229566
218335228347
218335240648
218335234833
218335240647
218335242837
218335234803
218335234801
218335246352
218335242839
218335234834
218335234838
218335242836
218335234832

According to its name Relations_s is probably a string, therefore needs conversion to JSON (by using todynamic()).

Option 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")
    )
ParentChildren
197138[]
234449[]
218335[247970,242838,242835,246163,234839,229566,228347,240648,234833,240647,242837,234803,234801,246352,242839,234834,234838,242836,234832]
Option 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)
    )
ParentChildren
197138
234449
218335247970
218335242838
218335242835
218335246163
218335234839
218335229566
218335228347
218335240648
218335234833
218335240647
218335242837
218335234803
218335234801
218335246352
218335242839
218335234834
218335234838
218335242836
218335234832
吻风 2025-02-17 16:34:02

如果我正确理解了您的描述,则可以使用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
itemlink
197138父母
234449父母
247970儿童
242838儿童
242835CHILD CHILD

If I understood your description correctly, you could try the following, using the mv-apply and parse operators:

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
itemlink
197138Parent
234449Parent
247970Child
242838Child
242835Child
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文