druid-io / pydruid

A Python connector for Druid
Other
506 stars 194 forks source link

Query Filter Or Syntax? #78

Closed philos22 closed 7 years ago

philos22 commented 7 years ago

what is the syntax for OR conditions in the filter argument?

eg. filter = (Dimension('A')=='val1') & ((Dimension('B')=='val2')# | (Dimension('C')=='val3'))

This doesn't seem to work, leads to error:

File "./pydruid_query.py", line 150, in <module> gfl2 = group_last2.export_tsv('group_last2_result.tsv') File "/usr/lib/python2.6/site-packages/pydruid/query.py", line 99, in export_tsv header = list(self.result[0]['event'].keys()) IndexError: list index out of range

ratb3rt commented 7 years ago

Apart from the rogue #, your example looks ok. You can look at the output of filter.build_filter(filter) to see what it's generated - this should be {'type': 'and', 'fields': [{'dimension': 'A', 'value': 'val1', 'type': 'selector'}, {'type': 'or', 'fields': [{'dimension': 'B', 'value': 'val2', 'type': 'selector'}, {'dimension': 'C', 'value': 'val3', 'type': 'selector'}]}]}