Skip to content

Commit

Permalink
Merge pull request #10318 from kjellwinblad/kjell/feat/rule_engine_fr…
Browse files Browse the repository at this point in the history
…om_clause_support_both_string_types

feat(rule engine sql): enable both ' and " strings in FROM clause
  • Loading branch information
kjellwinblad committed Apr 6, 2023
2 parents 0a73866 + 0e66eb5 commit 1938882
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
33 changes: 33 additions & 0 deletions apps/emqx_rule_engine/test/emqx_rule_engine_SUITE.erl
Expand Up @@ -2634,6 +2634,39 @@ t_sqlparse_invalid_json(_Config) ->
}
)
).

t_sqlparse_both_string_types_in_from(_Config) ->
%% Here is an SQL select statement with both string types in the FROM clause
SqlSelect =
"select clientid, topic as tp "
"from 't/tt', \"$events/client_connected\" ",
?assertMatch(
{ok, #{<<"clientid">> := <<"abc">>, <<"tp">> := <<"t/tt">>}},
emqx_rule_sqltester:test(
#{
sql => SqlSelect,
context => #{clientid => <<"abc">>, topic => <<"t/tt">>}
}
)
),
%% Here is an SQL foreach statement with both string types in the FROM clause
SqlForeach =
"foreach payload.sensors "
"from 't/#', \"$events/client_connected\" ",
?assertMatch(
{ok, []},
emqx_rule_sqltester:test(
#{
sql => SqlForeach,
context =>
#{
payload => <<"{\"sensors\": 1}">>,
topic => <<"t/a">>
}
}
)
).

%%------------------------------------------------------------------------------
%% Test cases for telemetry functions
%%------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions changes/ce/feat-10318.en.md
@@ -0,0 +1 @@
Now, the rule engine language's FROM clause supports both strings enclosed in double quotes (") and single quotes (').
1 change: 1 addition & 0 deletions changes/ce/feat-10318.zh.md
@@ -0,0 +1 @@
现在,规则引擎语言的 FROM 子句支持使用双引号(")和单引号(')括起来的字符串。
2 changes: 1 addition & 1 deletion mix.exs
Expand Up @@ -65,7 +65,7 @@ defmodule EMQXUmbrella.MixProject do
# maybe forbid to fetch quicer
{:emqtt,
github: "emqx/emqtt", tag: "1.8.5", override: true, system_env: maybe_no_quic_env()},
{:rulesql, github: "emqx/rulesql", tag: "0.1.4"},
{:rulesql, github: "emqx/rulesql", tag: "0.1.5"},
{:observer_cli, "1.7.1"},
{:system_monitor, github: "ieQu1/system_monitor", tag: "3.0.3"},
{:telemetry, "1.1.0"},
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Expand Up @@ -70,7 +70,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.8.5"}}}
, {rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.4"}}}
, {rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.5"}}}
, {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"}}}
, {getopt, "1.0.2"}
Expand Down

0 comments on commit 1938882

Please sign in to comment.