Closed Karmenzind closed 4 years ago
Thanks for raising the issue (and apologies for the super late reply).
This is a bug (thanks for catching!). It's probably coming from the fact that most of my queries are usually single statement queries and single return single series (and lack of testing).
Your fix is good for single-statement/multi-series queries but would fail for multi-statement queries (which I don't know why anyone would ever want to use, but InfluxDB allows it so we need code that can handle that).
Using itertools
, I think something like this would be more generic (basically just pushing out gs
up to the statement level):
def iterpoints(resp, parser=None):
gs = []
for statement in resp['results']:
if 'series' not in statement:
continue
for series in statement['series']:
if parser is None:
gs.append((x for x in series['values']))
elif 'meta' in inspect.signature(parser).parameters:
meta = {k: series[k] for k in series if k != 'values'}
meta['statement_id'] = statement['statement_id']
gs.append((parser(*x, meta=meta) for x in series['values']))
else:
gs.append((parser(*x) for x in series['values']))
return itertools.chain(*gs)
Let me know what you think.
I will add this fix to 0.10.0 (which will hopefully come out later this month).
Thank you! I'll try it at my leisure time.
Hi
During processing this query:
This is the raw data that
InfluxDBClient.query
returned.And I want to use this code to get parsed dicts:
But only got the first row (
"instance": "C:"
). And below is the source ofiterpoints
. As you can see, the for-loop returned at the first iteration.I modified this function as a workaround:
It worked for me. But it returned nested generator which might be wierd. I want to know if you have a better idea.