Skip to content

Commit

Permalink
Merge pull request #11166 from lafirest/feat/porti_uuid_el_v4
Browse files Browse the repository at this point in the history
feat(ruleengine): port random && uuid_v4 functions from v4
  • Loading branch information
lafirest committed Jun 30, 2023
2 parents c8d1bd3 + ae3ebfe commit 1ea92d4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/emqx_rule_engine/src/emqx_rule_engine.app.src
Expand Up @@ -5,7 +5,7 @@
{vsn, "5.0.20"},
{modules, []},
{registered, [emqx_rule_engine_sup, emqx_rule_engine]},
{applications, [kernel, stdlib, rulesql, getopt, emqx_ctl]},
{applications, [kernel, stdlib, rulesql, getopt, emqx_ctl, uuid]},
{mod, {emqx_rule_engine_app, []}},
{env, []},
{licenses, ["Apache-2.0"]},
Expand Down
22 changes: 22 additions & 0 deletions apps/emqx_rule_engine/src/emqx_rule_funcs.erl
Expand Up @@ -242,6 +242,13 @@
mongo_date/2
]).

%% Random Funcs
-export([
random/0,
uuid_v4/0,
uuid_v4_no_hyphen/0
]).

%% Proc Dict Func
-export([
proc_dict_get/1,
Expand Down Expand Up @@ -1021,6 +1028,18 @@ term_encode(Term) ->
term_decode(Data) when is_binary(Data) ->
erlang:binary_to_term(Data).

%%------------------------------------------------------------------------------
%% Random Funcs
%%------------------------------------------------------------------------------
random() ->
rand:uniform().

uuid_v4() ->
uuid_str(uuid:get_v4(), binary_standard).

uuid_v4_no_hyphen() ->
uuid_str(uuid:get_v4(), binary_nodash).

%%------------------------------------------------------------------------------
%% Dict Funcs
%%------------------------------------------------------------------------------
Expand Down Expand Up @@ -1186,3 +1205,6 @@ convert_timestamp(MillisecondsTimestamp) ->
Secs = MicroTimestamp div 1000_000 - MegaSecs * 1000_000,
MicroSecs = MicroTimestamp rem 1000_000,
{MegaSecs, Secs, MicroSecs}.

uuid_str(UUID, DisplyOpt) ->
uuid:uuid_to_string(UUID, DisplyOpt).
4 changes: 4 additions & 0 deletions changes/ce/feat-11166.en.md
@@ -0,0 +1,4 @@
Added 3 random SQL functions to the rule engine.
- random(): Generates a random number between 0 and 1 (0.0 =< X < 1.0).
- uuid_v4(): Generates a random UUID (version 4) string.
- uuid_v4_no_hyphen(): Generates a random UUID (version 4) string without hyphens.
4 changes: 3 additions & 1 deletion mix.exs
Expand Up @@ -97,7 +97,9 @@ defmodule EMQXUmbrella.MixProject do
{:gpb, "4.19.7", override: true, runtime: false},
{:hackney, github: "emqx/hackney", tag: "1.18.1-1", override: true},
# set by hackney (dependency)
{:ssl_verify_fun, "1.1.6", override: true}
{:ssl_verify_fun, "1.1.6", override: true},
{:uuid, github: "okeuday/uuid", tag: "v2.0.6", override: true},
{:quickrand, github: "okeuday/quickrand", tag: "v2.0.6", override: true}
] ++
emqx_apps(profile_info, version) ++
enterprise_deps(profile_info) ++ bcrypt_dep() ++ jq_dep() ++ quicer_dep()
Expand Down
1 change: 1 addition & 0 deletions rebar.config
Expand Up @@ -83,6 +83,7 @@
, {hackney, {git, "https://github.com/emqx/hackney.git", {tag, "1.18.1-1"}}}
%% in conflict by erlavro and rocketmq
, {jsone, {git, "https://github.com/emqx/jsone.git", {tag, "1.7.1"}}}
, {uuid, {git, "https://github.com/okeuday/uuid.git", {tag, "v2.0.6"}}}
]}.

{xref_ignores,
Expand Down

0 comments on commit 1ea92d4

Please sign in to comment.