在 Kusto 中解析数据

Parse data in Kusto

我正在尝试在 Kusto 中解析以下数据。需要帮助。

[[ObjectCount][LinkCount][DurationInUs]]
[ChangeEnumeration][[88][9][346194]]
[ModifyTargetInLive][[3][6][595903]]

需要没有任何硬编码的通用实现。

理想情况下 - 您可以更改以该格式生成源数据的组件以使用标准格式(例如 CSV、Json 等)。

以下可能有效,但您应该考虑它非常低效

let T = datatable(s:string)
[
    '[[ObjectCount][LinkCount][DurationInUs]]',
    '[ChangeEnumeration][[88][9][346194]]',
    '[ModifyTargetInLive][[3][6][595903]]',
];
let keys = toscalar(
    T
    | where s startswith "[["
    | take 1
    | project extract_all(@'\[([^\[\]]+)\]', s)
);
T
| where s !startswith "[["
| project values = extract_all(@'\[([^\[\]]+)\]', s)
| mv-apply with_itemindex = i keys on (
    extend Category = tostring(values[0]), p = pack(tostring(keys[i]), values[i + 1])
    | summarize b = make_bag(p) by Category
)
| project-away values
| evaluate bag_unpack(b)

--->

| Category           | ObjectCount | LinkCount | DurationInUs |
|--------------------|-------------|-----------|--------------|
| ChangeEnumeration  | 88          | 9         | 346194       |
| ModifyTargetInLive | 3           | 6         | 595903       |