Merge pull request #11026 from kjellwinblad/kjell/fix/rule_engine/div_mod_strange/EMQX-10216

fix: rule engine different behavior for div and mod
This commit is contained in:
Kjell Winblad 2023-06-17 07:20:37 +02:00 committed by GitHub
commit 59ed8798c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 3 deletions

View File

@ -70,7 +70,8 @@
Op =:= '-' orelse Op =:= '-' orelse
Op =:= '*' orelse Op =:= '*' orelse
Op =:= '/' orelse Op =:= '/' orelse
Op =:= 'div') Op =:= 'div' orelse
Op =:= 'mod')
). ).
%% Compare operators %% Compare operators

View File

@ -66,6 +66,7 @@ groups() ->
t_sqlselect_with_3rd_party_impl2, t_sqlselect_with_3rd_party_impl2,
t_sqlselect_with_3rd_party_funcs_unknown, t_sqlselect_with_3rd_party_funcs_unknown,
t_sqlselect_001, t_sqlselect_001,
t_sqlselect_002,
t_sqlselect_inject_props, t_sqlselect_inject_props,
t_sqlselect_01, t_sqlselect_01,
t_sqlselect_02, t_sqlselect_02,
@ -1089,6 +1090,36 @@ t_sqlselect_001(_Config) ->
) )
). ).
t_sqlselect_002(_Config) ->
%% Verify that the div and mod can be used both as infix operations and as
%% function calls
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 \"t/#\" "
"",
?assertMatch(
{ok, #{
<<"mod1">> := 0,
<<"mod2">> := 1,
<<"div1">> := 2,
<<"div2">> := 3
}},
emqx_rule_sqltester:test(
#{
sql => Sql,
context =>
#{
payload => #{<<"what">> => 4},
topic => <<"t/a">>
}
}
)
).
t_sqlselect_inject_props(_Config) -> t_sqlselect_inject_props(_Config) ->
SQL = SQL =
"SELECT json_decode(payload) as p, payload, " "SELECT json_decode(payload) as p, payload, "

View File

@ -0,0 +1 @@
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.

View File

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

View File

@ -70,7 +70,7 @@
, {replayq, {git, "https://github.com/emqx/replayq.git", {tag, "0.3.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"}}} , {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}}
, {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.8.6"}}} , {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.8.6"}}}
, {rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.6"}}} , {rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.7"}}}
, {observer_cli, "1.7.1"} % NOTE: depends on recon 2.5.x , {observer_cli, "1.7.1"} % NOTE: depends on recon 2.5.x
, {system_monitor, {git, "https://github.com/ieQu1/system_monitor", {tag, "3.0.3"}}} , {system_monitor, {git, "https://github.com/ieQu1/system_monitor", {tag, "3.0.3"}}}
, {getopt, "1.0.2"} , {getopt, "1.0.2"}