我需要以下方面的帮助。 我有这样的数据
[{
"id": "0001",
"type": "donut",
"name": "Cake",
"topping":
[
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
}]
我想将其转换为以下内容
参数将是动态的或多个,而不仅仅是 Chocolate 和 Maple )
我想创建一个流分析查询来处理这些数据并将其存储到目标表中,目标表中已经有这些列,如 Id、Name、Type、Chocolate、Maple...... 请帮助我。
最佳答案
您可以通过udf获得帮助在 ASA 中。
UDF 代码:
function main(arg) {
var array = arg.topping;
var map = {};
map["id"] = arg.id;
map["type"] = arg.type;
map["name"] = arg.name;
for(var i=0;i<array.length;i++){
var key=array[i].type;
map[key] = array[i].id;
}
return map;
}
SQL:
WITH
c AS
(
SELECT
udf.processArray(jsoninput) as result
from jsoninput
)
select c.result
INTO
jaycosmos
from c
示例数据:
[{
"id": "0001",
"type": "donut",
"name": "Cake",
"topping":
[
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
},
{
"id": "0002",
"type": "donut2",
"name": "Cake2",
"topping":
[
{ "id": "5005", "type": "Chocolate" }
]
}
]
输出:
关于azure - 将 JSON 数据行转换为列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53075735/