Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion databend_py/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def query(self, statement):
resp_dict = self.do_query(url, query_sql)
self.client_session = resp_dict.get("session", self.default_session())
self.additional_headers = {XDatabendQueryIDHeader: resp_dict.get(QueryID)}
return resp_dict
return self.wait_until_has_schema(resp_dict)
except Exception as err:
log.logger.error(
f"http error on {url}, SQL: {statement} error msg:{str(err)}"
Expand All @@ -182,6 +182,19 @@ def format_url(self):
def reset_session(self):
self.client_session = dict()

def wait_until_has_schema(self, raw_data_dict):
resp_schema = raw_data_dict.get("schema")
while resp_schema is not None and len(resp_schema) == 0:
if raw_data_dict['next_uri'] is None:
break
resp = self.next_page(raw_data_dict['next_uri'])
resp_dict = json.loads(resp.content)
raw_data_dict = resp_dict
resp_schema = raw_data_dict.get("schema")
if resp_schema is not None and (len(resp_schema) != 0 or len(raw_data_dict.get("data")) != 0):
break
return raw_data_dict

def next_page(self, next_uri):
url = "{}://{}:{}{}".format(self.schema, self.host, self.port, next_uri)
return self.requests_session.get(url=url, headers=self.make_headers(), cookies=self.cookies)
Expand Down