Packages
dqe
0.3.7
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.25
0.3.24
0.3.23
0.3.22
0.3.21
0.3.20
0.3.19
0.3.18
0.3.17
0.3.16
0.3.15
0.3.14
0.3.13
0.3.12
0.3.11
0.3.10
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.2.2
0.2.1
0.2.0
0.1.36
0.1.35
0.1.34
0.1.33
0.1.22
0.1.21
0.1.20
0.1.10
0.1.9
DalmatinerDB query engine
Current section
Files
Jump to
Current section
Files
src/dql_naming.erl
%%%-------------------------------------------------------------------
%%% @author Heinz Nikolaus Gies <heinz@project-fifo.net>
%%% @copyright (C) 2016, Heinz Nikolaus Gies
%%% @doc
%%% Naming related logic
%%% @end
%%% Created : 2 Aug 2016 by Heinz Nikolaus Gies <heinz@licenser.net>
%%%-------------------------------------------------------------------
-module(dql_naming).
-export([update/1]).
%%--------------------------------------------------------------------
%% @doc Updates names for query parts.
%% @end
%%--------------------------------------------------------------------
update(Qs) ->
[update_name(Q) || Q <- Qs].
%%%===================================================================
%%% Internal functions
%%%===================================================================
update_name({named, L, C}) when is_list(L)->
{Path, Gs} = extract_path_and_groupings(C),
Name = [update_name_element(N, Path, Gs) || N <- L],
{named, dql_unparse:unparse_metric(Name), C};
update_name({named, _N, _C} = Q) when is_binary(_N) ->
Q;
update_name({named, _N, _C} = Q) ->
io:format("Unkown named: ~p~n", [Q]),
Q.
update_name_element({dvar, N}, _Path, Gs) ->
{_, Name} = lists:keyfind(N, 1, Gs),
Name;
update_name_element({pvar, N}, Path, _Gs) ->
lists:nth(N, Path);
update_name_element(N, _, _) ->
N.
extract_path_and_groupings(G = #{op := get, args := [_,_,_,_,Path]})
when is_list(Path) ->
{Path, extract_groupings(G)};
extract_path_and_groupings(G = #{op := get, args := [_,_,_,_,Path]})
when is_binary(Path) ->
{dproto:metric_to_list(Path), extract_groupings(G)};
extract_path_and_groupings({calc, _, G}) ->
extract_path_and_groupings(G);
%% If we find a combine we take the values of its first element
%% for grouings all elements will have the same anyway and for
%% pvars there is no 'right' answer so picking the first is
%% as good as picking any other.
extract_path_and_groupings({combine, _, [G | _]}) ->
extract_path_and_groupings(G).
extract_groupings(#{groupings := Gs}) ->
Gs;
extract_groupings(_) ->
[].