2727
2828class Query (collections .MutableSequence ):
2929 """
30- Query objects are produced by PyDruid clients and can be used for exporting query results into TSV files or
31- pandas.DataFrame objects for subsequent analysis. They also hold information about the issued query.
30+ Query objects are produced by PyDruid clients and can be used for
31+ exporting query results into TSV files or
32+ pandas.DataFrame objects for subsequent analysis. They also hold
33+ information about the issued query.
3234
3335 Query acts as a wrapper over raw result list of dictionaries.
3436
@@ -100,7 +102,8 @@ def export_tsv(self, dest_path):
100102 header .append ('timestamp' )
101103 header .append ('version' )
102104 else :
103- raise NotImplementedError ('TSV export not implemented for query type: {0}' .format (self .query_type ))
105+ raise NotImplementedError (
106+ 'TSV export not implemented for query type: {0}' .format (self .query_type ))
104107
105108 w .writerow (header )
106109
@@ -177,7 +180,9 @@ def export_pandas(self):
177180 for item in self .result :
178181 nres += [e .get ('event' ) for e in item ['result' ].get ('events' )]
179182 else :
180- raise NotImplementedError ('Pandas export not implemented for query type: {0}' .format (self .query_type ))
183+ raise NotImplementedError (
184+ 'Pandas export not implemented for query '
185+ 'type: {0}' .format (self .query_type ))
181186
182187 df = pandas .DataFrame (nres )
183188 return df
@@ -210,18 +215,22 @@ def parse_datasource(datasource, query_type):
210215 """
211216 Parse an input datasource object into valid dictionary
212217
213- Input can be a string, in which case it is simply returned, or a list, when it is turned into
214- a UNION datasource.
218+ Input can be a string, in which case it is simply returned, or a
219+ list, when it is turned into a UNION datasource.
215220
216221 :param datasource: datasource parameter
217222 :param string query_type: query type
218223 :raise ValueError: if input is not string or list of strings
219224 """
220225 if not (
221226 isinstance (datasource , six .string_types ) or
222- (isinstance (datasource , list ) and all ([isinstance (x , six .string_types ) for x in datasource ]))
227+ (
228+ isinstance (datasource , list ) and
229+ all ([isinstance (x , six .string_types ) for x in datasource ])
230+ )
223231 ):
224- raise ValueError ('Datasource definition not valid. Must be string or list of strings' )
232+ raise ValueError (
233+ 'Datasource definition not valid. Must be string or list of strings' )
225234 if isinstance (datasource , six .string_types ):
226235 return datasource
227236 else :
@@ -232,8 +241,9 @@ def validate_query(query_type, valid_parts, args):
232241 """
233242 Validate the query parts so only allowed objects are sent.
234243
235- Each query type can have an optional 'context' object attached which is used to set certain
236- query context settings, etc. timeout or priority. As each query can have this object, there's
244+ Each query type can have an optional 'context' object attached which
245+ is used to set certain query context settings, etc. timeout or
246+ priority. As each query can have this object, there's
237247 no need for it to be sent - it might as well be added here.
238248
239249 :param string query_type: a type of query
@@ -265,7 +275,8 @@ def build_query(self, query_type, args):
265275 if key == 'aggregations' :
266276 query_dict [key ] = build_aggregators (val )
267277 elif key == 'post_aggregations' :
268- query_dict ['postAggregations' ] = Postaggregator .build_post_aggregators (val )
278+ query_dict ['postAggregations' ] = \
279+ Postaggregator .build_post_aggregators (val )
269280 elif key == 'context' :
270281 query_dict ['context' ] = val
271282 elif key == 'datasource' :
@@ -290,8 +301,10 @@ def build_query(self, query_type, args):
290301
291302 def topn (self , args ):
292303 """
293- A TopN query returns a set of the values in a given dimension, sorted by a specified metric. Conceptually, a
294- topN can be thought of as an approximate GroupByQuery over a single dimension with an Ordering spec. TopNs are
304+ A TopN query returns a set of the values in a given dimension,
305+ sorted by a specified metric. Conceptually, a
306+ topN can be thought of as an approximate GroupByQuery over a
307+ single dimension with an Ordering spec. TopNs are
295308 faster and more resource efficient than GroupBy for this use case.
296309
297310 :param dict args: dict of arguments
@@ -310,7 +323,8 @@ def topn(self, args):
310323
311324 def timeseries (self , args ):
312325 """
313- A timeseries query returns the values of the requested metrics (in aggregate) for each timestamp.
326+ A timeseries query returns the values of the requested metrics
327+ (in aggregate) for each timestamp.
314328
315329 :param dict args: dict of args
316330
@@ -327,7 +341,8 @@ def timeseries(self, args):
327341
328342 def groupby (self , args ):
329343 """
330- A group-by query groups a results set (the requested aggregate metrics) by the specified dimension(s).
344+ A group-by query groups a results set (the requested aggregate
345+ metrics) by the specified dimension(s).
331346
332347 :param dict args: dict of args
333348
0 commit comments