【问题标题】:KQL Help: Need to trim the Datetime valueKQL 帮助:需要修剪 Datetime 值
【发布时间】:2021-10-26 00:27:43
【问题描述】:

我需要修剪 KQL 中的日期时间值。

我有基于定时器触发器的 Azure 功能,每 30 分钟运行一次

("0 */30 * * * *")]

我有 2 个日期时间列 StartTimeEndTime。我通过汇总 min(StartTime) - ma​​x(EndTime) 来获取 Azure Function 的运行时间。 我希望将 min(StartTime) 修剪为 Azure 函数的实际开始时间。

示例:如果 min(StartTime) 列值为“2021-10-25 10:02:26.7630995”,则 StartTime 应为“2021-10-25 10:00:00.000000”

如果 min(StartTime) 列值为“2021-10-25 10:32:26.7630995”,则 StartTime 应为 “2021-10-25 10:30:00.000000” "

到目前为止我的代码:(我需要第 4 行的帮助)

MyKustoTable | where isnotempty(RunID) and RunID > 41
| project RunID, CollectionTime, IngestionTime = ingestion_time()-30m
| summarize StartTime = min(CollectionTime), EndTime = max(IngestionTime) by RunID
| extend RBACDurationInMins = case((EndTime - StartTime)/1m > 30, "Trimmed StartTime", StartTime) 
| extend RBACDurationInMins = (EndTime - StartTime)/1m, ResourceType = "RBAC"
| project ResourceType, RunID, StartTime, EndTime, RBACDurationInMins
| sort by RunID desc

【问题讨论】:

    标签: azure-data-explorer kql


    【解决方案1】:

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

    如果 min(StartTime) 列值为“2021-10-25 10:02:26.7630995”,那么 StartTime 应为“2021-10-25 10:00:00.000000” p>

    如果 min(StartTime) 列值为“2021-10-25 10:32:26.7630995”,则 StartTime 应为“2021-10-25 10:30:00.000000” p>

    print dt1 = datetime(2021-10-25 10:02:26.7630995), 
          dt2 = datetime(2021-10-25 10:32:26.7630995)
    | project result1 = bin(dt1, 30m),
              result2 = bin(dt2, 30m)
    
    result1 result2
    2021-10-25 10:00:00.0000000 2021-10-25 10:30:00.0000000

    【讨论】:

    • 非常感谢@Yoni。 bin() 函数就像一个魅力。
    猜你喜欢
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    相关资源
    最近更新 更多