bryanyang0528/ksql-python

Response of client.query RuntimeError

Opened this issue · 0 comments

I'm trying to read from ksql in python with this script:

from ksql import KSQLAPI

client = KSQLAPI('http://0.0.0.0:8088',)
columns = ['id INT','name VARCHAR']
client.create_stream(table_name='students', columns_type= columns, topic='students')
query = client.query("SELECT name FROM students WHERE id = 1 ")
for student in query:
    print(student)

I was expecting a sequence of objects, as the documentation explains, instead it returns me a string representing pieces of an array of objects, with headers and at the end, a "RuntimeError: generator raised StopIteration" (each row is generated separately):

[{"header":{"queryId":"transient_STUDENTS_5788262560238090205","schema":"`NAME` STRING"}},

{"row":{"columns":["Alex"]}},

]

---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
[...]
The above exception was the direct cause of the following exception:
RuntimeError                              Traceback (most recent call last)
[...]
RuntimeError: generator raised StopIteration

This way I have to handle the exception or I have to break the loop when I find the ']' character. Also, I need to clean up each string because it is not a valid JSON (due to the final comma and new line), before deserializing it into a Python object with json.loads(str).