Hello @kunming jian ,
welcome to this moderated Azure community forum.
I tested the given message format and tried to transform that format in a regular table format:
WITH IotBaseInput AS(
SELECT
*
FROM
Input1
),
EventEachBinary AS(
SELECT
iot.deviceId,
CAST(iot.recordTime AS datetime) as recordTime,
CAST(GetArrayElement(iot.data, 0).type AS bigint) AS Type,
CAST(GetArrayElement(iot.data, 0).event1 AS bigint) AS Event1,
CAST(GetArrayElement(iot.data, 0).event2 AS bigint) AS Event2
FROM
IotBaseInput as iot
)
SELECT
*
FROM EventEachBinary
Note: The query can be optimized by I stayed quite close to your sample query.
It gives me:
I used this GetArrayElement because the JSON array has only one element.
It's recommended to test this for yourself using VS Code and the Stream Analytics Extension. There, you can test with a local file as input.
If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.