如何在 运行 Azure 流分析查询时获取系统时间

How to get system time while running Azure Stream Analytics Query

在应用程序中,有一组事件到达事件中心,作为流分析的一部分,我有一组要求,其中之一是查明某组记录是否尚未到达事件中心最后 x 分钟。我在消息中有一个时间戳,它告诉我消息的有效时间,但是为了计算延迟(在消息的有效时间和 now() 之间),我需要知道当前的时间戳,当我 运行查询。

我试过 System.Timestamp,但它给了我值“1970-01-01T12:01:01.0010000Z”

消息的入队时间戳是最新的,例如“2018-05-06T00:00:00.1000000Z”...但不确定为什么 System.timestamp 没有 return 我入队时间(当我没有使用 "Timestamp By" 子句时)。

那么,我有两个问题:

  1. 如何在执行流分析查询时获取服务器的当前时间戳。
  2. 为什么system.timestamp没有return入队时间戳

查询: SELECT System.Timestamp 作为 ts 从 来源

结果: “1970-01-01T12:01:01.0010000Z”

None 输入数据中的时间戳早于 2018 年 5 月 6 日。

谢谢, 罗杰尼什

The Enqueue timestamp for the message is latest like "2018-05-06T00:00:00.1000000Z"... But not sure why System.timestamp does not return me the enqueue time (when I have not used "Timestamp By" Clause).

System.Timestamp (Stream Analytics)所述如下:

If a TIMESTAMP BY clause is not specified for a given input, arrival time of the event is used as a timestamp. For example Enqueued time of the event will be used in case of Event Hub input.

我刚刚测试了这个问题,发现如果你只是在Azure Portal的"JOB TOPOLOGY > Query"下测试查询,那么对于没有指定TIMESTAMP BY子句的方法,System.Timestamp的值将是1970-01-01T12:01:01.0010000Z。在指定 TIMESTAMP BY 子句时,System.Timestamp 的值将是您在 TIMESTAMP BY 子句中指定的列值。

然后,我刚刚为我的工作创建了一个 Blob 输入和 Blob 输出,然后在 Overview 选项卡下,单击 Start 以 运行 我的 Stream Analytics 工作,我可以成功检索 [=53= 的正确值].

查询:

SELECT birth,name,System.Timestamp as t   
into output
FROM input

测试:


更新:

How do I get current timestamp of the server when the stream analytics query is getting executed.

根据您的要求,我假设您可以使用 JavaScript UDF。我刚刚创建了一个示例 UDF,如下所示:

function main(s) {
    return new Date().toISOString();
}

测试:

您可以计算 UDF 内的延迟或利用内置函数 Date and Time Functions