MAK
MAK

Reputation: 1288

Get Message object properties in stream analytics

This is a sample JSON input packet. I'm writing transformation queries to get the data and it is working fine.

[{
      "source": "xda",
      "data": 
        [{
            "masterTag": "UNIFY",
            "speed": 180
        }],
      "EventEnqueuedUtcTime": "2018-07-20T19:28:18.5230000Z",
  },
  {
      "source": "xda",
      "data": [{
            "masterTag": "UNIFY",
            "speed": 214
        }],
      "EventEnqueuedUtcTime": "2018-07-20T19:28:20.5550000Z",
  }
]

However, a custom property has been added to the message object when it is sent to IoT hub by the name of "proFilter". This is not inside the payload, but is present in the message object. I can get this property using Azure function but I'm not sure how to get it in Stream Analytics transformation query. Is there any way I can get it?

Basic transformation query:

WITH data AS
(
    SELECT
        source,
        GetArrayElement(data,0) as data_packet 
    FROM input 
)

SELECT 
    source, 
    data_packet.masterTag 
INTO 
    output
FROM data

Upvotes: 0

Views: 675

Answers (1)

Riccardo Bellini
Riccardo Bellini

Reputation: 260

Include the following function in your SELECT statement:

GetMetadataPropertyValue(input, '[User].[proFilter]') AS proFilter

If you are interested in retrieving all your custom properties as a record, you can use

GetMetadataPropertyValue(input, '[User]') AS userprops

See this doc for further reference

Upvotes: 2

Related Questions