0

我正在尝试使用 Azure 数据资源管理器/Kusto 查询从管道运行数据创建另一列。我对 Kusto 很陌生,不知道该怎么做。目标是为每一位客户,

  1. 如果上一次运行失败并且最后一次运行失败,则失败之间的天数/小时差。
  2. 如果上一次运行成功而上一次运行失败,则获取事件之间的天数/小时差
  3. 如果上一个事件失败而上一个事件成功,则忽略。

数据集

Customers   PipelineType    PipelineState    TimeStamp
CustomerA   PipelineA   Succes               2021-08-13 12:59:03.0073653
CustomerA   PipelineA   Fail                 2021-08-13 09:59:03.0124853
CustomerA   PipelineB   Succes               2021-08-13 11:56:03.0151948
CustomerA   Pipeline B  Fail                 2021-08-12 17:56:03.0019445
CustomerA   Pipeline C  Succes               2021-08-13 13:16:03.0015617
CustomerA   Pipeline C  Fail                 2021-07-30 21:52:03.0157372
CustomerB   PipelineA   Succes               2021-08-13 12:59:03.0073331
CustomerB   PipelineA   Succes               2021-08-13 12:57:03.0099138
CustomerB   PipelineB   Fail                 2021-07-30 03:33:03.0123262
CustomerB   Pipeline B  Succes               2021-08-13 13:16:03.0015297
CustomerB   Pipeline C  Fail                 2021-08-13 12:57:03.0099499
CustomerB   Pipeline C  Succes               2021-08-13 13:16:03.0016348
CustomerC   PipelineA   Succes               2021-08-13 13:16:03.0016999
CustomerC   PipelineA   Succes               2021-08-13 12:59:03.0074113
CustomerC   PipelineB   Succes               2021-08-13 10:56:03.0075546
CustomerC   Pipeline B  Fail                 2021-08-11 06:54:03.0118628
CustomerC   Pipeline C  Fail                 2021-08-13 13:16:03.0016233
CustomerC   Pipeline C  Fail                 2021-08-13 12:59:03.0072337
``
4

1 回答 1

1

如果我正确理解要求,您可以对数据集进行排序,然后使用case()andprev()函数。

例如:

datatable(customer:string, PipelineType:string, PipelineState:string, TimeStamp:datetime)
[
    'CustomerA', 'Pipeline A', 'Fail',    datetime(2021-08-13 12:59:03.0073653),
    'CustomerA', 'Pipeline A', 'Fail',    datetime(2021-08-13 09:59:03.0124853),
    'CustomerA', 'Pipeline B', 'Success', datetime(2021-08-13 11:56:03.0151948),
    'CustomerA', 'Pipeline B', 'Fail',    datetime(2021-08-12 17:56:03.0019445),
    'CustomerA', 'Pipeline C', 'Success', datetime(2021-08-13 13:16:03.0015617),
    'CustomerA', 'Pipeline C', 'Fail',    datetime(2021-07-30 21:52:03.0157372),
    'CustomerB', 'Pipeline A', 'Fail',    datetime(2021-08-13 12:59:03.0073331),
    'CustomerB', 'Pipeline A', 'Success', datetime(2021-08-13 12:57:03.0099138),
    'CustomerB', 'Pipeline B', 'Fail',    datetime(2021-07-30 03:33:03.0123262),
    'CustomerB', 'Pipeline B', 'Success', datetime(2021-08-13 13:16:03.0015297),
    'CustomerB', 'Pipeline C', 'Fail',    datetime(2021-08-13 12:57:03.0099499),
    'CustomerB', 'Pipeline C', 'Success', datetime(2021-08-13 13:16:03.0016348),
    'CustomerC', 'Pipeline A', 'Fail',    datetime(2021-08-13 13:16:03.0016999),
    'CustomerC', 'Pipeline A', 'Fail',    datetime(2021-08-13 12:59:03.0074113),
    'CustomerC', 'Pipeline B', 'Success', datetime(2021-08-13 10:56:03.0075546),
    'CustomerC', 'Pipeline B', 'Fail',    datetime(2021-08-11 06:54:03.0118628),
    'CustomerC', 'Pipeline C', 'Fail',    datetime(2021-08-13 13:16:03.0016233),
    'CustomerC', 'Pipeline C', 'Fail',    datetime(2021-08-13 12:59:03.0072337),
]   
| order by customer asc, PipelineType asc, TimeStamp asc
| extend result = case(prev(customer) == customer and prev(PipelineType) == PipelineType and PipelineState == 'Fail', TimeStamp - prev(TimeStamp), timespan(null))
顾客 管道类型 管道状态 时间戳 结果
客户A 管道 A 失败 2021-08-13 09:59:03.0124853
客户A 管道 A 失败 2021-08-13 12:59:03.0073653 02:59:59.9948800
客户A 管道 B 失败 2021-08-12 17:56:03.0019445
客户A 管道 B 成功 2021-08-13 11:56:03.0151948
客户A 管道 C 失败 2021-07-30 21:52:03.0157372
客户A 管道 C 成功 2021-08-13 13:16:03.0015617
客户B 管道 A 成功 2021-08-13 12:57:03.0099138
客户B 管道 A 失败 2021-08-13 12:59:03.0073331 00:01:59.9974193
客户B 管道 B 失败 2021-07-30 03:33:03.0123262
客户B 管道 B 成功 2021-08-13 13:16:03.0015297
客户B 管道 C 失败 2021-08-13 12:57:03.0099499
客户B 管道 C 成功 2021-08-13 13:16:03.0016348
客户C 管道 A 失败 2021-08-13 12:59:03.0074113
客户C 管道 A 失败 2021-08-13 13:16:03.0016999 00:16:59.9942886
客户C 管道 B 失败 2021-08-11 06:54:03.0118628
客户C 管道 B 成功 2021-08-13 10:56:03.0075546
客户C 管道 C 失败 2021-08-13 12:59:03.0072337
客户C 管道 C 失败 2021-08-13 13:16:03.0016233 00:16:59.9943896

