Repository: druid-io/pydruid

Issue:
Exception when `filter=None`
When building query if `filter=None` then an exception occurs:

```
File "/Users/se7entyse7en/Envs/viralize-web/lib/python2.7/site-packages/pydruid/utils/filters.py", line 61, in build_filter
    return filter_obj.filter['filter']
 AttributeError: 'NoneType' object has no attribute 'filter'
```


Discussion:
xvrl: @dakra some tests would be nice
dakra: I added a test

Patch:
diff --git a/pydruid/query.py b/pydruid/query.py
index af246a0..cd7c1cf 100644
--- a/pydruid/query.py
+++ b/pydruid/query.py
@@ -24,12 +24,6 @@ from pydruid.utils.dimensions import build_dimension
 from pydruid.utils.postaggregator import Postaggregator
 from pydruid.utils.query_utils import UnicodeWriter
 
-try:
-    import pandas
-except ImportError:
-    print('Warning: unable to import Pandas. The export_pandas method will not work.')
-    pass
-
 
 class Query(collections.MutableSequence):
     """
@@ -159,6 +153,8 @@ class Query(collections.MutableSequence):
                     0      7  2013-10-04T00:00:00.000Z         user_1
                     1      6  2013-10-04T00:00:00.000Z         user_2
         """
+        import pandas
+
         if self.result:
             if self.query_type == "timeseries":
                 nres = [list(v['result'].items()) + [('timestamp', v['timestamp'])]
@@ -250,11 +246,11 @@ class QueryBuilder(object):
                 query_dict['pagingSpec'] = val
             elif key == 'limit_spec':
                 query_dict['limitSpec'] = val
-            elif key == "filter":
+            elif key == "filter" and val is not None:
                 query_dict[key] = Filter.build_filter(val)
-            elif key == "having":
+            elif key == "having" and val is not None:
                 query_dict[key] = Having.build_having(val)
-            elif key == 'dimension':
+            elif key == 'dimension' and val is not None:
                 query_dict[key] = build_dimension(val)
             elif key == 'dimensions':
                 query_dict[key] = [build_dimension(v) for v in val]


Test patch:
diff --git a/tests/test_query.py b/tests/test_query.py
index 64da17b..d84f35b 100644
--- a/tests/test_query.py
+++ b/tests/test_query.py
@@ -111,6 +111,44 @@ class TestQueryBuilder:
         # then
         assert query.query_dict == expected_query_dict
 
+    def test_build_query_none_type(self):
+        # given
+        expected_query_dict = {
+            'queryType': None,
+            'dataSource': 'things',
+            'aggregations': [{'fieldName': 'thing', 'name': 'count', 'type': 'count'}],
+            'filter': {'dimension': 'one', 'type': 'selector', 'value': 1},
+            'having': {'aggregation': 'sum', 'type': 'greaterThan', 'value': 1},
+            'dimension': 'dim1',
+        }
+
+        builder = QueryBuilder()
+
+        # when
+        builder_dict = {
+            'datasource': 'things',
+            'aggregations': {
+                'count': aggregators.count('thing'),
+            },
+            'filter': filters.Dimension('one') == 1,
+            'having': having.Aggregation('sum') > 1,
+            'dimension': 'dim1',
+        }
+        query = builder.build_query(None, builder_dict)
+
+        # then
+        assert query.query_dict == expected_query_dict
+
+        # you should be able to pass `None` to dimension/having/filter
+        for v in ['dimension', 'having', 'filter']:
+            expected_query_dict[v] = None
+            builder_dict[v] = None
+
+            query = builder.build_query(None, builder_dict)
+
+            assert query.query_dict == expected_query_dict
+
+
     def test_validate_query(self):
         # given
         builder = QueryBuilder()