Explorar el Código

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
Kjell Winblad hace 2 años
padre
commit
1938882f16

+ 33 - 0
apps/emqx_rule_engine/test/emqx_rule_engine_SUITE.erl

@@ -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
 %%------------------------------------------------------------------------------

+ 1 - 0
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 - 0
changes/ce/feat-10318.zh.md

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

+ 1 - 1
mix.exs

@@ -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"},

+ 1 - 1
rebar.config

@@ -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"}