Azure stream analytics job using arrays

Multi tool use
I set up a job in stream analytics that takes messages from a IotHub and loads the values in a SQL table.
Everything worked fine when using only one set of values per message, however I wanted to send several sets of values in a single message using an array.
The following is an example of a Json message that reaches the job:
[{
"valores": {
"0": {
"voltage": 230.8,
"current": 0.18,
"power": 32.093,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:20.1690000Z"
},
"1": {
"voltage": 230.7,
"current": 0.144,
"power": 23.759,
"frequency": 50.1,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:25.1690000Z"
},
"2": {
"voltage": 230.7,
"current": 0.143,
"power": 23.369,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:30.1740000Z"
},
"3": {
"voltage": 230.4,
"current": 0.163,
"power": 28.075,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:35.1730000Z"
},
"4": {
"voltage": 230.5,
"current": 0.167,
"power": 29.207,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:40.1810000Z"
},
},
"EventProcessedUtcTime": "2018-12-27T16:03:00.9574234Z",
"PartitionId": 3,
"EventEnqueuedUtcTime": "2018-12-27T16:02:58.0290000Z",
"IoTHub": {
"MessageId": null,
"CorrelationId": null,
"ConnectionDeviceId": "RaspberryPi-Teste1",
"ConnectionDeviceGenerationId": "636807313519039605",
"EnqueuedTime": "2018-12-27T16:02:58.0260000Z",
"StreamId": null
}
}
]
This output was obtained from the sample data utility in the Job.
I tried to set up a test query that collects only a single column for the DB (dvcid), however when I test the query I get a message with" An unexpected error has occured."
SELECT
StageElement.arrayvalue.dvcid as dvcid
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
CROSS APPLY GetArrayElements(evento.valores) AS StageElement
The job fails when I try to start it.
When I test the following query everything works fine, and I can see all the array Valores in a single column:
SELECT
*
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
I cant figure out what I am doing wrong.
azure-iot-hub azure-stream-analytics
New contributor
dsd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I set up a job in stream analytics that takes messages from a IotHub and loads the values in a SQL table.
Everything worked fine when using only one set of values per message, however I wanted to send several sets of values in a single message using an array.
The following is an example of a Json message that reaches the job:
[{
"valores": {
"0": {
"voltage": 230.8,
"current": 0.18,
"power": 32.093,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:20.1690000Z"
},
"1": {
"voltage": 230.7,
"current": 0.144,
"power": 23.759,
"frequency": 50.1,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:25.1690000Z"
},
"2": {
"voltage": 230.7,
"current": 0.143,
"power": 23.369,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:30.1740000Z"
},
"3": {
"voltage": 230.4,
"current": 0.163,
"power": 28.075,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:35.1730000Z"
},
"4": {
"voltage": 230.5,
"current": 0.167,
"power": 29.207,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:40.1810000Z"
},
},
"EventProcessedUtcTime": "2018-12-27T16:03:00.9574234Z",
"PartitionId": 3,
"EventEnqueuedUtcTime": "2018-12-27T16:02:58.0290000Z",
"IoTHub": {
"MessageId": null,
"CorrelationId": null,
"ConnectionDeviceId": "RaspberryPi-Teste1",
"ConnectionDeviceGenerationId": "636807313519039605",
"EnqueuedTime": "2018-12-27T16:02:58.0260000Z",
"StreamId": null
}
}
]
This output was obtained from the sample data utility in the Job.
I tried to set up a test query that collects only a single column for the DB (dvcid), however when I test the query I get a message with" An unexpected error has occured."
SELECT
StageElement.arrayvalue.dvcid as dvcid
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
CROSS APPLY GetArrayElements(evento.valores) AS StageElement
The job fails when I try to start it.
When I test the following query everything works fine, and I can see all the array Valores in a single column:
SELECT
*
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
I cant figure out what I am doing wrong.
azure-iot-hub azure-stream-analytics
New contributor
dsd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I set up a job in stream analytics that takes messages from a IotHub and loads the values in a SQL table.
Everything worked fine when using only one set of values per message, however I wanted to send several sets of values in a single message using an array.
The following is an example of a Json message that reaches the job:
[{
"valores": {
"0": {
"voltage": 230.8,
"current": 0.18,
"power": 32.093,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:20.1690000Z"
},
"1": {
"voltage": 230.7,
"current": 0.144,
"power": 23.759,
"frequency": 50.1,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:25.1690000Z"
},
"2": {
"voltage": 230.7,
"current": 0.143,
"power": 23.369,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:30.1740000Z"
},
"3": {
"voltage": 230.4,
"current": 0.163,
"power": 28.075,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:35.1730000Z"
},
"4": {
"voltage": 230.5,
"current": 0.167,
"power": 29.207,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:40.1810000Z"
},
},
"EventProcessedUtcTime": "2018-12-27T16:03:00.9574234Z",
"PartitionId": 3,
"EventEnqueuedUtcTime": "2018-12-27T16:02:58.0290000Z",
"IoTHub": {
"MessageId": null,
"CorrelationId": null,
"ConnectionDeviceId": "RaspberryPi-Teste1",
"ConnectionDeviceGenerationId": "636807313519039605",
"EnqueuedTime": "2018-12-27T16:02:58.0260000Z",
"StreamId": null
}
}
]
This output was obtained from the sample data utility in the Job.
I tried to set up a test query that collects only a single column for the DB (dvcid), however when I test the query I get a message with" An unexpected error has occured."
SELECT
StageElement.arrayvalue.dvcid as dvcid
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
CROSS APPLY GetArrayElements(evento.valores) AS StageElement
The job fails when I try to start it.
When I test the following query everything works fine, and I can see all the array Valores in a single column:
SELECT
*
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
I cant figure out what I am doing wrong.
azure-iot-hub azure-stream-analytics
New contributor
dsd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I set up a job in stream analytics that takes messages from a IotHub and loads the values in a SQL table.
Everything worked fine when using only one set of values per message, however I wanted to send several sets of values in a single message using an array.
The following is an example of a Json message that reaches the job:
[{
"valores": {
"0": {
"voltage": 230.8,
"current": 0.18,
"power": 32.093,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:20.1690000Z"
},
"1": {
"voltage": 230.7,
"current": 0.144,
"power": 23.759,
"frequency": 50.1,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:25.1690000Z"
},
"2": {
"voltage": 230.7,
"current": 0.143,
"power": 23.369,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:30.1740000Z"
},
"3": {
"voltage": 230.4,
"current": 0.163,
"power": 28.075,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:35.1730000Z"
},
"4": {
"voltage": 230.5,
"current": 0.167,
"power": 29.207,
"frequency": 50,
"energy": 0.71,
"dvcid": 1,
"gway": "SPC-G02",
"time": "2018-12-27T16:02:40.1810000Z"
},
},
"EventProcessedUtcTime": "2018-12-27T16:03:00.9574234Z",
"PartitionId": 3,
"EventEnqueuedUtcTime": "2018-12-27T16:02:58.0290000Z",
"IoTHub": {
"MessageId": null,
"CorrelationId": null,
"ConnectionDeviceId": "RaspberryPi-Teste1",
"ConnectionDeviceGenerationId": "636807313519039605",
"EnqueuedTime": "2018-12-27T16:02:58.0260000Z",
"StreamId": null
}
}
]
This output was obtained from the sample data utility in the Job.
I tried to set up a test query that collects only a single column for the DB (dvcid), however when I test the query I get a message with" An unexpected error has occured."
SELECT
StageElement.arrayvalue.dvcid as dvcid
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
CROSS APPLY GetArrayElements(evento.valores) AS StageElement
The job fails when I try to start it.
When I test the following query everything works fine, and I can see all the array Valores in a single column:
SELECT
*
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
I cant figure out what I am doing wrong.
azure-iot-hub azure-stream-analytics
azure-iot-hub azure-stream-analytics
New contributor
dsd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
dsd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
dsd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Dec 27 '18 at 16:36


