计算行数,直到获得当前拥有的团队值... Kusto,countof()

Count rows until you get to the current owning team value... Kusto, countof()

我有我一直在尝试开发的 Kusto 代码,如有任何帮助,我们将不胜感激。

objective是算到CurrentOwningTeamId在OwningTeamId列中第一次出现。

我打包了所有者团队编号并将值解析为它自己的一列。在我到达当前拥有团队之前,我需要计算拥有团队。 列是(示例):

Objective:计数到使用 Kusto(Application Insights 代码)在 OwningTeamId 列中第一次出现 CurrentOwningTeam 值:

[代码]

   OwningTeamId,   CurrenOwningTeam,    CreateDate,   RequestType
       155523          **888888**        2017-07-02    PRIMARY
       256924          **888888**        2017-08-02    TRANSFER
     **888888**        **888888**        2017-09-02    TRANSFER
       954005          **888888**        2017-10-02    TRANSFER
     **888888**        **888888**        2017-11-02    TRANSFER
       155523          **888888**        2017-12-02    TRANSFER
       954005          **888888**        2017-13-02    TRANSFER
     **888888**        **888888**        2017-14-02    TRANSFER

[/CODE]

我认为您可以使用 countof() 函数匹配当前拥有的团队,但我不知道如何使用正则表达式进行匹配。注意:每个事件的每个拥有团队的值都不同,这就是为什么我首先捕获事件的拥有团队并尝试计算 OwningTeamId 列中 CurrentOwningTeam 编号的第一个实例。换句话说,我想计算到达第一个拥有团队所需的次数。在这种情况下,它将是三个。

注意:OwningTeamId 和 CurrentOwningTeam 可以在每次事件中更改,我首先捕获 CurrentOwningTeam 然后尝试在 OwningTeamId 列中进行匹配。

注意:这只是一个事件,但我正在尝试做多个事件。 以下是我如何获得当前拥有的团队价值。 [/CODE]

  | extend CurrentOwningTeam=pack_array(OwningTeamId)
  | parse CurrentOwningTeam with * "[" CurrentOwningTeam:int "]" *
  | serialize CurrentOwningTeam

[/CODE]

我尝试使用 row_number() 但它不适用于多个事件,只能针对每个事件,因此我必须使用 count 或 countof 函数或其他方法。

感谢您的澄清。这是一个查询的建议,该查询计算按时间排序的行,直到达到特定条件(计数是使用 IncidentId 键的上下文)。

datatable(IncidentId:string, OwningTeamId:string, CurrentOwningTeam:string, CreateDate:datetime, RequestType:string)
[
'Id1','155523','888888',datetime(2017-02-07),'PRIMARY',
'Id1','256924','888888',datetime(2017-02-08),'TRANSFER',
'Id1','888888','888888',datetime(2017-02-09),'TRANSFER',
'Id1','954005','888888',datetime(2017-02-10),'TRANSFER',
'Id1','888888','888888',datetime(2017-02-11),'TRANSFER',
'Id1','155523','888888',datetime(2017-02-12),'TRANSFER',
'Id1','954005','888888',datetime(2017-02-13),'TRANSFER',
'Id1','888888','888888',datetime(2017-02-14),'TRANSFER',
// Id2
'Id2','155523','888888',datetime(2017-02-07),'PRIMARY',
'Id2','256924','888888',datetime(2017-02-08),'TRANSFER',
'Id2','999999','888888',datetime(2017-02-09),'TRANSFER',
'Id2','954005','888888',datetime(2017-02-10),'TRANSFER',
'Id2','888888','888888',datetime(2017-02-11),'TRANSFER',
'Id2','155523','888888',datetime(2017-02-12),'TRANSFER',
'Id2','954005','888888',datetime(2017-02-13),'TRANSFER',
'Id2','888888','888888',datetime(2017-02-14),'TRANSFER',
]
| order by IncidentId, CreateDate asc
| extend c= row_cumsum(1, IncidentId!=prev(IncidentId))
| where OwningTeamId == CurrentOwningTeam 
| summarize arg_min(CreateDate, c) by IncidentId

结果:

IncidentId  CreateDate  c
Id1  2017-02-09 00:00:00.0000000  3
Id2  2017-02-11 00:00:00.0000000  5

这里是指向如何使用 arg_min() 聚合查找最早记录的文档的 link,link 指向 row_cumsum()(累计总和)函数。

https://docs.microsoft.com/en-us/azure/kusto/query/arg-min-aggfunction https://docs.microsoft.com/en-us/azure/kusto/query/rowcumsumfunction

我通过直接使用 RowNumber 在 table 中进行分组来解决这个问题,然后最后求和得到我的总数。

      [CODE]

      | serialize Id  
      | extend RowNumber=row_number(1, (Id) ==Id)  
      | summarize TotalOwningTeamChanges=sum(RowNumber) by Id  

      [/CODE]

然后我得到了最小日期,将整个数据集提取到当前 OwningTeamName 的第一个实例。

      [CODE]
      //Outside the scope of the table.
      | extend ExtractFirstOwningTeamCreateDate=CreateDate2  
      | extend VeryFirstOwningTeamCreateDate=MinimumCreateDate  
      | where FirstOwningTeamRow == true or MinimumCreateDate <=
              ExtractFirstOwningTeamCreateDate  
      | serialize VeryFirstOwningTeamCreateDate  

      [/CODE]