【问题标题】:Need Help on KQL with Over Partitions在 KQL 上需要过度分区的帮助
【发布时间】:2022-01-02 09:53:17
【问题描述】:

我是 KQL 的新手,需要您对以下查询的帮助和建议。

我有如下数据:

Date         Identity  totalIngressInGB
2021-10-10     x            10
2021-10-10     y            20
2021-10-10     z            30
2021-10-10     q            10
2021-10-11     x            11
2021-10-11     y            22
2021-10-11     z            33
2021-10-11     p            10
2021-10-11     q            5

我想打印如下:

  • 尝试打印当天值(totalIngressInGB_c)和前一天值(totalIngressInGB_p),然后进行差异。

  • 在 diffInGB 列中仅打印正值,因为我只需要增量值。

Date          Identity  totalIngressInGB_c totalIngressInGB_p diffInGB
2021-10-11       X           11                  10              1
2021-10-11       y           22                  20              2
2021-10-11       z           33                  30              3
2021-10-11       p           10                  0               10

下面是 Hive SQL 中的代码和来自我们实际数据库的查询结果,现在数据在 ADX 中,我需要在 KQL 中打印相同的数据。我尝试了很多方法都无法在 KQL 中达到如下所示的准确结果。

【问题讨论】:

    标签: azure-data-explorer kql


    【解决方案1】:

    你可以使用prev()函数:https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/prevfunction

    table(Date:datetime, Identity :string, totalIngressInGB:long)
    [
        datetime(2021-10-10), 'x', 10,
        datetime(2021-10-10), 'y', 20,
        datetime(2021-10-10), 'z', 30,
        datetime(2021-10-10), 'q', 10,
        datetime(2021-10-11), 'x', 11,
        datetime(2021-10-11), 'y', 22,
        datetime(2021-10-11), 'z', 33,
        datetime(2021-10-11), 'p', 10,
        datetime(2021-10-11), 'q', 5,
    ]
    | order by Identity asc, Date asc 
    | project Date, Identity, totalIngressInGB_c = totalIngressInGB,
              totalIngressInGB_p = case(prev(Identity) == Identity, prev(totalIngressInGB),
                                        isempty(prev(Identity)), 0,
                                        long(null))
    | extend diff = totalIngressInGB_c - totalIngressInGB_p
    | where diff > 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-04
      • 2021-01-16
      • 2011-07-10
      • 2011-06-23
      • 2014-11-04
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      相关资源
      最近更新 更多