azure - 使用 "greater than"运算符实现外连接

标签 azure azure-data-explorer kql

我正在编写 Kusto 查询以从 AppInsights 返回日志记录事件。我有一个代表“密码重置请求”的自定义事件,后面应该是“密码重置已确认”事件。当然,客户可以多次请求重置密码,即使是在同一小时内。我正在尝试创建一个 Kusto 查询,该查询向我显示所有“密码重置请求”事件的日期/时间,以及随后发生的“密码重置已确认”事件的日期/时间。

我使用外部联接,因为并非所有客户都会完成密码重置,因此“密码重置已确认”事件是可选的:

customEvents
| where name == "Password Reset Request"
| project CustomerId = tostring(customDimensions.["CustomerId"]), RequestDateTime = timestamp
| join kind = leftouter
    (
    customEvents
    | where name == "Password Reset Confirmed"
    | project CustomerId = tostring(customDimensions.["CustomerId"]), ConfirmDatetime = timestamp
    )
    on CustomerId

这样做的问题是,如果客户请求重置密码两次,我会得到 4 条匹配记录,因为两个“密码重置请求”事件中的每一个都连接到两个“密码重置已确认”事件。

我想要做的是用附加条件约束外连接,以便我只选择Confirm事件在Request事件之后的记录,如下所示:

on CustomerId, $right.ConfirmDatetime > $left.RequestDateTime

但 Kusto 查询语言似乎仅支持使用相等运算符的连接条件,不支持其他任何操作。是否可以实现这个查询?我见过this其中讨论了使用 binmv-expand 对查询连接进行时间限制,但我正在寻找不受时间窗口限制的东西,而只是寻找相应的使用“大于”运算符的事件。

谢谢。

最佳答案

这可以通过在 join 子句后添加过滤器来实现:

customEvents
| where name == "Password Reset Request"
| project CustomerId = tostring(customDimensions.["CustomerId"]), RequestDateTime = timestamp
| join kind = leftouter
    (
    customEvents
    | where name == "Password Reset Confirmed"
    | project CustomerId = tostring(customDimensions.["CustomerId"]), ConfirmDatetime = timestamp
    )
    on CustomerId
| where ConfirmDatetime > RequestDateTime

关于azure - 使用 "greater than"运算符实现外连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66970784/

相关文章:

powershell - 在资源管理器中添加 VHD 作为操作系统磁盘时出错

asp.net-mvc - 在 asp.net MVC 上创建 Azure 存储表

azure - 如何通过绑定(bind)到 Blob 存储的 Azure 事件网格触发 Azure 函数

azure - kusto 百分位数转换

c# - Azure Functions V4 .NET 7 以编程方式获取默认/主 key

azure-data-explorer - 总结在连接字符串中选择选项 true/false 的次数

azure - 动态数组上的 Kusto UDF(映射字符串值)

azure - 如何在azure KQL中列出LogEntry中的所有json key

regex - 如何编写使用正则表达式过滤 where 子句的 Kusto 查询

Azure 数据资源管理器成本估算器给出了难以置信的估算