bryanyang0528 / ksql-python

A python wrapper for the KSQL REST API.
MIT License
159 stars 67 forks source link

ksql.upload.FileUpload.upload() gives InvalidQueryError #98

Closed qtfkwk closed 2 years ago

qtfkwk commented 3 years ago

The following snippet from ksql/upload.py:38 has a problem which is causing the InvalidQueryError exception to be raised when parsing a file that has one statement per line and each statement ends with a semicolon. The issue seems to be caused by rule being an empty string after yielding, and then the last 2 lines check that the empty rule ends with a semicolon... but the last rule already yielded!

Believe the fix is to simply delete these lines.

    def get_rules_list(self, ksqlfile):
        with open(ksqlfile) as rf:
            rule = ""

            for line in rf:
                rule = rule + " " + line.strip()

                if rule[-1:] == ";":
                    yield rule
                    rule = ""

            if rule[-1:] != ";":
                raise InvalidQueryError(rule)
qtfkwk commented 3 years ago

https://github.com/bryanyang0528/ksql-python/pull/99

Ga11u commented 2 years ago

Is there any updates on this issue?

I agree with you. The code does not make sense. After reading all lines in the file the rule will be equal to "" .

Therefore this lines will always rise and error:

if rule[-1:] != ";":
    raise InvalidQueryError(rule)

If these lines are equal to something else than "" that would mean the last query was invalid, and if it is equal to ";" , this means the last rule has not bien yield, but this second scenario cannot happend within the current code. Hence, these lines should al least be changed to:

if rule[-1:] != "":
    raise InvalidQueryError(rule)