range 运算符

生成值的单列表。

注意

此运算符不采用表格输入。

语法

rangecolumnNamefromstarttostopstepstep

详细了解语法约定

参数

客户 类型​​ 必需 描述
columnName string 输出表中的单列名称。
start int、long、real、datetime 或 timespan 输出中的最小值。
stop int、long、real、datetime 或 timespan 输出中正生成的最大值或最大值边界(如果 step 跳过此值)。
step int、long、real、datetime 或 timespan 两个连续值之间的差异。

注意

这些值不能引用任何表的列。 如需基于输入表计算范围,请使用 range 函数,可能需配合使用 mv-expand 运算符。

返回

一个包含单个列名为 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

以下示例演示如何将 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,其值是 147

range Steps from 1 to 8 step 3

以下示例演示如何使用 range 运算符创建小型的临时维度表,并使用该表在源数据不具有值的位置引入零。

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