更新:回复您的评论 - 只需添加适当的过滤器。

例如:

datatable(customer:string, PipelineType:string, PipelineState:string, TimeStamp:datetime)
[
    'CustomerA', 'Pipeline A', 'Fail',    datetime(2021-08-13 12:59:03.0073653),
    'CustomerA', 'Pipeline A', 'Fail',    datetime(2021-08-13 09:59:03.0124853),
    'CustomerA', 'Pipeline B', 'Success', datetime(2021-08-13 11:56:03.0151948),
    'CustomerA', 'Pipeline B', 'Fail',    datetime(2021-08-12 17:56:03.0019445),
    'CustomerA', 'Pipeline C', 'Success', datetime(2021-08-13 13:16:03.0015617),
    'CustomerA', 'Pipeline C', 'Fail',    datetime(2021-07-30 21:52:03.0157372),
    'CustomerB', 'Pipeline A', 'Fail',    datetime(2021-08-13 12:59:03.0073331),
    'CustomerB', 'Pipeline A', 'Success', datetime(2021-08-13 12:57:03.0099138),
    'CustomerB', 'Pipeline B', 'Fail',    datetime(2021-07-30 03:33:03.0123262),
    'CustomerB', 'Pipeline B', 'Success', datetime(2021-08-13 13:16:03.0015297),
    'CustomerB', 'Pipeline C', 'Fail',    datetime(2021-08-13 12:57:03.0099499),
    'CustomerB', 'Pipeline C', 'Success', datetime(2021-08-13 13:16:03.0016348),
    'CustomerC', 'Pipeline A', 'Fail',    datetime(2021-08-13 13:16:03.0016999),
    'CustomerC', 'Pipeline A', 'Fail',    datetime(2021-08-13 12:59:03.0074113),
    'CustomerC', 'Pipeline B', 'Success', datetime(2021-08-13 10:56:03.0075546),
    'CustomerC', 'Pipeline B', 'Fail',    datetime(2021-08-11 06:54:03.0118628),
    'CustomerC', 'Pipeline C', 'Fail',    datetime(2021-08-13 13:16:03.0016233),
    'CustomerC', 'Pipeline C', 'Fail',    datetime(2021-08-13 12:59:03.0072337),
]   
| order by customer asc, PipelineType asc, TimeStamp asc
| where not((prev(customer) == customer and prev(PipelineType) == PipelineType and PipelineState == 'Success' and prev(PipelineState) == 'Fail') or 
            (prev(customer) == customer and prev(PipelineType) == PipelineType and PipelineState == 'Fail' and next(PipelineState) == 'Success'))
| extend result = case(prev(customer) == customer and prev(PipelineType) == PipelineType and PipelineState == 'Fail', TimeStamp - prev(TimeStamp), timespan(null))
顾客 管道类型 管道状态 时间戳 结果
客户A 管道 A 失败 2021-08-13 09:59:03.0124853
客户A 管道 A 失败 2021-08-13 12:59:03.0073653 02:59:59.9948800
客户A 管道 B 失败 2021-08-12 17:56:03.0019445
客户A 管道 C 失败 2021-07-30 21:52:03.0157372
客户B 管道 A 成功 2021-08-13 12:57:03.0099138
客户B 管道 A 失败 2021-08-13 12:59:03.0073331 00:01:59.9974193
客户B 管道 B 失败 2021-07-30 03:33:03.0123262
客户B 管道 C 失败 2021-08-13 12:57:03.0099499
客户C 管道 A 失败 2021-08-13 12:59:03.0074113
客户C 管道 A 失败 2021-08-13 13:16:03.0016999 00:16:59.9942886
客户C 管道 B 失败 2021-08-11 06:54:03.0118628
客户C 管道 C 失败 2021-08-13 12:59:03.0072337
客户C 管道 C 失败 2021-08-13 13:16:03.0016233 00:16:59.9943896
于 2021-08-13T14:59:27.967 回答