fix(emqx_rule_engine): Dialyzer warning related to generated code

This commit is contained in:
Zaiming Shi 2020-11-09 21:28:58 +01:00
parent 6a1aae52eb
commit 764d5977c1
2 changed files with 26 additions and 16 deletions

View File

@ -49,6 +49,10 @@
-export_type([select/0]). -export_type([select/0]).
%% Dialyzer gives up on the generated code.
%% probably due to stack depth, or inlines.
-dialyzer({nowarn_function, [parse_select/1]}).
%% Parse one select statement. %% Parse one select statement.
-spec(parse_select(string() | binary()) -spec(parse_select(string() | binary())
-> {ok, select()} | {parse_error, term()} | {lex_error, term()}). -> {ok, select()} | {parse_error, term()} | {lex_error, term()}).
@ -76,7 +80,7 @@ parse_select(Sql) ->
end end
catch catch
_Error:Reason:StackTrace -> _Error:Reason:StackTrace ->
{parse_error, Reason, StackTrace} {parse_error, {Reason, StackTrace}}
end. end.
-spec(select_fields(select()) -> list(field())). -spec(select_fields(select()) -> list(field())).

View File

@ -21,24 +21,30 @@
-export([ test/1 -export([ test/1
]). ]).
%% Dialyzer gives up on the generated code.
%% probably due to stack depth, or inlines.
-dialyzer({nowarn_function, [test/1,
test_rule/4,
flatten/1,
sql_test_action/0,
fill_default_values/2
]}).
-spec(test(#{}) -> {ok, Result::map()} | no_return()). -spec(test(#{}) -> {ok, Result::map()} | no_return()).
test(#{<<"rawsql">> := Sql, <<"ctx">> := Context}) -> test(#{<<"rawsql">> := Sql, <<"ctx">> := Context}) ->
case emqx_rule_sqlparser:parse_select(Sql) of {ok, Select} = emqx_rule_sqlparser:parse_select(Sql),
{ok, Select} -> InTopic = maps:get(<<"topic">>, Context, <<>>),
InTopic = maps:get(<<"topic">>, Context, <<>>), EventTopics = emqx_rule_sqlparser:select_from(Select),
EventTopics = emqx_rule_sqlparser:select_from(Select), case lists:all(fun is_publish_topic/1, EventTopics) of
case lists:all(fun is_publish_topic/1, EventTopics) of true ->
true -> %% test if the topic matches the topic filters in the rule
%% test if the topic matches the topic filters in the rule case emqx_rule_utils:can_topic_match_oneof(InTopic, EventTopics) of
case emqx_rule_utils:can_topic_match_oneof(InTopic, EventTopics) of true -> test_rule(Sql, Select, Context, EventTopics);
true -> test_rule(Sql, Select, Context, EventTopics); false -> {error, nomatch}
false -> {error, nomatch}
end;
false ->
%% the rule is for both publish and events, test it directly
test_rule(Sql, Select, Context, EventTopics)
end; end;
Error -> error(Error) false ->
%% the rule is for both publish and events, test it directly
test_rule(Sql, Select, Context, EventTopics)
end. end.
test_rule(Sql, Select, Context, EventTopics) -> test_rule(Sql, Select, Context, EventTopics) ->