Merge pull request #10318 from kjellwinblad/kjell/feat/rule_engine_from_clause_support_both_string_types

feat(rule engine sql): enable both ' and " strings in FROM clause
This commit is contained in:
Kjell Winblad 2023-04-06 09:19:44 +02:00 committed by GitHub
commit 1938882f16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 2 deletions

View File

@ -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 %% Test cases for telemetry functions
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------

View File

@ -0,0 +1 @@
Now, the rule engine language's FROM clause supports both strings enclosed in double quotes (") and single quotes (').

View File

@ -0,0 +1 @@
现在,规则引擎语言的 FROM 子句支持使用双引号(")和单引号(')括起来的字符串。

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.5", override: true, system_env: maybe_no_quic_env()}, 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"}, {: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.5"}}} , {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 , {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"}