treasure-data / td-client-python

Treasure Data API library for Python
Apache License 2.0
47 stars 24 forks source link

job.result_format('json') returns an error #4

Closed kiyoto closed 9 years ago

kiyoto commented 9 years ago

OS: Windows 8.1 64-bit Python: 2.7.8 (Anaconda 2.1.0) tdclient version: 0.1.9

import tdclient
client = tdclient.Client('APIKEY')
job = client.query('sample_datasets', 'SELECT symbol, COUNT(1) FROM nasdaq GROUP BY symbol', type='presto')
# wait for job.finished() == True
[j for j in job.result_format('json')]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-33-82d90024ed4f> in <module>()
----> 1 [j for j in job.result_format('json')]

C:\Users\Kiyoto\Anaconda\lib\site-packages\tdclient\model.pyc in result_format(self, format)
    615         else:
    616             if self._result is None:
--> 617                 for row in self._client.job_result_format_each(self._job_id, format):
    618                     yield row
    619             else:

C:\Users\Kiyoto\Anaconda\lib\site-packages\tdclient\client.pyc in job_result_format_each(self, job_id, format)
    329         Returns: an iterator of rows in result set
    330         """
--> 331         for row in self.api.job_result_format_each(job_id, format):
    332             yield row
    333

C:\Users\Kiyoto\Anaconda\lib\site-packages\tdclient\job_api.pyc in job_result_format_each(self, job_id, format)
    179                     yield row
    180             elif format == "json":
--> 181                 unpacker = json.load(codecs.getreader("utf-8")(res))
    182                 for row in unpacker:
    183                     yield row

C:\Users\Kiyoto\Anaconda\lib\json\__init__.pyc in load(fp, encoding, cls, object_hook, parse_float, parse_int, parse_constant, objec
t_pairs_hook, **kw)
    288         parse_float=parse_float, parse_int=parse_int,
    289         parse_constant=parse_constant, object_pairs_hook=object_pairs_hook,
--> 290         **kw)
    291
    292

C:\Users\Kiyoto\Anaconda\lib\json\__init__.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, objec
t_pairs_hook, **kw)
    336             parse_int is None and parse_float is None and
    337             parse_constant is None and object_pairs_hook is None and not kw):
--> 338         return _default_decoder.decode(s)
    339     if cls is None:
    340         cls = JSONDecoder

C:\Users\Kiyoto\Anaconda\lib\json\decoder.pyc in decode(self, s, _w)
    367         end = _w(s, end).end()
    368         if end != len(s):
--> 369             raise ValueError(errmsg("Extra data", s, end, len(s)))
    370         return obj
    371

ValueError: Extra data: line 2 column 1 - line 2833 column 1 (char 14 - 38650)
yyuu commented 9 years ago

hmm. confirmed the reproduction.... will fix it.

yyuu commented 9 years ago

@kiyoto I found a bug in test case. I fixed tests and relating impl as well, and released v0.1.10. Please check if your problem has been solved.

https://pypi.python.org/pypi/td-client/0.1.10