Procházet zdrojové kódy

Merge branch 'develop'

develop-0.1.8
Pedram Nimreezi před 9 roky
rodič
revize
f2c3489ffb
5 změnil soubory, kde provedl 44 přidání a 4 odebrání
  1. +7
    -0
      README.org
  2. +18
    -2
      src/glc.erl
  3. +2
    -1
      src/glc_code.erl
  4. +7
    -0
      src/glc_lib.erl
  5. +10
    -1
      src/glc_ops.erl

+ 7
- 0
README.org Zobrazit soubor

@ -51,6 +51,11 @@ Select all events where 'a' exists and is equal to 0.
glc:eq(a, 0).
#+END_EXAMPLE
Select all events where 'a' exists and is not equal to 0.
#+BEGIN_EXAMPLE
glc:neq(a, 0).
#+END_EXAMPLE
Select all events where 'a' exists and is less than 0.
#+BEGIN_EXAMPLE
glc:lt(a, 0).
@ -220,6 +225,8 @@ or
#+END_EXAMPLE
* CHANGELOG
0.1.8
- Add support for not equal
0.1.7
- Support multiple functions specified using `with/2`

+ 18
- 2
src/glc.erl Zobrazit soubor

@ -28,6 +28,8 @@
%% glc:gt(a, 0).
%% %% Select all events where 'a' exists and is equal to 0.
%% glc:eq(a, 0).
%% %% Select all events where 'a' exists and is not equal to 0.
%% glc:neq(a, 0).
%% %% Select all events where 'a' exists and is less than 0.
%% glc:lt(a, 0).
%% %% Select all events where 'a' exists and is anything.
@ -74,7 +76,7 @@
-export([
lt/2, lte/2,
eq/2,
eq/2, neq/2,
gt/2, gte/2,
wc/1,
nf/1
@ -113,6 +115,10 @@ lte(Key, Term) ->
eq(Key, Term) ->
glc_ops:eq(Key, Term).
-spec neq(atom(), term()) -> glc_ops:op().
neq(Key, Term) ->
glc_ops:neq(Key, Term).
-spec gt(atom(), term()) -> glc_ops:op().
gt(Key, Term) ->
glc_ops:gt(Key, Term).
@ -434,13 +440,23 @@ events_test_() ->
fun() ->
%% If a selection condition but no body is specified the event
%% counts as input to the query, but not as filtered out.
{compiled, Mod} = setup_query(testmod7, glc:eq('$n', 'noexists@nohost')),
{compiled, Mod} = setup_query(testmod7a, glc:eq('$n', 'noexists@nohost')),
glc:handle(Mod, gre:make([{'$n', 'noexists@nohost'}], [list])),
?assertEqual(1, Mod:info(input)),
?assertEqual(0, Mod:info(filter)),
?assertEqual(1, Mod:info(output))
end
},
{"opfilter not equal test",
fun() ->
{compiled, Mod} = setup_query(testmod7b, glc:neq('$n', 'noexists@nohost')),
glc:handle(Mod, gre:make([{'$n', 'noexists@nohost'}], [list])),
glc:handle(Mod, gre:make([{'$n', 'notexists@nohost'}], [list])),
?assertEqual(2, Mod:info(input)),
?assertEqual(1, Mod:info(filter)),
?assertEqual(1, Mod:info(output))
end
},
{"opfilter wildcard test",
fun() ->
{compiled, Mod} = setup_query(testmod8, glc:wc(a)),

+ 2
- 1
src/glc_code.erl Zobrazit soubor

@ -253,10 +253,11 @@ abstract_filter_({Key, '!'}, OnMatch, OnNomatch, State) ->
_OnMatch=fun(#state{}=State2) -> OnMatch(State2) end,
State);
abstract_filter_({Key, Op, Value}, OnMatch, OnNomatch, State)
when Op =:= '>'; Op =:= '='; Op =:= '<';
when Op =:= '>'; Op =:= '='; Op =:= '!='; Op =:= '<';
Op =:= '>='; Op =:= '=<'; Op =:= '<=' ->
Op2 = case Op of
'=' -> '=:=';
'!=' -> '=/=';
'<=' -> '=<';
Op -> Op
end,

+ 7
- 0
src/glc_lib.erl Zobrazit soubor

@ -65,6 +65,11 @@ matches({Key, '=', Term}, Event) ->
{true, Term2} -> Term2 =:= Term;
false -> false
end;
matches({Key, '!=', Term}, Event) ->
case gre:find(Key, Event) of
{true, Term2} -> Term2 =/= Term;
false -> false
end;
matches({Key, '>', Term}, Event) ->
case gre:find(Key, Event) of
{true, Term2} -> Term2 > Term;
@ -253,6 +258,8 @@ is_valid({Field, '=<', _Term}) when is_atom(Field) ->
true;
is_valid({Field, '=', _Term}) when is_atom(Field) ->
true;
is_valid({Field, '!=', _Term}) when is_atom(Field) ->
true;
is_valid({Field, '>=', _Term}) when is_atom(Field) ->
true;
is_valid({Field, '>', _Term}) when is_atom(Field) ->

+ 10
- 1
src/glc_ops.erl Zobrazit soubor

@ -3,7 +3,7 @@
-export([
lt/2, lte/2,
eq/2,
eq/2, neq/2,
gt/2, gte/2,
wc/1,
nf/1
@ -23,6 +23,7 @@
-type op() ::
{atom(), '=<', term()} |
{atom(), '=', term()} |
{atom(), '!=', term()} |
{atom(), '>', term()} |
{atom(), '>=', term()} |
{atom(), '*'} |
@ -55,6 +56,14 @@ eq(Key, Term) when is_atom(Key) ->
eq(Key, Term) ->
erlang:error(badarg, [Key, Term]).
%% @doc Test that a field value is not equal to a term.
-spec neq(atom(), term()) -> op().
neq(Key, Term) when is_atom(Key) ->
{Key, '!=', Term};
neq(Key, Term) ->
erlang:error(badarg, [Key, Term]).
%% @doc Test that a field value is greater than a term.
-spec gt(atom(), term()) -> op().
gt(Key, Term) when is_atom(Key) ->

Načítá se…
Zrušit
Uložit