Commit 85dcf9f1 authored by Heinz N. Gies's avatar Heinz N. Gies
Browse files

Add exist queries

parent 061d0524
......@@ -39,7 +39,7 @@
},
{elvis_style, state_record_and_type},
{elvis_style, no_spec_with_records},
{elvis_style, dont_repeat_yourself, #{min_complexity => 12,
{elvis_style, dont_repeat_yourself, #{min_complexity => 13,
ignore => [dql_parser] }},
{elvis_style, no_debug_call,
#{ignore => []}}
......
......@@ -5,9 +5,9 @@
{<<"dflow">>,{pkg,<<"dflow">>,<<"0.3.0">>},0},
{<<"dproto">>,{pkg,<<"dproto">>,<<"0.5.2">>},0},
{<<"dqe_fun">>,{pkg,<<"dqe_fun">>,<<"0.2.1">>},0},
{<<"dqe_idx">>,{pkg,<<"dqe_idx">>,<<"0.4.2">>},0},
{<<"dqe_idx">>,{pkg,<<"dqe_idx">>,<<"0.4.3">>},0},
{<<"dqe_idx_ddb">>,{pkg,<<"dqe_idx_ddb">>,<<"0.5.1">>},0},
{<<"dqe_idx_pg">>,{pkg,<<"dqe_idx_pg">>,<<"0.5.5">>},0},
{<<"dqe_idx_pg">>,{pkg,<<"dqe_idx_pg">>,<<"0.5.7">>},0},
{<<"dynamic_compile">>,{pkg,<<"dynamic_compile">>,<<"1.0.0">>},1},
{<<"epgsql">>,{pkg,<<"epgsql">>,<<"3.3.0">>},2},
{<<"erlware_commons">>,{pkg,<<"erlware_commons">>,<<"1.0.0">>},0},
......@@ -16,7 +16,7 @@
{<<"ibrowse">>,{pkg,<<"ibrowse">>,<<"4.4.0">>},1},
{<<"jsxd">>,{pkg,<<"jsxd">>,<<"0.2.4">>},1},
{<<"lager">>,{pkg,<<"lager">>,<<"3.2.4">>},0},
{<<"mmath">>,{pkg,<<"mmath">>,<<"0.2.17">>},0},
{<<"mmath">>,{pkg,<<"mmath">>,<<"0.2.19">>},0},
{<<"otters">>,{pkg,<<"otters">>,<<"0.2.10">>},0},
{<<"pgapp">>,{pkg,<<"pgapp">>,<<"0.0.2">>},1},
{<<"poolboy">>,{pkg,<<"poolboy">>,<<"1.5.1">>},1},
......@@ -35,9 +35,9 @@
{<<"dflow">>, <<"DA0EB8F14B01ED894BD32F1CEE3B13646DFC30FA60D59B408BFCD0653E0984D7">>},
{<<"dproto">>, <<"D1C9929353589BD395CAB3E5C6E1CFC4DC8B0660527145E2DD221771D4467ABD">>},
{<<"dqe_fun">>, <<"6A634A0DC40D82365C7DE8BFEE6485E1A64770E6568497DEA70926DF46CE9B7C">>},
{<<"dqe_idx">>, <<"AF85F48FE83D023DFDA84BEE5BB5273B4A37C4A3DC4252FF4D0B5C39625833CE">>},
{<<"dqe_idx">>, <<"275F45869B1791BE6679D6B4A250C72CF43636CB4B3F2213E5D4AA6F8E0F1CF2">>},
{<<"dqe_idx_ddb">>, <<"8E0F6034A3890293A620293BC384BF1DDC8D9124985F56B304D6996603483EF2">>},
{<<"dqe_idx_pg">>, <<"1E96BE0F0FCAB1E64BBB6802393A0AA134B2EEDFACBCEB08EC3D2B4CB69F1C81">>},
{<<"dqe_idx_pg">>, <<"E6B24FEF5DD8F323FA14F67DB76DE15C0636B579E0CE6C5A3968CAD5EC3C0712">>},
{<<"dynamic_compile">>, <<"8171B2CB4953EA3ED2EF63F5B26ABF677ACD0CA32210C2A08A7A8406A743F76B">>},
{<<"epgsql">>, <<"974A578340E52012CBAB820CE756E7ED1DF1BAF0110C59A6753D8337A2CF9454">>},
{<<"erlware_commons">>, <<"087467DE5833C0BB5B3CCDD387F9E9C1FB816A75B7A709629BF24B5ED3246C51">>},
......@@ -46,7 +46,7 @@
{<<"ibrowse">>, <<"2D923325EFE0D2CB09B9C6A047B2835A5EDA69D8A47ED6FF8BC03628B764E991">>},
{<<"jsxd">>, <<"C14114AFCA463F2D03D3FB6CC81FD51CDA8CA86A47E5AC3ABDF0CA572A73A413">>},
{<<"lager">>, <<"A6DEB74DAE7927F46BD13255268308EF03EB206EC784A94EAF7C1C0F3B811615">>},
{<<"mmath">>, <<"DFD52637B19F1EEF6B0AAAC473CAC2FC27A7190B6A6420454A917423527F3030">>},
{<<"mmath">>, <<"8549F4A2A9C5239323A252974DAE8B40B61BE88826A0EF7E8077900DE943F9E6">>},
{<<"otters">>, <<"31A7B47D50E14B15CAE380D060F666A54A2D79688BCC29D4CCB70E2FE05B0EA8">>},
{<<"pgapp">>, <<"3E104BB777C8455D8B26D1538B67ABE0188EE97B1DF973FD936C2204CB316196">>},
{<<"poolboy">>, <<"6B46163901CFD0A1B43D692657ED9D7E599853B3B21B95AE5AE0A777CF9B6CA8">>},
......
......@@ -11,77 +11,90 @@
-export([expand/4]).
expand(Qs, Start, End, Opts) ->
lists:flatten([expand_grouped(Q, Start, End, [], Opts) || Q <- Qs]).
lists:flatten([expand_grouped(Q, Start, End, [], [], Opts) || Q <- Qs]).
expand_grouped({calc, Chain, #{op := group_by, args := [L, G, Fun]}},
Start, End, Groupings, Opts) ->
Start, End, Groupings, Names, Opts) ->
Groupings1 = Groupings ++ G,
R = expand_grouped(L, Start, End, Groupings1, Opts),
R = expand_grouped(L, Start, End, Groupings1, Names, Opts),
R1 = combine_groupings(R, G, Fun),
[{calc, Chain, E} || E <- R1];
expand_grouped(Q = #{op := events}, Start, End, _, _Opts) ->
expand_grouped(Q = #{op := events}, Start, End, _, _Names, _Opts) ->
[Q#{ranges => [{Start, End, default}]}];
expand_grouped(Q = #{op := named, args := [L, M, S]},
Start, End, Groupings, Opts)
Start, End, Groupings, Names, Opts)
when is_list(L) ->
MGs = [N || {_, {dvar, N}} <- M],
Gs = [N || {dvar, N} <- L],
[Q#{args => [L, M, S1]} ||
S1 <- expand_grouped(S, Start, End, Gs ++ MGs ++ Groupings, Opts)];
S1 <- expand_grouped(S, Start, End, MGs ++ Groupings,
Gs ++ Names, Opts)];
expand_grouped(Q = #{op := named, args := [N, M, S]},
Start, End, Groupings, Opts) ->
Start, End, Groupings, Names, Opts) ->
MGs = [D || {_, {dvar, D}} <- M],
[Q#{args => [N, M, S1]} ||
S1 <- expand_grouped(S, Start, End, MGs ++ Groupings, Opts)];
S1 <- expand_grouped(S, Start, End, MGs ++ Groupings, Names, Opts)];
expand_grouped(Q = #{op := timeshift, args := [T, S]},
Start, End, Groupings, Opts) ->
Start, End, Groupings, Names, Opts) ->
[Q#{args => [T, S1]} ||
S1 <- expand_grouped(S, Start, End, Groupings, Opts)];
S1 <- expand_grouped(S, Start, End, Groupings, Names, Opts)];
expand_grouped({calc, Fs, Q}, Start, End, Groupings, Opts) ->
[{calc, Fs, Q1} || Q1 <- expand_grouped(Q, Start, End, Groupings, Opts)];
expand_grouped({calc, Fs, Q}, Start, End, Groupings, Names, Opts) ->
[{calc, Fs, Q1} ||
Q1 <- expand_grouped(Q, Start, End, Groupings, Names, Opts)];
expand_grouped({combine, F, Qs}, Start, End, Groupings, Opts) ->
[{combine, F, lists:flatten([expand_grouped(Q, Start, End, Groupings, Opts)
|| Q <- Qs])}];
expand_grouped({combine, F, Qs}, Start, End, Groupings, Names, Opts) ->
[{combine, F,
lists:flatten([expand_grouped(Q, Start, End, Groupings, Names, Opts)
|| Q <- Qs])}];
expand_grouped(Q = #{op := get}, Start, End, _Groupings, _Opts) ->
expand_grouped(Q = #{op := get}, Start, End, _Groupings, _Names, _Opts) ->
[Q#{ranges => [{Start, End, default}]}];
expand_grouped(Q = #{op := lookup,
args := [Collection, Metric, Where]},
Start, End, [], Opts) ->
Start, End, [], [], Opts) ->
{ok, BMs} = dqe_idx:lookup({in, Collection, Metric, Where},
Start, End, Opts),
expand_lookup(Q, BMs, []);
expand_grouped(Q = #{op := lookup,
args := [Collection, Metric, Where]},
Start, End, Groupings, Opts) ->
Groupings1 = lists:usort(Groupings),
{ok, BMs} = dqe_idx:lookup({in, Collection, Metric, Where},
Start, End, Groupings1, Opts),
Start, End, Groupings, Names, Opts) ->
Groupings1 = lists:usort(Groupings ++ Names),
Query = {in, Collection, Metric, expand_where(Names, Where)},
{ok, BMs} = dqe_idx:lookup(Query, Start, End, Groupings1, Opts),
expand_lookup(Q, BMs, Groupings1);
expand_grouped(Q = #{op := lookup,
args := [Collection, Metric]}, Start, End, [], Opts) ->
args := [Collection, Metric]}, Start, End, [], [], Opts) ->
{ok, BMs} = dqe_idx:lookup({in, Collection, Metric},
Start, End, Opts),
expand_lookup(Q, BMs, []);
expand_grouped(Q = #{op := lookup,
args := [Collection, Metric]},
Start, End, Groupings, Opts) ->
Start, End, Groupings, [], Opts) ->
Groupings1 = lists:usort(Groupings),
{ok, BMs} = dqe_idx:lookup({in, Collection, Metric},
Start, End, Groupings1, Opts),
expand_lookup(Q, BMs, Groupings1);
expand_grouped(Q = #{op := lookup,
args := [Collection, Metric]},
Start, End, Groupings, [{Ns, K} | Names], Opts) ->
Groupings1 = lists:usort(Groupings ++ [{Ns, K} | Names]),
Where = expand_where(Names, {'exists', {tag, Ns, K}}),
Query = {in, Collection, Metric, Where},
{ok, BMs} = dqe_idx:lookup(Query, Start, End, Groupings1, Opts),
expand_lookup(Q, BMs, Groupings1);
expand_grouped(Q = #{op := sget,
args := [Bucket, Glob]}, Start, End, _Groupings, _Opts) ->
args := [Bucket, Glob]},
Start, End, _Groupings, _Names, _Opts) ->
%% Glob is in an extra list since expand is build to use one or more
%% globs
{ok, {_Bucket, Ms}} = dqe_idx:expand(Bucket, [Glob]),
......@@ -112,3 +125,8 @@ append_values(E = #{
}, Gs) ->
S = orddict:from_list(Values),
{[orddict:fetch(G, S) || G <- Gs], E}.
expand_where([], Where) ->
Where;
expand_where([{Ns, K} | R], W) ->
expand_where(R, {'and', {'exists', {tag, Ns, K}}, W}).
......@@ -22,7 +22,6 @@ update(Qs) ->
%%% Internal functions
%%%===================================================================
update_name({named, L, M, C = {calc, _, #{op := events}}}) when is_list(L) ->
{named, dql_unparse:unparse_metric(L), M, C};
......@@ -69,3 +68,4 @@ extract_groupings(#{groupings := Gs}) ->
Gs;
extract_groupings(_) ->
[].
......@@ -282,7 +282,7 @@ tag -> part_or_name ':' part_or_name : {tag, '$1', '$3'}.
where_part -> tag '=' part_or_name : {'=', '$1', '$3'}.
where_part -> tag op_ne part_or_name : {'!=', '$1', '$3'}.
where_part -> tag kw_not part_or_name : {'!=', '$1', '$3'}.
where_part -> tag : {'=', '$1', <<>>}.
where_part -> tag : {'exists', '$1'}.
where_part -> '(' where ')' : '$2'.
where -> where_part : '$1'.
......
└─ dqe─v0.7.6+build.315.ref0e91027
└─ dqe─0.7.9
├─ ddb_connection─0.4.3
│ ├─ ddb_client─0.5.7
│ └─ poolboy─1.5.1
......@@ -7,9 +7,9 @@
│ ├─ jsxd─0.2.4
│ └─ snappiest─1.2.0
├─ dqe_fun─0.2.1
├─ dqe_idx─0.4.2
├─ dqe_idx─0.4.3
├─ dqe_idx_ddb─0.5.1
├─ dqe_idx_pg─0.5.4
├─ dqe_idx_pg─0.5.7
│ ├─ pgapp─0.0.2
│ │ └─ epgsql─3.3.0
│ └─ sqlmig─0.1.5
......@@ -18,8 +18,8 @@
├─ hdr_histogram─0.2.0
├─ lager─3.2.4
│ └─ goldrush─0.1.9
├─ mmath─0.2.17
├─ otters─0.2.8
├─ mmath─0.2.19
├─ otters─0.2.10
│ ├─ dynamic_compile─1.0.0
│ └─ ibrowse─4.4.0
└─ qdate─0.4.4
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment