fix: cannot access columns exported by FOREACH in DO clause
This commit is contained in:
parent
39b00ab602
commit
154fe441de
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_rule_engine,
|
{application, emqx_rule_engine,
|
||||||
[{description, "EMQX Rule Engine"},
|
[{description, "EMQX Rule Engine"},
|
||||||
{vsn, "4.4.18"}, % strict semver, bump manually!
|
{vsn, "4.4.19"}, % strict semver, bump manually!
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, [emqx_rule_engine_sup, emqx_rule_registry, emqx_rule_engine_jwt_sup]},
|
{registered, [emqx_rule_engine_sup, emqx_rule_registry, emqx_rule_engine_jwt_sup]},
|
||||||
{applications, [kernel,stdlib,rulesql,getopt,jose]},
|
{applications, [kernel,stdlib,rulesql,getopt,jose]},
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
%% -*- mode: erlang -*-
|
%% -*- mode: erlang -*-
|
||||||
%% Unless you know what you are doing, DO NOT edit manually!!
|
%% Unless you know what you are doing, DO NOT edit manually!!
|
||||||
{VSN,
|
{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",
|
{"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_events,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_rule_engine_app,brutal_purge,soft_purge,[]},
|
{load_module,emqx_rule_engine_app,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_rule_registry,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_engine,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_rule_runtime,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",
|
{"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_events,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_rule_engine_app,brutal_purge,soft_purge,[]},
|
{load_module,emqx_rule_engine_app,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]}]},
|
{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]}]},
|
||||||
|
|
|
@ -103,12 +103,12 @@ do_apply_rule(#rule{id = RuleId,
|
||||||
case ?RAISE(match_conditions(Conditions, ColumnsAndSelected),
|
case ?RAISE(match_conditions(Conditions, ColumnsAndSelected),
|
||||||
{match_conditions_error, {_EXCLASS_,_EXCPTION_,_ST_}}) of
|
{match_conditions_error, {_EXCLASS_,_EXCPTION_,_ST_}}) of
|
||||||
true ->
|
true ->
|
||||||
Collection2 = filter_collection(Input, InCase, DoEach, Collection),
|
Collection2 = filter_collection(ColumnsAndSelected, InCase, DoEach, Collection),
|
||||||
case Collection2 of
|
case Collection2 of
|
||||||
[] -> emqx_rule_metrics:inc_rules_no_result(RuleId);
|
[] -> emqx_rule_metrics:inc_rules_no_result(RuleId);
|
||||||
_ -> emqx_rule_metrics:inc_rules_passed(RuleId)
|
_ -> emqx_rule_metrics:inc_rules_passed(RuleId)
|
||||||
end,
|
end,
|
||||||
{ok, [take_actions(Actions, Coll, Input, OnFailed) || Coll <- Collection2]};
|
{ok, [take_actions(Actions, Coll, ColumnsAndSelected, OnFailed) || Coll <- Collection2]};
|
||||||
false ->
|
false ->
|
||||||
ok = emqx_rule_metrics:inc_rules_no_result(RuleId),
|
ok = emqx_rule_metrics:inc_rules_no_result(RuleId),
|
||||||
{error, nomatch}
|
{error, nomatch}
|
||||||
|
|
|
@ -987,16 +987,19 @@ t_sqlparse_foreach_7(_Config) ->
|
||||||
#{<<"payload">> => Payload,
|
#{<<"payload">> => Payload,
|
||||||
<<"topic">> => <<"t/a">>}})).
|
<<"topic">> => <<"t/a">>}})).
|
||||||
|
|
||||||
|
-define(COLL, #{<<"info">> := [<<"haha">>, #{<<"name">> := <<"cmd1">>, <<"cmd">> := <<"1">>}]}).
|
||||||
t_sqlparse_foreach_8(_Config) ->
|
t_sqlparse_foreach_8(_Config) ->
|
||||||
%% Verify foreach-do-incase and cascaded AS
|
%% 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 "
|
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) "
|
"incase is_map(info) "
|
||||||
"from \"t/#\" "
|
"from \"t/#\" "
|
||||||
"where s.page = '2' ",
|
"where s.page = '2' ",
|
||||||
Payload = <<"{\"sensors\": {\"page\": 2, \"collection\": "
|
Payload = <<"{\"sensors\": {\"page\": 2, \"collection\": "
|
||||||
"{\"info\":[\"haha\", {\"name\":\"cmd1\", \"cmd\":\"1\"}]} } }">>,
|
"{\"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(
|
emqx_rule_sqltester:test(
|
||||||
#{<<"rawsql">> => Sql,
|
#{<<"rawsql">> => Sql,
|
||||||
<<"ctx">> =>
|
<<"ctx">> =>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_dashboard,
|
{application, emqx_dashboard,
|
||||||
[{description, "EMQX Web Dashboard"},
|
[{description, "EMQX Web Dashboard"},
|
||||||
{vsn, "4.4.17"}, % strict semver, bump manually!
|
{vsn, "4.4.18"}, % strict semver, bump manually!
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, [emqx_dashboard_sup]},
|
{registered, [emqx_dashboard_sup]},
|
||||||
{applications, [kernel,stdlib,mnesia,minirest]},
|
{applications, [kernel,stdlib,mnesia,minirest]},
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
, {gproc, {git, "https://github.com/uwiger/gproc", {tag, "0.9.0"}}}
|
, {gproc, {git, "https://github.com/uwiger/gproc", {tag, "0.9.0"}}}
|
||||||
, {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}}
|
, {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}}
|
||||||
, {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.9.1"}}}
|
, {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"}}}
|
, {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"}}}
|
, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "3.0.1"}}}
|
||||||
, {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.3.6"}}}
|
, {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.3.6"}}}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
%% the emqx `release' version, which in turn is comprised of several
|
%% the emqx `release' version, which in turn is comprised of several
|
||||||
%% apps, one of which is this. See `emqx_release.hrl' for more
|
%% apps, one of which is this. See `emqx_release.hrl' for more
|
||||||
%% info.
|
%% info.
|
||||||
{vsn, "4.4.18"}, % strict semver, bump manually!
|
{vsn, "4.4.19"}, % strict semver, bump manually!
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications, [ kernel
|
{applications, [ kernel
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
%% -*- mode: erlang -*-
|
%% -*- mode: erlang -*-
|
||||||
%% Unless you know what you are doing, DO NOT edit manually!!
|
%% Unless you know what you are doing, DO NOT edit manually!!
|
||||||
{VSN,
|
{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_relup,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_app,brutal_purge,soft_purge,[]},
|
{load_module,emqx_app,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_plugins,brutal_purge,soft_purge,[]}]},
|
{load_module,emqx_plugins,brutal_purge,soft_purge,[]}]},
|
||||||
|
@ -537,7 +540,10 @@
|
||||||
{apply,{application,set_env,
|
{apply,{application,set_env,
|
||||||
[gen_rpc,insecure_auth_fallback_allowed,true]}}]},
|
[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_relup,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_app,brutal_purge,soft_purge,[]},
|
{load_module,emqx_app,brutal_purge,soft_purge,[]},
|
||||||
{load_module,emqx_plugins,brutal_purge,soft_purge,[]}]},
|
{load_module,emqx_plugins,brutal_purge,soft_purge,[]}]},
|
||||||
|
|
Loading…
Reference in New Issue