请教大佬,payload包含了嵌套数组,看说明文档没有提到嵌套支持,不知道能否支持,有两个需求:
1.重命名嵌套数组的各元素名称,现在是通过字符串替换,json编码解码,虽然效果达到了,但总感觉性能不佳
2.需要把数组中dq=192的数据过滤出来,其他数据不要,这个我还不知道怎么弄。
以下为需要改进的SQL
SELECT
payload.sn AS application_id,
username AS customer_id,
publish_received_at AS upload_time,
json_decode(
replace(
replace(
replace(
replace(
json_encode(payload.devs),
‘“d”’,‘“data”’),
‘“dev”’,‘“device_name”’),
‘“m”’,‘“param_name”’),
‘“v”’,‘“value”’)
) AS dataset
FROM “test_topic”
以下为测试payload
{
“devs”: [{
“d”: [{
“m”: “Temp”,
“v”: 26.5,
“ts”: 1555487077,
“dq”: 0
},{
“m”: “Power”,
“v”: 12.6,
“ts”: 1555487077,
“dq”: 192
}],
“dev”: “chiller111”
},{
“d”: [{
“m”: “Hz”,
“v”: 35,
“ts”: 1555487077,
“dq”: 192
}],
“dev”: “inverter222”
}],
“pKey”: “test”,
“sn”: “DD4F63F2B7CE4CE”,
“ts”: 1555487077,
“ver”: “1.1.0”
}