环境
- EMQX 版本:5.8.0
- 操作系统版本:Windows11
重现此问题的步骤
- 在规则引擎中添加SQL:
SELECT
jq('
. as $top |
select($top.params.ip | test("^(192\\.168\\.10\\.179)$")) |
.params as $second |
.params.device[].children[] |
select(.fc == "MX"
and (.nodeName | test("celGGIO1\\.AnIn(0?[1-9]|1[0-9]|2[0-4])\\.mag\\.f")) |
{
measure: (if .value | tonumber <= 1.75 then "low" elif .value | tonumber >= 2.4 then "high" end),
ld_name: (.nodeName | split("/")[0]),
node_name: .nodeName,
type,
fc,
value
}
', payload) as node_list
FROM "t/#"
- 启用调试,输入测试内容:
{
"id": 1808766991990378500,
"time": 1725588552140,
"params": {
"code": "a9d70cae0827a6c0",
"ip": "192.168.10.179",
"port": 102,
"device": [
{
"ldName": "BTSE",
"children": [
{
"nodeName": "BTSE/celGGIO1.AnIn1.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.198"
},
{
"nodeName": "BTSE/celGGIO1.AnIn2.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.196"
},
{
"nodeName": "BTSE/celGGIO1.AnIn3.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.220"
},
{
"nodeName": "BTSE/celGGIO1.AnIn4.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.192"
},
{
"nodeName": "BTSE/celGGIO1.AnIn5.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.206"
},
{
"nodeName": "BTSE/celGGIO1.AnIn6.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.205"
},
{
"nodeName": "BTSE/celGGIO1.AnIn7.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.223"
},
{
"nodeName": "BTSE/celGGIO1.AnIn8.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.218"
},
{
"nodeName": "BTSE/celGGIO1.AnIn9.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.193"
},
{
"nodeName": "BTSE/celGGIO1.AnIn10.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.210"
},
{
"nodeName": "BTSE/celGGIO1.AnIn11.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.256"
},
{
"nodeName": "BTSE/celGGIO1.AnIn12.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.228"
},
{
"nodeName": "BTSE/celGGIO1.AnIn13.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.204"
},
{
"nodeName": "BTSE/celGGIO1.AnIn14.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.239"
},
{
"nodeName": "BTSE/celGGIO1.AnIn15.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.202"
},
{
"nodeName": "BTSE/celGGIO1.AnIn16.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.274"
},
{
"nodeName": "BTSE/celGGIO1.AnIn17.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.200"
},
{
"nodeName": "BTSE/celGGIO1.AnIn18.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.224"
},
{
"nodeName": "BTSE/celGGIO1.AnIn19.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.203"
},
{
"nodeName": "BTSE/celGGIO1.AnIn20.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.229"
},
{
"nodeName": "BTSE/celGGIO1.AnIn21.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.193"
},
{
"nodeName": "BTSE/celGGIO1.AnIn22.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.198"
},
{
"nodeName": "BTSE/celGGIO1.AnIn23.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.214"
},
{
"nodeName": "BTSE/celGGIO1.AnIn24.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "2.198"
},
{
"nodeName": "BTSE/celGGIO1.AnIn25.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.365"
},
{
"nodeName": "BTSE/celGGIO1.AnIn26.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.360"
},
{
"nodeName": "BTSE/celGGIO1.AnIn27.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.342"
},
{
"nodeName": "BTSE/celGGIO1.AnIn28.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.378"
},
{
"nodeName": "BTSE/celGGIO1.AnIn29.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.356"
},
{
"nodeName": "BTSE/celGGIO1.AnIn30.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.318"
},
{
"nodeName": "BTSE/celGGIO1.AnIn31.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.352"
},
{
"nodeName": "BTSE/celGGIO1.AnIn32.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.367"
},
{
"nodeName": "BTSE/celGGIO1.AnIn33.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.373"
},
{
"nodeName": "BTSE/celGGIO1.AnIn34.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.358"
},
{
"nodeName": "BTSE/celGGIO1.AnIn35.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.389"
},
{
"nodeName": "BTSE/celGGIO1.AnIn36.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.381"
},
{
"nodeName": "BTSE/celGGIO1.AnIn37.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.332"
},
{
"nodeName": "BTSE/celGGIO1.AnIn38.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.366"
},
{
"nodeName": "BTSE/celGGIO1.AnIn39.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.373"
},
{
"nodeName": "BTSE/celGGIO1.AnIn40.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.371"
},
{
"nodeName": "BTSE/celGGIO1.AnIn41.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.368"
},
{
"nodeName": "BTSE/celGGIO1.AnIn42.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.396"
},
{
"nodeName": "BTSE/celGGIO1.AnIn43.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.372"
},
{
"nodeName": "BTSE/celGGIO1.AnIn44.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.350"
},
{
"nodeName": "BTSE/celGGIO1.AnIn45.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.445"
},
{
"nodeName": "BTSE/celGGIO1.AnIn46.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.354"
},
{
"nodeName": "BTSE/celGGIO1.AnIn47.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.387"
},
{
"nodeName": "BTSE/celGGIO1.AnIn48.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0.367"
}
]
},
{
"ldName": "BTSE2",
"children": [
{
"nodeName": "BTSE2/celGGIO1.AnIn1.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn2.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn3.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn4.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn5.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn6.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn7.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn8.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn9.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn10.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn11.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn12.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn13.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn14.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn15.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn16.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn17.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn18.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn19.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn20.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn21.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn22.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn23.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn24.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn25.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn26.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn27.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn28.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn29.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn30.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn31.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn32.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn33.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn34.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn35.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn36.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn37.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn38.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn39.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn40.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn41.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn42.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn43.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn44.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn45.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn46.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn47.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
},
{
"nodeName": "BTSE2/celGGIO1.AnIn48.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
]
}
]
}
}
- 保存,点击运行测试
预期行为
正确输出measure字段判断出来的结果,即
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn1.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn2.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn3.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn4.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn5.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn6.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn7.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn8.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn9.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn10.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn11.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn12.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn13.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn14.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn15.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn16.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn17.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn18.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn19.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn20.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn21.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn22.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn23.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
{
"measure": "low",
"ld_name": "BTSE2",
"node_name": "BTSE2/celGGIO1.AnIn24.mag.f",
"type": "MMS_FLOAT",
"fc": "MX",
"value": "0"
}
在jq的在线环境可以正常解析
实际行为
点击运行测试后报400 BAD_REQUEST: {“select_and_transform_error”:“jq_exception”}
日志:
2024-09-11 17:39:12 2024-09-11T17:39:12.415123+08:00 [warning] tag: RULE_SQL_EXEC, clientid: c_emqx, msg: SELECT_clause_exception, reason: {throw,{jq_exception,{jq_err_compile,<<“jq: error: syntax error, unexpected end (Unix shell quoting issues?) at , line 14:\n measure: (if .value | tonumber <= 1.75 then "low" elif .value | tonumber >= 2.4 then "high" end), jq: error: Possibly unterminated ‘if’ statement at , line 14:\n”…>>}},[{emqx_rule_funcs,jq,3,[{file,“emqx_rule_funcs.erl”},{line,925}]},{emqx_rule_runtime,do_apply_func,4,[{file,“emqx_rule_runtime.erl”},{line,697}]},{emqx_rule_runtime,select_and_transform,3,[{file,“emqx_rule_runtime.erl”},{line,273}]},{emqx_rule_runtime,evaluate_select,3,[{file,“emqx_rule_runtime.erl”},{line,227}]},{emqx_rule_runtime,do_apply_rule,3,[{file,“emqx_rule_runtime.erl”},{line,214}]},{emqx_rule_runtime,apply_rule,3,[{file,“emqx_rule_runtime.erl”},{line,87}]},{emqx_rule_sqltester,test_rule,4,[{file,“emqx_rule_sqltester.erl”},{line,163}]},{emqx_rule_engine_api,‘/rule_test’,2,[{file,“emqx_rule_engine_api.erl”},{line,420}]},{minirest_handler,apply_callback,3,[{file,“minirest_handler.erl”},{line,158}]},{minirest_handler,handle,2,[{file,“minirest_handler.erl”},{line,56}]},{minirest_handler,init,2,[{file,“minirest_handler.erl”},{line,27}]},{cowboy_handler,execute,2,[{file,“cowboy_handler.erl”},{line,41}]},{cowboy_stream_h,execute,3,[{file,“cowboy_stream_h.erl”},{line,318}]},{cowboy_stream_h,request_process,3,[{file,“cowboy_stream_h.erl”},{line,302}]},{proc_lib,init_p_do_apply,3,[{file,“proc_lib.erl”},{line,241}]}]}