我尝试将平面JSON数据从事件中心转换为DocumentDB。目标结构应如下所示:
{
"id" : 1
"field_1" : "value_1",
"details" : {
"detail_field_1":"abc",
"detail_field_2":"def"
}
}
从源代码创建:
{
"id":1,
"field_1" : "value_1",
"detail_field_1":"abc",
"detail_field_2":"def"
}
我查看了Azure Stream Analytics的文档,但没有明确说明如何创建正确的查询。
谁可以帮助我?
答案 0 :(得分:2)
您可以利用the new JavaScript UDF feature编写嵌套的JSON对象进行输出。
注册用户定义的函数“UDF.getDetails()”,如下所示:
function main(obj) {
//get details object from input payload
var details_obj = {};
details_obj.detail_field_1 = obj.detail_field_1;
details_obj.detail_field_2 = obj.detail_field_2;
return JSON.stringify(details_obj);
}
然后在查询中调用UDF以获取嵌套JSON对象的字符串。
SELECT
id,
field_1,
UDF.getDetails(input) As details
INTO output
FROM input