KQL 加入最大值
KQL Join on max value
我需要加入 table 到 return 右侧 table 的 MAX 值。我曾尝试使用 'datatable' 模拟它,但失败得很惨 :(。我会尝试用文字描述。
T1 = datatable(ID:int, Properties:string, ConfigTime:datetime) [1,'a,b,c','2021-03-04 00:00:00']
T2 = datatable(ID:int, Properties:string, ConfigTime:datetime) [2,'a,b,c','2021-03-02 00:00:00', 3,'a,b','2021-03-01 00:00:00', 4,'c','2021-03-20 00:00:00']
我将其用作 T2 上的更新策略,它具有 T1 的源。所以我想 select T1 中的行,然后加入 T2 中具有最高时间戳的行。我的第一次尝试如下:
T1 | join kind=inner T2 on Id
| summarize arg_max(ConfigTime1, Id, Properties, Properties1, ConfigTime) by Id
| project Id, Properties, ConfigTime
在我的实际更新策略中,我合并了 T1 和 T2 的属性,然后写入 T2,但为了简单起见,我暂时保留了它。
目前,我的 T2 中没有从更新策略中获得任何输出。任何关于我应该这样做的另一种方式的指导将不胜感激。谢谢
我想你要找的是工会
let T1 = datatable(ID:int, Properties:string, ConfigTime:datetime) [
1,'a,b,c','2021-03-04 00:00:00'
];
let T2 = datatable(ID:int, Properties:string, ConfigTime:datetime) [
2,'a,b,c','2021-03-02 00:00:00',
3,'a,b','2021-03-01 00:00:00',
4,'c','2021-03-20 00:00:00'
];
下面是一个使用带有 summarize max 的变量的例子:
let Latest = toscalar(T2 | summarize max(ConfigTime));
T1
| union (T2 | where ConfigTime == Latest)
结果将保留 T1 中的条目,并且仅保留 T2 中的最新条目。
如果这没有反映您的预期结果,请显示您的预期输出。
您似乎想将 arg_max 计算推入联接的 T2 端,如下所示:
T1
| join kind=inner (
T2
| summarize arg_max(ConfigTime1, Id, Properties, Properties1, ConfigTime) by Id
| project Id, Properties, ConfigTime
) on Id
请注意,为确保可接受的性能,您希望限制 arg_max 搜索的时间范围,因此您应该考虑在 arg_max 之前使用基于时间的过滤器。
我需要加入 table 到 return 右侧 table 的 MAX 值。我曾尝试使用 'datatable' 模拟它,但失败得很惨 :(。我会尝试用文字描述。
T1 = datatable(ID:int, Properties:string, ConfigTime:datetime) [1,'a,b,c','2021-03-04 00:00:00']
T2 = datatable(ID:int, Properties:string, ConfigTime:datetime) [2,'a,b,c','2021-03-02 00:00:00', 3,'a,b','2021-03-01 00:00:00', 4,'c','2021-03-20 00:00:00']
我将其用作 T2 上的更新策略,它具有 T1 的源。所以我想 select T1 中的行,然后加入 T2 中具有最高时间戳的行。我的第一次尝试如下:
T1 | join kind=inner T2 on Id
| summarize arg_max(ConfigTime1, Id, Properties, Properties1, ConfigTime) by Id
| project Id, Properties, ConfigTime
在我的实际更新策略中,我合并了 T1 和 T2 的属性,然后写入 T2,但为了简单起见,我暂时保留了它。
目前,我的 T2 中没有从更新策略中获得任何输出。任何关于我应该这样做的另一种方式的指导将不胜感激。谢谢
我想你要找的是工会
let T1 = datatable(ID:int, Properties:string, ConfigTime:datetime) [
1,'a,b,c','2021-03-04 00:00:00'
];
let T2 = datatable(ID:int, Properties:string, ConfigTime:datetime) [
2,'a,b,c','2021-03-02 00:00:00',
3,'a,b','2021-03-01 00:00:00',
4,'c','2021-03-20 00:00:00'
];
下面是一个使用带有 summarize max 的变量的例子:
let Latest = toscalar(T2 | summarize max(ConfigTime));
T1
| union (T2 | where ConfigTime == Latest)
结果将保留 T1 中的条目,并且仅保留 T2 中的最新条目。
如果这没有反映您的预期结果,请显示您的预期输出。
您似乎想将 arg_max 计算推入联接的 T2 端,如下所示:
T1
| join kind=inner (
T2
| summarize arg_max(ConfigTime1, Id, Properties, Properties1, ConfigTime) by Id
| project Id, Properties, ConfigTime
) on Id
请注意,为确保可接受的性能,您希望限制 arg_max 搜索的时间范围,因此您应该考虑在 arg_max 之前使用基于时间的过滤器。