扁平化依赖关系

问题描述 投票:0回答:2

我有

dependency
A
,其中有其他
parentId
dependency
B
,其中有
parentId
dependency
C
,其中有
parentId
request
R
 

其他一些依赖项与请求的连接较短,例如

A -> B -> R

dependency
A
如何获取
request
对象?

如何从最底层

dependency
到父级
request

我认为这可以通过使用

operation_Id
来实现,但事实并非如此,当存在一系列API调用时,一个API调用另一个API,将会有多个具有相同
operation_id

的请求
azure-application-insights kql
2个回答
2
投票

可以使用 3 个连接来构建展平列表:

datatable (id: int, parrentId: int, name: string)[
1, int(null), 'R1',
2, 1, 'C1',
3, 2, 'B1',
4, 3, 'A1',
5, int(null), 'R2',
6, 5, 'B2',
7, 6, 'A2',
]
| as T
| where isnull(parrentId)
| join kind=leftouter (T) on $left.id == $right.parrentId
| join kind=leftouter (T) on $left.id1 == $right.parrentId
| join kind=leftouter (T) on $left.id2 == $right.parrentId
| project request=id, lowest= coalesce(id3, id2, id1)

2
投票

根据应用,也可以使用扫描操作员来解决任务。

datatable (t: int, id: int, parrentId: int, name: string)[
1, 1, int(null), 'R1',
2, 2, 1, 'C1',
3, 3, 2, 'B1',
4, 4, 3, 'A1',
5, 5, int(null), 'R2',
6, 6, 5, 'B2',
7, 7, 6, 'A2',
]
| sort by t
| scan declare (leaf:int) with (
step Child output=none: name startswith 'A' or id == Child.parrentId
 => leaf= coalesce(Child.leaf, id);
step Root: isnull(parrentId) and id == Child.parrentId => leaf= Child.leaf;
)

扫描运算符需要对事件进行排序,从最后一个依赖事件到请求事件。 Child 步骤匹配最后一个依赖项(叶)和以下依赖项。步骤 Root 与请求匹配。只有步骤 Root 具有带有附加列叶的输出。如果结果中不需要叶 ID,则可以简化查询。

© www.soinside.com 2019 - 2024. All rights reserved.