Search code examples
azure-stream-analytics

In Azure Stream Analytics Query I am getting an error when using Timestamp by


I have some data coming in and I need to calculate the parts per min value in the stream. The following is my query

WITH first AS (
SELECT
   TS.ArrayIndex,
   TS.ArrayValue.FQN,
   TS.ArrayValue.vqts
FROM
  [EventHubInput] as hub
CROSS APPLY GetArrayElements(hub.timeseries) AS TS )

SELECT first.FQN ,( max(cast(vqt.arrayvalue.v as BIGINT))-(min(cast(vqt.arrayvalue.v as BIGINT)))) AS PPM  
FROM first  
CROSS APPLY GetArrayElements(first.vqts) AS vqt where first.FQN like '%Production%' and vqt.arrayvalue.q = 192 
timestamp by
vqt.arrayvalue.t
group by 
first.FQN, TumblingWindow(minute, 1)

I get an error when I add timestamp by vqt.arrayvalue.t

My input data looks like this..

{
  "timeSeries": [
    {
        "fqn":"MyEnterprise.Gateways.GatewayE.CLX.Tags.StateBasic",
            "vqts":[
                    {
                    "v": "" ,
                    "q": 192 ,
                    "t":"2016-06-24T16:39:45.683+0000"
                    }
        ]
    },              {
        "fqn":"MyEnterprise.Gateways.GatewayE.CLX.Tags.ProductionCount",
            "vqts":[
                    {
                    "v": 264 ,
                    "q": 192 ,
                    "t":"2016-06-24T16:39:45.683+0000"
                    }
        ]
    },              {
        "fqn":".Gateways.GatewayE.CLX.Tags.StateDetailed",
            "vqts":[
                    {
                    "v": "" ,
                    "q": 192 ,
                    "t":"2016-06-24T16:39:45.683+0000"
                    }
        ]
    }           ]

}

It would be great if anybody could help!!


Solution

  • A single event from the stream can only have one timestamp field. What you are currently doing is assigning timestamp for each individual array value from this event. Unfortunately this is currently unsupported.

    Possible workaround is to split your ASA job into two. The first one will not use TIMESTAMP BY but will do CROSS APPLY and send array values as individual event to intermediate Event Hub. The second job will read from there, use TIMESTAMP BY and apply the rest of the logic.