dsd
1
1
New contributor
dsd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
dsd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
dsd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
GetArrayElement is used for Array elements in JSON. In your case, you have nested JSON, so you need to use GetRecordProperties.
Here's the modified queries
SELECT
StageElement.PropertyValue.dvcid as dvcid
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
CROSS APPLY GetRecordProperties(evento.valores) AS StageElement
Let me know if it works for you.
Thanks,
JS
I'm embarassed for such a basic mistake. I corrected the JSON data replacing it for an array and the query worked fine. Thank you for the answer.
– dsd
Dec 28 '18 at 9:33
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
dsd is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53948131%2fazure-stream-analytics-job-using-arrays%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
GetArrayElement is used for Array elements in JSON. In your case, you have nested JSON, so you need to use GetRecordProperties.
Here's the modified queries
SELECT
StageElement.PropertyValue.dvcid as dvcid
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
CROSS APPLY GetRecordProperties(evento.valores) AS StageElement
Let me know if it works for you.
Thanks,
JS
I'm embarassed for such a basic mistake. I corrected the JSON data replacing it for an array and the query worked fine. Thank you for the answer.
– dsd
Dec 28 '18 at 9:33
add a comment |
GetArrayElement is used for Array elements in JSON. In your case, you have nested JSON, so you need to use GetRecordProperties.
Here's the modified queries
SELECT
StageElement.PropertyValue.dvcid as dvcid
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
CROSS APPLY GetRecordProperties(evento.valores) AS StageElement
Let me know if it works for you.
Thanks,
JS
I'm embarassed for such a basic mistake. I corrected the JSON data replacing it for an array and the query worked fine. Thank you for the answer.
– dsd
Dec 28 '18 at 9:33
add a comment |
GetArrayElement is used for Array elements in JSON. In your case, you have nested JSON, so you need to use GetRecordProperties.
Here's the modified queries
SELECT
StageElement.PropertyValue.dvcid as dvcid
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
CROSS APPLY GetRecordProperties(evento.valores) AS StageElement
Let me know if it works for you.
Thanks,
JS
GetArrayElement is used for Array elements in JSON. In your case, you have nested JSON, so you need to use GetRecordProperties.
Here's the modified queries
SELECT
StageElement.PropertyValue.dvcid as dvcid
INTO [Guardardb]
FROM [Pc-Sdm230] AS evento
CROSS APPLY GetRecordProperties(evento.valores) AS StageElement
Let me know if it works for you.
Thanks,
JS
answered Dec 27 '18 at 22:23


