如何使用JavaScript UDF将Azure Stream Analytics中的“类似于字典"的结构转换为多维数组? [英] How to convert a 'dictionary-like' structure in Azure Stream Analytics to a multi dimensional array with a javascript UDF?
问题描述
使用Azure Stream Analytics的 CollectTop
聚合函数后,我得到了一个类似于json的结构,该结构似乎像是Dictionary of Dictionary.我需要将其转换为多维数组,然后传递给AzureML UDF.
After using the CollectTop
aggregation function of Azure Stream Analytics, I get back a json-like structure that seems to be like a Dictionary of Dictionaries.
I need to convert this one to a multi-dimensional array which I want to pass to an AzureML UDF.
我的问题主要是关于如何在javascript-UDF中解释这种结构,因为我对Java完全陌生.
My question is mostly on how I can interpret this structure in a javascript-UDF, as I'm totally new to Javascript.
这是一个示例记录(使用 CollectTop
),但是挑战在于我的JavaScript UDF应该是什么样子?
This is a sample record (using CollectTop
), but the challenge is how my javascript UDF should look like?
[
{"rank":1,"value":{"engineid":"engine001","tmp":-0.0019,"hum":-0.0002,"eventtime":4}},
{"rank":2,"value":{"engineid":"engine001","tmp":-0.0026,"hum":-0.0002,"eventtime":2}},
{"rank":3,"value":{"engineid":"engine001","tmp":0.0003,"hum":-0.0002,"eventtime":1}}
]
根据上面的数据结构,我很想生成以下数组.(以tmp和hum字段表示)
From the above data structure, I'd love to get the following array generated. (taking tmp & hum fields)
[[-0.0019, -0.0002], [-0.0026, -0.0002], [0.0003, -0.0002]]
欢迎任何帮助或见解.
这个问题与另外两个问题有关:
This question is related to two other questions:
- CollectTop返回的行比我在Azure流分析中期望的要多
- 最诚挚的问候
推荐答案
var input = [ {"rank":1,"value":{"engineid":"engine001","tmp":-0.0019,"hum":-0.0002,"eventtime":4}}, {"rank":2,"value":{"engineid":"engine001","tmp":-0.0026,"hum":-0.0002,"eventtime":2}}, {"rank":3,"value":{"engineid":"engine001","tmp":0.0003,"hum":-0.0002,"eventtime":1}} ]; console.log(getOutput(input)); function getOutput(input){ var output = []; for(var x in input){ var array = []; array.push(input[x].value.tmp); array.push(input[x].value.hum); output.push(array); } return output; }
这是您需要的吗?
这篇关于如何使用JavaScript UDF将Azure Stream Analytics中的“类似于字典"的结构转换为多维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!