Skip to content

Commit

Permalink
Skvh snap filter fix (#318)
Browse files Browse the repository at this point in the history
* #308
'*' is not interpreted as wildcard becuse only symbols in list are considered wildcards.
added clause hasWild to interpret '*' as wildcard too.

* #308 Added unit test for testing behaviour of filter compilation for ['*'] case

* #308 - added specific case for skvh '*' handling in filter2ms

* #308 Updated tests according to comments

* cosmetics and refactoring

Co-authored-by: piosok <[email protected]>
  • Loading branch information
c-bik and piosok authored Feb 10, 2020
1 parent 4d63516 commit b9d4a72
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/imem_snap.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1158,13 +1158,16 @@ process_chunk(SkvhMap, FoldFun, #{skvh := true} = Ctx) ->
process_chunk(Rec, FoldFun, Ctx) ->
apply_fold_fun(Rec, FoldFun, Ctx).

filters2ms(true, Filters) ->
[case hasWild(Filter) of
false -> {#{ckey => Filter}, [], ['$_']};
true -> {#{ckey => '$1'}, f2mc(Filter, '$1'), ['$_']}
end || Filter <- Filters];
filters2ms(false, Filters) ->
[{'$1', f2mc(Filter, {element, 2, '$1'}), ['$_']} || Filter <- Filters].
filters2ms(_, []) -> [];
filters2ms(true, [Filter|Filters]) ->
[filter2ms(Filter) | filters2ms(true, Filters)];
filters2ms(false, [Filter | Filters]) ->
[{'$1', f2mc(Filter, {element, 2, '$1'}), ['$_']} | filters2ms(false, Filters)].

filter2ms(Filter) -> filter2ms(Filter, hasWild(Filter)).
filter2ms('*', _) -> {'$1', [], ['$_']};
filter2ms(Filter, false) -> {#{ckey => Filter}, [], ['$_']};
filter2ms(Filter, true) -> {#{ckey => '$1'}, f2mc(Filter, '$1'), ['$_']}.

apply_fold_fun(Term, FoldFun, Ctx) ->
case FoldFun(Term, Ctx) of
Expand Down Expand Up @@ -1388,7 +1391,7 @@ f2mc_test_() ->
{
inparallel,
[{
lists:flatten(io_lib:format("~s : ~p", [Title, Filter])),
Title,
fun() ->
case catch f2mc(Filter, '$1') of
{'EXIT', Exception} ->
Expand Down Expand Up @@ -1451,6 +1454,21 @@ f2mc_test_() ->
]
}.

filters2ms_test_() ->
{
inparallel,
[
{
Title,
?_assertEqual(MatchSpec, filters2ms(IsSkvh, Filter))
} || {Title, IsSkvh, Filter, MatchSpec} <- [
{"all", false, ['*'], [{'$1',[],['$_']}]},
{"list all", true, [['*']], [{#{ckey => '$1'},[{is_list,'$1'}],['$_']}] },
{"all tuple", true, [{'*'}], [{#{ckey => '$1'},[{is_tuple,'$1'}],['$_']}]}
]
]
}.

msrun_test_() ->
Rows = [
["a"],
Expand Down

0 comments on commit b9d4a72

Please sign in to comment.