Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rule engine sql): enable both ' and " strings in FROM clause #10318

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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