你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
range 运算符
生成值的单列表。
注意
此运算符不采用表格输入。
语法
range
columnNamefrom
startto
stopstep
step
详细了解语法约定。
参数
客户 | 类型 | 必需 | 描述 |
---|---|---|---|
columnName | string |
✔️ | 输出表中的单列名称。 |
start | int、long、real、datetime 或 timespan | ✔️ | 输出中的最小值。 |
stop | int、long、real、datetime 或 timespan | ✔️ | 输出中正生成的最大值或最大值边界(如果 step 跳过此值)。 |
step | int、long、real、datetime 或 timespan | ✔️ | 两个连续值之间的差异。 |
返回
一个包含单个列 columnName 的表,其值包括 start、start step...,直至 stop+
。
示例
过去七天的范围
以下示例创建一个表,其中包含过去七天内延长的当前时间戳的条目,每天一次。
range LastWeek from ago(7d) to now() step 1d
输出
LastWeek |
---|
2015-12-05 09:10:04.627 |
2015-12-06 09:10:04.627 |
... |
2015-12-12 09:10:04.627 |
合并不同的停止时间
以下示例演示如何使用 union
运算符扩展范围以使用多次停止时间。
let Range1 = range Time from datetime(2024-01-01) to datetime(2024-01-05) step 1d;
let Range2 = range Time from datetime(2024-01-06) to datetime(2024-01-10) step 1d;
union Range1, Range2
| order by Time asc
输出
时间 |
---|
2024-01-04 00:00:00.0000000 |
2024-01-05 00:00:00.0000000 |
2024-01-06 00:00:00.0000000 |
2024-01-07 00:00:00.0000000 |
2024-01-08 00:00:00.0000000 |
2024-01-09 00:00:00.0000000 |
2024-01-10 00:00:00.0000000 |
使用参数的范围
以下示例演示如何将 range
运算符与参数配合使用,这些参数随后会作为表进行扩展和使用。
let toUnixTime = (dt:datetime)
{
(dt - datetime(1970-01-01)) / 1s
};
let MyMonthStart = startofmonth(now()); //Start of month
let StepBy = 4.534h; //Supported timespans
let nn = 64000; // Row Count parametrized
let MyTimeline = range MyMonthHour from MyMonthStart to now() step StepBy
| extend MyMonthHourinUnixTime = toUnixTime(MyMonthHour), DateOnly = bin(MyMonthHour,1d), TimeOnly = MyMonthHour - bin(MyMonthHour,1d)
; MyTimeline | order by MyMonthHour asc | take nn
输出
MyMonthHour | MyMonthHourinUnixTime | DateOnly | TimeOnly |
---|---|---|---|
2023-02-01 | 00:00:00.0000000 | 1675209600 | 2023-02-01 00:00:00.0000000 |
2023-02-01 | 04:32:02.4000000 | 1675225922.4 | 2023-02-01 00:00:00.0000000 |
2023-02-01 | 09:04:04.8000000 | 1675242244.8 | 2023-02-01 00:00:00.0000000 |
2023-02-01 | 13:36:07.2000000 | 1675258567.2 | 2023-02-01 00:00:00.0000000 |
... | ... | ... | ... |
递增步骤
以下示例创建一个表,其中包含一个名为 Steps
的列,其类型为 long
,并导致值从 1 到 8 递增 3。
range Steps from 1 to 8 step 3
| Steps |
|-------|
| 1 |
| 4 |
| 7 |
### Traces over a time range
The following example shows how the `range` operator can be used to create a dimension table that is used to introduce zeros where the source data has no values. It takes timestamps from the last four hours and counts traces for each one minute interval. When there are no traces for a specific interval, the count is zero.
```kusto
range TIMESTAMP from ago(4h) to now() step 1m
| join kind=fullouter
(Traces
| where TIMESTAMP > ago(4h)
| summarize Count=count() by bin(TIMESTAMP, 1m)
) on TIMESTAMP
| project Count=iff(isnull(Count), 0, Count), TIMESTAMP
| render timechart