fix: cannot access columns exported by FOREACH in DO clause

This commit is contained in:
Shawn 2023-05-06 09:09:20 +08:00
parent 39b00ab602
commit 154fe441de
8 changed files with 31 additions and 14 deletions

View File

@ -1,6 +1,6 @@
{application, emqx_rule_engine,
[{description, "EMQX Rule Engine"},
{vsn, "4.4.18"}, % strict semver, bump manually!
{vsn, "4.4.19"}, % strict semver, bump manually!
{modules, []},
{registered, [emqx_rule_engine_sup, emqx_rule_registry, emqx_rule_engine_jwt_sup]},
{applications, [kernel,stdlib,rulesql,getopt,jose]},

View File

@ -1,9 +1,13 @@
%% -*- mode: erlang -*-
%% Unless you know what you are doing, DO NOT edit manually!!
{VSN,
[{"4.4.17",[{load_module,emqx_rule_utils,brutal_purge,soft_purge,[]}]},
[{"4.4.18",[{load_module,emqx_rule_runtime,brutal_purge,soft_purge,[]}]},
{"4.4.17",
[{load_module,emqx_rule_runtime,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_utils,brutal_purge,soft_purge,[]}]},
{"4.4.16",
[{load_module,emqx_rule_utils,brutal_purge,soft_purge,[]},
[{load_module,emqx_rule_runtime,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_utils,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_events,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_engine_app,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]}]},
@ -254,9 +258,13 @@
{load_module,emqx_rule_engine,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_runtime,brutal_purge,soft_purge,[]}]},
{<<".*">>,[]}],
[{"4.4.17",[{load_module,emqx_rule_utils,brutal_purge,soft_purge,[]}]},
[{"4.4.18",[{load_module,emqx_rule_runtime,brutal_purge,soft_purge,[]}]},
{"4.4.17",
[{load_module,emqx_rule_runtime,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_utils,brutal_purge,soft_purge,[]}]},
{"4.4.16",
[{load_module,emqx_rule_utils,brutal_purge,soft_purge,[]},
[{load_module,emqx_rule_runtime,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_utils,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_events,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_engine_app,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]}]},

View File

@ -103,12 +103,12 @@ do_apply_rule(#rule{id = RuleId,
case ?RAISE(match_conditions(Conditions, ColumnsAndSelected),
{match_conditions_error, {_EXCLASS_,_EXCPTION_,_ST_}}) of
true ->
Collection2 = filter_collection(Input, InCase, DoEach, Collection),
Collection2 = filter_collection(ColumnsAndSelected, InCase, DoEach, Collection),
case Collection2 of
[] -> emqx_rule_metrics:inc_rules_no_result(RuleId);
_ -> emqx_rule_metrics:inc_rules_passed(RuleId)
end,
{ok, [take_actions(Actions, Coll, Input, OnFailed) || Coll <- Collection2]};
{ok, [take_actions(Actions, Coll, ColumnsAndSelected, OnFailed) || Coll <- Collection2]};
false ->
ok = emqx_rule_metrics:inc_rules_no_result(RuleId),
{error, nomatch}

View File

@ -987,16 +987,19 @@ t_sqlparse_foreach_7(_Config) ->
#{<<"payload">> => Payload,
<<"topic">> => <<"t/a">>}})).
-define(COLL, #{<<"info">> := [<<"haha">>, #{<<"name">> := <<"cmd1">>, <<"cmd">> := <<"1">>}]}).
t_sqlparse_foreach_8(_Config) ->
%% Verify foreach-do-incase and cascaded AS
Sql = "foreach json_decode(payload) as p, p.sensors as s, s.collection as c, c.info as info "
"do info.cmd as msg_type, info.name as name "
"do info.cmd as msg_type, info.name as name, s, c "
"incase is_map(info) "
"from \"t/#\" "
"where s.page = '2' ",
Payload = <<"{\"sensors\": {\"page\": 2, \"collection\": "
"{\"info\":[\"haha\", {\"name\":\"cmd1\", \"cmd\":\"1\"}]} } }">>,
?assertMatch({ok,[#{<<"name">> := <<"cmd1">>, <<"msg_type">> := <<"1">>}]},
?assertMatch({ok,[#{<<"name">> := <<"cmd1">>, <<"msg_type">> := <<"1">>,
<<"s">> := #{<<"page">> := 2, <<"collection">> := ?COLL},
<<"c">> := ?COLL}]},
emqx_rule_sqltester:test(
#{<<"rawsql">> => Sql,
<<"ctx">> =>

View File

@ -1,6 +1,6 @@
{application, emqx_dashboard,
[{description, "EMQX Web Dashboard"},
{vsn, "4.4.17"}, % strict semver, bump manually!
{vsn, "4.4.18"}, % strict semver, bump manually!
{modules, []},
{registered, [emqx_dashboard_sup]},
{applications, [kernel,stdlib,mnesia,minirest]},

View File

@ -48,7 +48,7 @@
, {gproc, {git, "https://github.com/uwiger/gproc", {tag, "0.9.0"}}}
, {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}}
, {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.9.1"}}}
, {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.8.9"}}}
, {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.8.10"}}}
, {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.8.1.11"}}}
, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "3.0.1"}}}
, {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.3.6"}}}

View File

@ -6,7 +6,7 @@
%% the emqx `release' version, which in turn is comprised of several
%% apps, one of which is this. See `emqx_release.hrl' for more
%% info.
{vsn, "4.4.18"}, % strict semver, bump manually!
{vsn, "4.4.19"}, % strict semver, bump manually!
{modules, []},
{registered, []},
{applications, [ kernel

View File

@ -1,7 +1,10 @@
%% -*- mode: erlang -*-
%% Unless you know what you are doing, DO NOT edit manually!!
{VSN,
[{"4.4.17",
[{"4.4.18",
[{load_module,emqx_relup,brutal_purge,soft_purge,[]},
{load_module,emqx_app,brutal_purge,soft_purge,[]}]},
{"4.4.17",
[{load_module,emqx_relup,brutal_purge,soft_purge,[]},
{load_module,emqx_app,brutal_purge,soft_purge,[]},
{load_module,emqx_plugins,brutal_purge,soft_purge,[]}]},
@ -537,7 +540,10 @@
{apply,{application,set_env,
[gen_rpc,insecure_auth_fallback_allowed,true]}}]},
{<<".*">>,[]}],
[{"4.4.17",
[{"4.4.18",
[{load_module,emqx_relup,brutal_purge,soft_purge,[]},
{load_module,emqx_app,brutal_purge,soft_purge,[]}]},
{"4.4.17",
[{load_module,emqx_relup,brutal_purge,soft_purge,[]},
{load_module,emqx_app,brutal_purge,soft_purge,[]},
{load_module,emqx_plugins,brutal_purge,soft_purge,[]}]},