Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions databend_py/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ class Connection(object):
# 'database': 'default'
# }
def __init__(self, host, port=None, user=defines.DEFAULT_USER, password=defines.DEFAULT_PASSWORD,
connect_timeout=defines.DEFAULT_CONNECT_TIMEOUT,
database=defines.DEFAULT_DATABASE, secure=False, copy_purge=False, session_settings=None,
persist_cookies=False):
self.host = host
self.port = port
self.user = user
self.password = password
self.database = database
self.connect_timeout = connect_timeout
self.secure = secure
self.copy_purge = copy_purge
self.session_max_idle_time = defines.DEFAULT_SESSION_IDLE_TIME
Expand Down Expand Up @@ -124,6 +126,7 @@ def do_query(self, url, query_sql):
data=json.dumps(query_sql),
headers=self.make_headers(),
auth=HTTPBasicAuth(self.user, self.password),
timeout=self.connect_timeout,
verify=True)
try:
resp_dict = json.loads(response.content)
Expand Down
1 change: 1 addition & 0 deletions databend_py/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
DEFAULT_USER = 'root'
DEFAULT_PASSWORD = ''
DEFAULT_SESSION_IDLE_TIME = 30
DEFAULT_CONNECT_TIMEOUT = 20

DBMS_NAME = 'Databend'
CLIENT_NAME = 'databend-py'
Expand Down
3 changes: 3 additions & 0 deletions databend_py/retry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from databend_py.errors import WarehouseTimeoutException


Expand All @@ -22,6 +24,7 @@ def newfn(*args, **kwargs):
'Exception thrown when attempting to run %s, attempt '
'%d of %d' % (func, attempt, times)
)
time.sleep(attempt * 5)
attempt += 1
return func(*args, **kwargs)

Expand Down
24 changes: 13 additions & 11 deletions docs/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ client = Client(
database="default",
user="user",
port="443",
secure=True,
password="password", settings={"copy_purge": True, "force": True})
```

### Parameter References

| Parameter | Description | Default | example |
|------------------|----------------------------------------------------------------------------------------------------------|-------------|------------------------------------------------|
| user | username | root | |
| password | password | None | | |
| port | server port | None | |
| database | selected database | default |
| secure | Enable SSL | false | http://root@localhost:8000/db?secure=False |
| copy_purge | If True, the command will purge the files in the stage after they are loaded successfully into the table | false | http://root@localhost:8000/db?copy_purge=False |
| debug | Enable debug log | False | http://root@localhost:8000/db?debug=True |
| persist_cookies | if using cookies set by server to perform following requests. | False | http://root@localhost:8000/db?persist_cookies=True|
| null_to_none | if the result data NULL which is of type str, change it to NoneType | False | http://root@localhost:8000/db?null_to_none=True|
| Parameter | Description | Default | example |
|-------------------|----------------------------------------------------------------------------------------------------------|---------|-----------------------------------------------------------|
| user | username | root | |
| password | password | None | | |
| port | server port | None | |
| database | selected database | default |
| secure | Enable SSL | false | http://root@localhost:8000/db?secure=False |
| copy_purge | If True, the command will purge the files in the stage after they are loaded successfully into the table | false | http://root@localhost:8000/db?copy_purge=False |
| debug | Enable debug log | False | http://root@localhost:8000/db?debug=True |
| persist_cookies | if using cookies set by server to perform following requests. | False | http://root@localhost:8000/db?persist_cookies=True |
| null_to_none | if the result data NULL which is of type str, change it to NoneType | False | http://root@localhost:8000/db?null_to_none=True |
| connect_timeout | timeout seconds when connect to databend | 20 | http://root:root@localhost:8000/db?connect_timeout=30 |

4 changes: 4 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def test_simple(self):
self.assertEqual(c.connection.schema, "http")
c = Client.from_url("databend://root:root@localhost:8000/default?compress=True")
self.assertEqual(c._uploader._compress, True)
self.assertEqual(c.connection.connect_timeout, 20)

c = Client.from_url("databend://root:root@localhost:8000/default?connect_timeout=30")
self.assertEqual(c.connection.connect_timeout, 30)

self.assertEqual(c.connection.persist_cookies, False)
c = Client.from_url('https://root:root@localhost:8000?persist_cookies=True')
Expand Down