Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mas d31 i433re2capture #438

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ cover_*
.eqc-info
leveled_data/*
compile_commands.json
*parser.erl
*lexer.erl
5 changes: 3 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

{xref_checks,
[undefined_function_calls,undefined_functions,
locals_not_used,
deprecated_function_calls, deprecated_functions]}.

{cover_excl_mods,
[testutil,
[leveled_filterlexer, leveled_filterparser, leveled_evallexer, leveled_evalparser,
testutil,
appdefined_SUITE, basic_SUITE, iterator_SUITE,
perf_SUITE, recovery_SUITE, riak_SUITE, tictac_SUITE]}.

Expand All @@ -23,6 +23,7 @@
]},
{test, [{extra_src_dirs, ["test/end_to_end", "test/property"]}
]},
{perf_fexp, [{erl_opts, [{d, test_filter_expression}]}]},
{perf_full, [{erl_opts, [{d, performance, riak_fullperf}]}]},
{perf_mini, [{erl_opts, [{d, performance, riak_miniperf}]}]},
{perf_prof, [{erl_opts, [{d, performance, riak_profileperf}]}]}
Expand Down
2 changes: 1 addition & 1 deletion src/leveled_bookie.erl
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ book_returnfolder(Pid, RunnerType) ->
IndexVal::term(),
Start::IndexVal,
End::IndexVal,
ReturnTerms::boolean(),
ReturnTerms::boolean()|binary(),
TermRegex :: leveled_codec:regular_expression().

book_indexfold(Pid, Constraint, FoldAccT, Range, TermHandling)
Expand Down
54 changes: 48 additions & 6 deletions src/leveled_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,17 @@
{index_specs(), infinity|integer()}. % {KeyChanges, TTL}
-type maybe_lookup() ::
lookup|no_lookup.
-type actual_regex() ::
reference()|{re_pattern, term(), term(), term(), term()}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason not to use the opaque type re:mp() instead of re_patten...?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-type capture_value() :: binary()|integer().
-type capture_filter_fun() ::
fun((#{binary() => capture_value()}) -> boolean()).
-type capture_eval_fun() ::
fun((binary(), binary()) -> #{binary() => capture_value()}).
-type capture_reference() ::
{eval, capture_eval_fun(), capture_filter_fun()}.
-type regular_expression() ::
{re_pattern, term(), term(), term(), term()}|undefined.
% first element must be re_pattern, but tuple may change legnth with
% versions
actual_regex()|undefined|capture_reference().

-type value_fetcher() ::
{fun((pid(), leveled_codec:journal_key()) -> any()),
Expand Down Expand Up @@ -155,6 +162,7 @@
last_moddate/0,
lastmod_range/0,
regular_expression/0,
actual_regex/0,
value_fetcher/0,
proxy_object/0,
slimmed_key/0
Expand Down Expand Up @@ -292,8 +300,9 @@ maybe_accumulate(
maybe_accumulate(T, Acc, Count, Filter, AccFun).

-spec accumulate_index(
{boolean(), undefined|leveled_runner:mp()}, leveled_runner:acc_fun())
-> any().
{boolean()|binary(),
regular_expression()},
leveled_runner:acc_fun()) -> any().
accumulate_index({false, undefined}, FoldKeysFun) ->
fun({?IDX_TAG, Bucket, _IndexInfo, ObjKey}, _Value, Acc) ->
FoldKeysFun(Bucket, ObjKey, Acc)
Expand All @@ -302,9 +311,19 @@ accumulate_index({true, undefined}, FoldKeysFun) ->
fun({?IDX_TAG, Bucket, {_IdxFld, IdxValue}, ObjKey}, _Value, Acc) ->
FoldKeysFun(Bucket, {IdxValue, ObjKey}, Acc)
end;
accumulate_index(
{AddTerm, {eval, EvalFun, FilterFun}}, FoldKeysFun) ->
fun({?IDX_TAG, Bucket, {_IdxFld, IdxValue}, ObjKey}, _Value, Acc) ->
CptMap = EvalFun(IdxValue, ObjKey),
check_captured_terms(
CptMap,
FilterFun, AddTerm, FoldKeysFun,
Bucket, IdxValue, ObjKey,
Acc)
end;
accumulate_index({AddTerm, TermRegex}, FoldKeysFun) ->
fun({?IDX_TAG, Bucket, {_IdxFld, IdxValue}, ObjKey}, _Value, Acc) ->
case leveled_util:regex_run(IdxValue, TermRegex) of
case leveled_util:regex_run(IdxValue, TermRegex, []) of
nomatch ->
Acc;
_ ->
Expand All @@ -317,6 +336,29 @@ accumulate_index({AddTerm, TermRegex}, FoldKeysFun) ->
end
end.

check_captured_terms(
CptMap, FilterFun, AddTerm, FoldKeysFun, B, IdxValue, ObjKey, Acc) ->
case FilterFun(CptMap) of
true ->
case AddTerm of
true ->
FoldKeysFun(B, {IdxValue, ObjKey}, Acc);
false ->
FoldKeysFun(B, ObjKey, Acc);
CptKey when is_binary(CptKey) ->
case maps:get(CptKey, CptMap, undefined) of
undefined ->
Acc;
CptValue ->
FoldKeysFun(B, {CptValue, ObjKey}, Acc)
end
end;
false ->
Acc
end.



-spec key_dominates(ledger_kv(), ledger_kv()) -> boolean().
%% @doc
%% When comparing two keys in the ledger need to find if one key comes before
Expand Down
Loading