下面是一个快速而乏味的解决方案。
如果您有更好的,请将其包含在您的答案中。
let tree_height = 15;
range i from -1 to tree_height * 2 step 2
| extend side_width = tree_height + 1 - i / 2
| extend side_space = strrep(" ", side_width)
| extend tree_part = case(i > 0, strcat("/", strrep("*", i), @"\"), " ^ ")
| project ta_da = strcat(side_space, tree_part, side_space)
Run Code Online (Sandbox Code Playgroud)
^
/*\
/***\
/*****\
/*******\
/*********\
/***********\
/*************\
/***************\
/*****************\
/*******************\
/*********************\
/***********************\
/*************************\
/***************************\
/*****************************\
Run Code Online (Sandbox Code Playgroud)
kql azure-data-explorer azure-sentinel azure-monitor kusto-explorer
我有一个表,我想使用 Kusto 查询语言获取每个组的最新条目。这是表格:
文档状态日志
ID | 文档ID | 地位 | 创建日期 |
---|---|---|---|
2 | 1 | S1 | 2011年7月29日 |
3 | 1 | S2 | 2011年7月30日 |
6 | 1 | S1 | 2011年8月2日 |
1 | 2 | S1 | 2011年7月28日 |
4 | 2 | S2 | 2011年7月30日 |
5 | 2 | S3 | 2011年8月1日 |
6 | 3 | S1 | 2011年8月2日 |
该表将按 DocumentID 分组并按 DateCreated 降序排序。对于每个 DocumentID,我想获取最新状态。
我的首选输出:
文档ID | 地位 | 创建日期 |
---|---|---|
1 | S1 | 2011年8月2日 |
2 | S3 | 2011年8月1日 |
3 | S1 | 2011年8月2日 |
有没有办法使用 KQL 只获取每个组中的顶部?
GetOnlyTheTop伪代码如下:
SELECT
DocumentID,
GetOnlyTheTop(Status),
GetOnlyTheTop(DateCreated)
FROM DocumentStatusLogs
GROUP BY DocumentID
ORDER BY DateCreated DESC
Run Code Online (Sandbox Code Playgroud)
图片来源:改编自 DPP 的 SQL 问题:获取每组的前 1 行
group-by partition-by kql azure-data-explorer kusto-explorer
我有一个 Kusto 图表,其中的图例带有查询中的变量名称(平台)。我想从此图例中删除附加文本。我做了一些研究,并且能够从 SQL 中看到类似的结果,但是您能告诉我如何在 KQL 中做到这一点吗?
例如,从下面我想从图例中删除“平台”一词和包大小,并仅显示 Win_T3 和 Linux_T3
我希望图表图例仅显示 windows_C4 。从图例中删除图例和补丁大小。您可以在表中的第一张图片中看到落纱时间中图例的补丁大小
场景:kusto 表中的数据在 5 小时后更新。任务:从 .net API 调用查询 在查询中,创建一个子查询并使用该子查询对更大的表执行联接
let table1=materialize(
Customer|where CustomerId=="cust-reg-aabb-cc232"|distinct CustomerId,City);
CustomerPurchase
|where CustomerId=="cust-reg-aabb-cc232"
//perform join with table1 and other things
Run Code Online (Sandbox Code Playgroud)
或者
let table1=view(){
Customer|where CustomerId=="cust-reg-aabb-cc232"|distinct CustomerId,City};
CustomerPurchase
|where CustomerId=="cust-reg-aabb-cc232"
//perform join with table1 and CustomerPurchase
Run Code Online (Sandbox Code Playgroud)
CustomerPurchase 和客户数据每 5 小时更新一次(添加新行)。更优化的是:创建视图或使用materialize方法。我浏览了文档,但无法理解两者之间的区别。
另外,由于我正在实现 API,是否可以使用物化视图而不是 table1?
我的查询有 count 函数,它返回按天汇总的行数。现在,当该表中没有行时,我没有得到任何结果,而是需要包含所有天数的行并且计数为零。我尝试过coalesc
但没有成功。任何帮助深表感谢!
谢谢!
这是我的查询:
exceptions
| where name == 'my_scheduler' and timestamp > ago(30d)
| extend day = split(tostring(timestamp + 19800s), 'T')[0]
| summarize schedulerFailed = coalesce(count(),tolong("0")) by tostring(day)
Run Code Online (Sandbox Code Playgroud) CTRL
当我们选择 all ( + A
) run ( F5
)时,以下查询会成功。
let Foo = "foo";
let Bar = (baz: string) {
print baz;
};
Bar(Foo); // errors here
Run Code Online (Sandbox Code Playgroud)
问题是 Kusto Explorer 列出了两个问题。和 均Foo
未知Bar
。我们如何向他们介绍语言服务Foo
并Bar
让他们了解?
查询运行...
问题列表显示“名称‘Bar’未引用任何已知函数”以及“名称‘Foo’未引用任何已知列、表、变量或函数”。
我们如何才能让语言服务相信Foo
并且Bar
存在?
我正在尝试编写一个 Kusto 查询来查找在由另一列分组的列中具有最大值的记录,但还需要第三个(剩余)列。
假设有三列 A(时间戳)B(impvalue:数字)和 C(另一个值:字符串)。我需要获取按 C 和最大时间戳分组的记录及其相应的 B 列。
在 Sql 中,我很清楚如何使用自连接来做到这一点。我是 Kusto 的新手,我尝试了一些与 summarise、join 和 top 运算符的组合,但无法使其工作。
例子:
输出:
我正在检查 kusto 文档以检查是否可以创建直方图,但我似乎没有找到与直方图相关的任何内容。仅条形图和柱形图。
有没有办法在 KQL 中创建直方图或者这是不可能的?
我有一张 kusto 的表,有 13,000 行。我想知道如何在此表中创建一个新列,仅随机填充2 个值(0 和 1)。是否还可以创建一个包含 3 个不同数据类型值的列: string ?
我想根据数据表Fruit
中具有子字符串匹配的单元格通过连接这两个表来创建一个结果表Things
。
let Fruit = datatable(fruit:string)
[
"apple",
"banana"
"orange"
];
let Things = datatable(fruit:string)
[
"anappletree",
"myoranges"
];
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的事情:
Fruit
| join Things on $left.fruit contains $right.thing
Run Code Online (Sandbox Code Playgroud)
但出现此错误:
Semantic Error
join: only column entities or equality expressions are allowed in this context.
Run Code Online (Sandbox Code Playgroud)
所以这里不能用contains
。
我如何加入这个以便我可以获得一张包含以下内容的表格
"apple" | "anappletree"
"banana" | ""
"orange" | "myoranges"
Run Code Online (Sandbox Code Playgroud) 是否可以在不指定表名的情况下直接查询数据库范围?
例如,当我触发命令时.show database extents
,我会得到给定数据库中的范围列表。如果我从结果中选择一个特定的范围 id,或者通常属于该数据库的任何范围 id,有没有办法在不引用表名的情况下查询它?
我有一个要求,我需要规范/聚合每 1 秒轮询一次的数据,间隔为 1 分钟。我还有两列需要聚合,例如 SensorName、SensorValue。我可以将时间戳分为 1 分钟,但无法获取相应的两列。我怎么做?下面是我使用的查询和得到的输出。
Table
| where TimeStamp between (datetime(2020-09-01)..datetime(2020-09-30))
| summarize by bin(TimeStamp , 1min)
Run Code Online (Sandbox Code Playgroud)