Skip to content

Commit

Permalink
add __ne__ to Dimension so you can filter = Dimension('dim') != val
Browse files Browse the repository at this point in the history
  • Loading branch information
dakra committed Mar 9, 2016
1 parent 56efc78 commit 5290823
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pydruid/utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def __init__(self, dim):
def __eq__(self, other):
return Filter(dimension=self.dimension, value=other)

def __ne__(self, other):
return ~Filter(dimension=self.dimension, value=other)

class JavaScript:
def __init__(self, dim):
self.dimension = dim
Expand Down
7 changes: 7 additions & 0 deletions tests/utils/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ def test_dimension(self):
expected = {'type': 'selector', 'dimension': 'dim', 'value': 'val'}
assert actual == expected

def test_ne_dimension(self):
d = filters.Dimension('dim')
actual = filters.Filter.build_filter(d != 'val')
expected = {'field': {'dimension': 'dim', 'type': 'selector', 'value': 'val'},
'type': 'not'}
assert actual == expected


class TestFilter:

Expand Down

0 comments on commit 5290823

Please sign in to comment.