条件结果 - Azure 数据资源管理器/日志分析/KQL
Conditional Result - Azure Data Explorer / Log Analytics / KQL
目前,我正在查询 returns Union
3 个表(总共 13 行)。所有 3 个表都有相同的列集。
当前查询
let bytes_to_gb =
(1024 * 1024 * 1024)
;
let tab_cpu =
performanceCounters
| where category == "Processor" and counter == "% Processor Time" and instance == "_Total"
| where ...
| summarize timestamp = max(timestamp), value = avg(value) by host_name = cloud_RoleInstance, host_type = "WXYZ", counter_name = "%CPU", threshold = 90
;
let tab_memory =
performanceCounters
| where category == "Memory" and counter == "Available Bytes"
| where ...
| summarize timestamp = max(timestamp), value = avg(value / bytes_to_gb) by host_name = cloud_RoleInstance, host_type = "ZYXW", counter_name = "Available Memory (GB)", threshold = 10
;
let tab_exceptions =
exceptions
| where ...
| summarize timestamp = max(timestamp), value = (count(itemCount) * 1.0) by host_name = "Exceptions", host_type = "Web", counter_name = "Exception", threshold = 10
| where value >= 10
union
tab_cpu, // 6 rows
tab_memory, // 6 rows
tab_exceptions // 1 row
我正在寻找的是 - 包含 tab_cpu
和 tab_memory
的结果 只有 如果 tab_exceptions
有行。
这就是我在 SQL 查询中所做的,但没有得到 KQL 的正确解决方案。
IF EXISTS (SELECT * FROM tab_exceptions WHERE ...)
SELECT * FROM tab_cpu WHERE ...;
UNION
SELECT * FROM tab_memory WHERE ...
UNION
SELECT * FROM tab_exceptions WHERE ...
ELSE
...
您可以按照类似于以下示例的方式使用 union
运算符:
let T1 = range x from 1 to 3 step 1; // for the other case, replace with: let T1 = datatable(x:long)[];
let T2 = range x from 4 to 6 step 1;
let T3 = range x from 7 to 9 step 1;
let T1_has_rows = toscalar(T1 | summarize count() > 0);
union
(T1 | where T1_has_rows == false),
(union T1, T2, T3 | where T1_has_rows == true)
目前,我正在查询 returns Union
3 个表(总共 13 行)。所有 3 个表都有相同的列集。
当前查询
let bytes_to_gb =
(1024 * 1024 * 1024)
;
let tab_cpu =
performanceCounters
| where category == "Processor" and counter == "% Processor Time" and instance == "_Total"
| where ...
| summarize timestamp = max(timestamp), value = avg(value) by host_name = cloud_RoleInstance, host_type = "WXYZ", counter_name = "%CPU", threshold = 90
;
let tab_memory =
performanceCounters
| where category == "Memory" and counter == "Available Bytes"
| where ...
| summarize timestamp = max(timestamp), value = avg(value / bytes_to_gb) by host_name = cloud_RoleInstance, host_type = "ZYXW", counter_name = "Available Memory (GB)", threshold = 10
;
let tab_exceptions =
exceptions
| where ...
| summarize timestamp = max(timestamp), value = (count(itemCount) * 1.0) by host_name = "Exceptions", host_type = "Web", counter_name = "Exception", threshold = 10
| where value >= 10
union
tab_cpu, // 6 rows
tab_memory, // 6 rows
tab_exceptions // 1 row
我正在寻找的是 - 包含 tab_cpu
和 tab_memory
的结果 只有 如果 tab_exceptions
有行。
这就是我在 SQL 查询中所做的,但没有得到 KQL 的正确解决方案。
IF EXISTS (SELECT * FROM tab_exceptions WHERE ...)
SELECT * FROM tab_cpu WHERE ...;
UNION
SELECT * FROM tab_memory WHERE ...
UNION
SELECT * FROM tab_exceptions WHERE ...
ELSE
...
您可以按照类似于以下示例的方式使用 union
运算符:
let T1 = range x from 1 to 3 step 1; // for the other case, replace with: let T1 = datatable(x:long)[];
let T2 = range x from 4 to 6 step 1;
let T3 = range x from 7 to 9 step 1;
let T1_has_rows = toscalar(T1 | summarize count() > 0);
union
(T1 | where T1_has_rows == false),
(union T1, T2, T3 | where T1_has_rows == true)