Jean-Sébastien
48717
48717
I'm embarassed for such a basic mistake. I corrected the JSON data replacing it for an array and the query worked fine. Thank you for the answer.
– dsd
Dec 28 '18 at 9:33
add a comment |
I'm embarassed for such a basic mistake. I corrected the JSON data replacing it for an array and the query worked fine. Thank you for the answer.
– dsd
Dec 28 '18 at 9:33
I'm embarassed for such a basic mistake. I corrected the JSON data replacing it for an array and the query worked fine. Thank you for the answer.
– dsd
Dec 28 '18 at 9:33
I'm embarassed for such a basic mistake. I corrected the JSON data replacing it for an array and the query worked fine. Thank you for the answer.
– dsd
Dec 28 '18 at 9:33
add a comment |
dsd is a new contributor. Be nice, and check out our Code of Conduct.
dsd is a new contributor. Be nice, and check out our Code of Conduct.
dsd is a new contributor. Be nice, and check out our Code of Conduct.
dsd is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53948131%2fazure-stream-analytics-job-using-arrays%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
hy 8hYtisIYTreHfE,JsF5m8q4iJ0cGujCCf5,GQypV,u3W4YBl,IPVhd XI mww5NlII 2 WoHxTCmTCclrkkrM,4KeHM,wTj7J