Merge pull request #11073 from kjellwinblad/kjell/fix/4.4/div_mod_diff_behavior/EMQX-10216
fix: rule engine different behavior for div and mod
This commit is contained in:
commit
4ee6244c93
|
@ -149,7 +149,8 @@
|
||||||
Op =:= '-' orelse
|
Op =:= '-' orelse
|
||||||
Op =:= '*' orelse
|
Op =:= '*' orelse
|
||||||
Op =:= '/' orelse
|
Op =:= '/' orelse
|
||||||
Op =:= 'div')).
|
Op =:= 'div' orelse
|
||||||
|
Op =:= 'mod')).
|
||||||
|
|
||||||
%% Compare operators
|
%% Compare operators
|
||||||
-define(is_comp(Op), (Op =:= '=' orelse
|
-define(is_comp(Op), (Op =:= '=' orelse
|
||||||
|
|
|
@ -57,6 +57,7 @@ groups() ->
|
||||||
, t_sqlselect_00
|
, t_sqlselect_00
|
||||||
, t_sqlselect_01
|
, t_sqlselect_01
|
||||||
, t_sqlselect_02
|
, t_sqlselect_02
|
||||||
|
, t_sqlselect_04
|
||||||
, t_sqlselect_1
|
, t_sqlselect_1
|
||||||
, t_sqlselect_2
|
, t_sqlselect_2
|
||||||
]},
|
]},
|
||||||
|
@ -423,6 +424,39 @@ t_sqlselect_03(_Config) ->
|
||||||
emqtt:stop(Client),
|
emqtt:stop(Client),
|
||||||
emqx_rule_registry:remove_rule(TopicRule1).
|
emqx_rule_registry:remove_rule(TopicRule1).
|
||||||
|
|
||||||
|
t_sqlselect_04(_Config) ->
|
||||||
|
%% Verify that div and mod works as expected
|
||||||
|
ok = emqx_rule_engine:load_providers(),
|
||||||
|
SQL = ""
|
||||||
|
"select 2 mod 2 as mod1,\n"
|
||||||
|
" mod(3, 2) as mod2,\n"
|
||||||
|
" 4 div 2 as div1,\n"
|
||||||
|
" div(7, 2) as div2\n"
|
||||||
|
"from \"t2\" "
|
||||||
|
"",
|
||||||
|
TopicRule1 = create_simple_repub_rule(
|
||||||
|
<<"t1">>,
|
||||||
|
SQL,
|
||||||
|
<<"{\"mod1\": ${mod1},\"mod2\": ${mod2},\"div1\": ${div1},\"div2\": ${div2}}">>
|
||||||
|
),
|
||||||
|
{ok, Client} = emqtt:start_link([{username, <<"emqx">>}]),
|
||||||
|
{ok, _} = emqtt:connect(Client),
|
||||||
|
{ok, _, _} = emqtt:subscribe(Client, <<"t1">>, 0),
|
||||||
|
emqtt:publish(Client, <<"t2">>, <<"">>, 0),
|
||||||
|
receive {publish, #{payload := Payload}} ->
|
||||||
|
?assertMatch(#{
|
||||||
|
<<"mod1">> := 0,
|
||||||
|
<<"mod2">> := 1,
|
||||||
|
<<"div1">> := 2,
|
||||||
|
<<"div2">> := 3
|
||||||
|
}, emqx_json:decode(Payload, [return_maps]))
|
||||||
|
after 1000 ->
|
||||||
|
ct:fail(wait_for_t1)
|
||||||
|
end,
|
||||||
|
emqtt:stop(Client),
|
||||||
|
emqx_rule_registry:remove_rule(TopicRule1).
|
||||||
|
|
||||||
|
|
||||||
t_sqlselect_1(_Config) ->
|
t_sqlselect_1(_Config) ->
|
||||||
ok = emqx_rule_engine:load_providers(),
|
ok = emqx_rule_engine:load_providers(),
|
||||||
TopicRule = create_simple_repub_rule(
|
TopicRule = create_simple_repub_rule(
|
||||||
|
|
|
@ -46,3 +46,5 @@
|
||||||
- Fixed an issue where the WebHook plugin failed to execute the `on_client_connack` hook [#10710](https://github.com/emqx/emqx/pull/10710).
|
- Fixed an issue where the WebHook plugin failed to execute the `on_client_connack` hook [#10710](https://github.com/emqx/emqx/pull/10710).
|
||||||
|
|
||||||
See https://github.com/emqx/emqx/issues/10628 for more details.
|
See https://github.com/emqx/emqx/issues/10628 for more details.
|
||||||
|
|
||||||
|
- Addressed an inconsistency in the usage of 'div' and 'mod' operations within the rule engine. Previously, the 'div' operation was only usable as an infix operation and 'mod' could only be applied through a function call. With this change, both 'div' and 'mod' can be used via function call syntax and infix syntax.
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
, {replayq, {git, "https://github.com/emqx/replayq", {tag, "0.3.5"}}}
|
, {replayq, {git, "https://github.com/emqx/replayq", {tag, "0.3.5"}}}
|
||||||
, {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {branch, "2.0.4"}}}
|
, {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {branch, "2.0.4"}}}
|
||||||
, {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.2.3.2"}}}
|
, {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.2.3.2"}}}
|
||||||
, {rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.5"}}}
|
, {rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.7"}}}
|
||||||
, {recon, {git, "https://github.com/ferd/recon", {tag, "2.5.1"}}}
|
, {recon, {git, "https://github.com/ferd/recon", {tag, "2.5.1"}}}
|
||||||
, {observer_cli, "1.6.1"} % NOTE: depends on recon 2.5.1
|
, {observer_cli, "1.6.1"} % NOTE: depends on recon 2.5.1
|
||||||
, {getopt, "1.0.1"}
|
, {getopt, "1.0.1"}
|
||||||
|
|
Loading…
Reference in New Issue