Ao.Zhang
Ao.Zhang

Reputation: 17

Azure Stream Analytics has function like GETDATE() or CURRENT_TIMESTAMP?

My scenarios is that sensors always store data at local,sometime these data will be uploaded to Event Hub but I don't need all the data,I need filter data by a time field in Azure Stream Analytics. But Azure Stream does not have GETDATE() or CURRENT_TIMESTAMP. Is there any other alternatives ?

SELECT
  devId,
  dataType,
  utc
INTO
  into
FROM
  output
WHERE
 (TRY_CAST(utc AS bigint) IS NOT NULL) AND
 (DATEADD(millisecond, utc, '1970/01/01 GMT') >= DATEADD(minute,-5,CURRENT_TIMESTAMP))

Upvotes: 1

Views: 3203

Answers (1)

You can use System.Timestamp like here and also filter/group by for a given time window:

SELECT * INTO ArchiveOutput FROM Input TIMESTAMP BY Time

SELECT Make, System.TimeStamp AS Time, COUNT(*) AS [Count] INTO AlertOutput FROM Input TIMESTAMP BY Time GROUP BY Make, TumblingWindow(second, 10) HAVING [Count] >= 3

You have many other examples here https://azure.microsoft.com/en-us/documentation/articles/stream-analytics-stream-analytics-query-patterns/#query-example-find-last-event-in-a-window

Upvotes: 2

Related Questions