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

View File

@ -21,10 +21,18 @@
-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()).
test(#{<<"rawsql">> := Sql, <<"ctx">> := Context}) ->
case emqx_rule_sqlparser:parse_select(Sql) of
{ok, Select} ->
{ok, Select} = emqx_rule_sqlparser:parse_select(Sql),
InTopic = maps:get(<<"topic">>, Context, <<>>),
EventTopics = emqx_rule_sqlparser:select_from(Select),
case lists:all(fun is_publish_topic/1, EventTopics) of
@ -37,8 +45,6 @@ test(#{<<"rawsql">> := Sql, <<"ctx">> := Context}) ->
false ->
%% the rule is for both publish and events, test it directly
test_rule(Sql, Select, Context, EventTopics)
end;
Error -> error(Error)
end.
test_rule(Sql, Select, Context, EventTopics) ->