summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorILYA Khlopotov <iilyak@apache.org>2018-10-17 10:35:11 -0700
committerILYA Khlopotov <iilyak@apache.org>2018-11-13 02:01:15 -0800
commitcbc8cf7ccbeffadb6978a9ede683d5c238886e07 (patch)
tree8b9dbe9cef3e9257db14869c8455e6a20b28d8c5
parent8d3b78c27394b183ff8352b2acb8d4af30f7753e (diff)
downloadcouchdb-cbc8cf7ccbeffadb6978a9ede683d5c238886e07.tar.gz
Support prefix based matching in couch_epi_data_gen
-rw-r--r--src/couch_epi/src/couch_epi_data_gen.erl22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/couch_epi/src/couch_epi_data_gen.erl b/src/couch_epi/src/couch_epi_data_gen.erl
index 16a5986eb..50876466d 100644
--- a/src/couch_epi/src/couch_epi_data_gen.erl
+++ b/src/couch_epi/src/couch_epi_data_gen.erl
@@ -149,15 +149,33 @@ version_method(Defs) ->
getter(Source, Key, Data) ->
D = couch_epi_codegen:format_term(Data),
Src = atom_to_list(Source),
- K = couch_epi_codegen:format_term(Key),
couch_epi_codegen:scan(
- "get(" ++ Src ++ ", " ++ K ++ ") ->" ++ D ++ ";").
+ "get(" ++ Src ++ ", " ++ format_key(Key) ++ ") ->" ++ D ++ ";").
version(Source, Data) ->
Src = atom_to_list(Source),
VSN = couch_epi_util:hash(Data),
couch_epi_codegen:scan("version(" ++ Src ++ ") ->" ++ VSN ++ ";").
+format_key(Key) when is_tuple(Key) ->
+ Parts = lists:map(fun format_key/1, tuple_to_list(Key)),
+ "{" ++ string:join(Parts, ",") ++ "}";
+format_key(Key) when is_list(Key) ->
+ case lists:reverse(Key) of
+ "*" ++ K -> "\"" ++ lists:reverse(K) ++ "\" ++ _";
+ _ -> couch_epi_codegen:format_term(Key)
+ end;
+format_key(Key) when is_binary(Key) andalso size(Key) > 0 ->
+ case binary:last(Key) of
+ $* ->
+ KeyList = binary_to_list(binary:part(Key, {0, size(Key) - 1})),
+ "<<\"" ++ KeyList ++ "\", _/binary>>";
+ _ ->
+ "<<\"" ++ binary_to_list(Key) ++ "\">>"
+ end;
+format_key(Key) ->
+ couch_epi_codegen:format_term(Key).
+
%% ------------------------------------------------------------------
%% Helper functions
%% ------------------------------------------------------------------