fix(rule SQL): allow expressions as array items

Fixes:
https://github.com/emqx/emqx/issues/12465
https://emqx.atlassian.net/browse/EMQX-11953
This commit is contained in:
Kjell Winblad 2024-03-06 11:47:33 +01:00
parent f1e9da9048
commit c206ee37e0
3 changed files with 27 additions and 2 deletions

View File

@ -102,6 +102,7 @@ groups() ->
t_sqlparse_array_index_3,
t_sqlparse_array_index_4,
t_sqlparse_array_index_5,
t_sqlparse_array_with_expressions,
t_sqlparse_select_matadata_1,
t_sqlparse_array_range_1,
t_sqlparse_array_range_2,
@ -3040,6 +3041,30 @@ t_sqlparse_array_index_5(_Config) ->
)
).
t_sqlparse_array_with_expressions(_Config) ->
Sql =
"select "
" [21 + 21, abs(-abs(-2)), [1 + 1], 4] "
"from \"t/#\" ",
{ok, Res} =
emqx_rule_sqltester:test(
#{
sql => Sql,
context => #{
payload => <<"">>,
topic => <<"t/a">>
}
}
),
?assert(
lists:any(
fun({_K, V}) ->
V =:= [42, 2, [2], 4]
end,
maps:to_list(Res)
)
).
t_sqlparse_select_matadata_1(_Config) ->
%% array with json string payload:
Sql0 =

View File

@ -65,7 +65,7 @@ defmodule EMQXUmbrella.MixProject do
# maybe forbid to fetch quicer
{:emqtt,
github: "emqx/emqtt", tag: "1.10.1", override: true, system_env: maybe_no_quic_env()},
{:rulesql, github: "emqx/rulesql", tag: "0.1.7"},
{:rulesql, github: "emqx/rulesql", tag: "0.1.8"},
{:observer_cli, "1.7.1"},
{:system_monitor, github: "ieQu1/system_monitor", tag: "3.0.3"},
{:telemetry, "1.1.0"},

View File

@ -91,7 +91,7 @@
{replayq, {git, "https://github.com/emqx/replayq.git", {tag, "0.3.7"}}},
{pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}},
{emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.10.1"}}},
{rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.7"}}},
{rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.8"}}},
% NOTE: depends on recon 2.5.x
{observer_cli, "1.7.1"},
{system_monitor, {git, "https://github.com/ieQu1/system_monitor", {tag, "3.0.3"}}},