在应用程序中,有一组事件到达事件中心,作为流分析的一部分,我有一组要求,其中之一是查明某些记录集在过去 x 中是否尚未到达事件中心分钟。我在消息内有一个时间戳,它告诉我消息的有效时间,但是为了计算延迟(消息的有效时间和 now() 之间),我需要知道运行时的当前时间戳查询。
我尝试了 System.Timestamp,但它给了我值“1970-01-01T12:01:01.0010000Z”
消息的入队时间戳是最新的,例如“2018-05-06T00:00:00.1000000Z”...但不确定为什么 System.timestamp 不向我返回入队时间(当我没有使用“Timestamp By”时) “子句)。
所以,我有两个问题:
- 执行流分析查询时如何获取服务器的当前时间戳。
- 为什么 system.timestamp 不返回入队时间戳
查询: 选择 System.Timestamp 作为 ts 从 来源
结果: “1970-01-01T12:01:01.0010000Z”
输入数据中的时间戳均不早于 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 输出,然后在“概述”选项卡下,单击“开始”运行我的流分析作业,我可以成功检索 System.Timestamp 的正确值。
查询:
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 .
关于azure - 如何在运行 Azure 流分析查询时获取系统时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50225733/