From e1604d6219d293530e0d7bc0a869fe41f90f79a7 Mon Sep 17 00:00:00 2001 From: Nick McKoy Date: Thu, 31 Dec 2015 09:36:24 -0500 Subject: [PATCH 1/2] support javascript filter --- pydruid/utils/filters.py | 12 ++++++++++++ tests/utils/test_filters.py | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/pydruid/utils/filters.py b/pydruid/utils/filters.py index 9ee5677f..e448a073 100644 --- a/pydruid/utils/filters.py +++ b/pydruid/utils/filters.py @@ -27,6 +27,11 @@ def __init__(self, **args): "dimension": args["dimension"], "value": args["value"]}} + elif args["type"] == "javascript": + self.filter = {"filter": {"type": "javascript", + "dimension": args["dimension"], + "function": args["function"]}} + elif args["type"] == "and": self.filter = {"filter": {"type": "and", "fields": args["fields"]}} @@ -67,3 +72,10 @@ def __init__(self, dim): def __eq__(self, other): return Filter(dimension=self.dimension, value=other) + +class Javascript: + def __init__(self, dim): + self.dimension = dim + + def __eq__(self, func): + return Filter(type='javascript', dimension=self.dimension, function=func) diff --git a/tests/utils/test_filters.py b/tests/utils/test_filters.py index c1a851f1..644d60e4 100644 --- a/tests/utils/test_filters.py +++ b/tests/utils/test_filters.py @@ -22,6 +22,12 @@ def test_selector_filter(self): expected = {'type': 'selector', 'dimension': 'dim', 'value': 'val'} assert actual == expected + def test_javascript_filter(self): + actual = filters.Filter.build_filter( + filters.Filter(type='javascript', dimension='dim', function='function(x){return true}')) + expected = {'type': 'javascript', 'dimension': 'dim', 'function': 'function(x){return true}'} + assert actual == expected + def test_and_filter(self): f1 = filters.Filter(dimension='dim1', value='val1') f2 = filters.Filter(dimension='dim2', value='val2') From 10a8340af24eddbab955acbb304e18a24c418e1a Mon Sep 17 00:00:00 2001 From: Nick McKoy Date: Fri, 8 Jan 2016 13:03:16 -0500 Subject: [PATCH 2/2] camel case JavaScript --- pydruid/utils/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydruid/utils/filters.py b/pydruid/utils/filters.py index e448a073..51c423e8 100644 --- a/pydruid/utils/filters.py +++ b/pydruid/utils/filters.py @@ -73,7 +73,7 @@ def __init__(self, dim): def __eq__(self, other): return Filter(dimension=self.dimension, value=other) -class Javascript: +class JavaScript: def __init__(self, dim): self.dimension = dim