long2ice / asynch

An asyncio ClickHouse Python Driver with native (TCP) interface support.
https://github.com/long2ice/asynch
Apache License 2.0
185 stars 43 forks source link

Optimize dict cursor when result is empty #65

Closed jiejieling closed 1 year ago

jiejieling commented 1 year ago

return {}/[] to instead of raising AttributeError when use dictCursor and result is empty

long2ice commented 1 year ago

Thanks!

jasonho-lynx commented 1 year ago

Sorry I'm late, but we should still return an error if the columns do not match. The empty dict and list should only be returned if the columns match but no rows are found, as mentioned in https://github.com/long2ice/asynch/issues/64. Example:

    async def fetchmany(self, size: int):
        rows = await super(DictCursor, self).fetchmany(size)
        if self._columns:
            return [dict(zip(self._columns, item)) for item in rows] if rows else []
        else:
            raise AttributeError("Not found valid columns")

The error message provides useful debugging information about why it is failing.