Skip to content
Advertisement

unpivot columns into two new columns in Stream Analytics

I have a stream from IoT Hub like:

I want to pass this stream in a SQL DB like this:

is there any way to use cross apply or other way to create two new columns form multi json element

Advertisement

Answer

If it’s a static pivot (you know in advance the list of fields and you can hardcode their value), then you get there with something like this:

You create one CTE per entities to extract and UNION them all at the end.

If you have dynamic values, you will need to use a JavaScript UDF. I don’t have a code sample sadly. It should be straightforward (but a bit painful).

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement