Skip to content

Commit

Permalink
Don't try to send readonly settings (even for send_progress or compre…
Browse files Browse the repository at this point in the history
…ssion) (#20)

* Make sure we don't send read only settings, remove brotli (seems broken), fix ping

* Fix Lint

* Don't modify keyword arguments
  • Loading branch information
genzgd authored Jun 17, 2022
1 parent 0af2727 commit 91c9f6a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion clickhouse_connect/driver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _validate_settings(self, settings: Dict[str, Any]):
if 'session' not in key:
setting_def = self.server_settings.get(key)
if setting_def is None or setting_def.readonly:
logger.warning('Setting %s is not valid or read only, ignoring', key)
logger.debug('Setting %s is not valid or read only, ignoring', key)
continue
validated[key] = value
return validated
Expand Down
22 changes: 13 additions & 9 deletions clickhouse_connect/driver/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import atexit
import re
import http as PyHttp

from typing import Optional, Dict, Any, Sequence, Union, List
from requests import Session, Response
from requests import Session, Response, get as req_get
from requests.adapters import HTTPAdapter
from requests.exceptions import RequestException

Expand All @@ -26,7 +27,7 @@
atexit.register(http_adapter.close)

# Increase this number just to be safe when ClickHouse is returning progress headers
PyHttp._MAXHEADERS = 10000 # pylint: disable=protected-access
PyHttp._MAXHEADERS = 10000 # pylint: disable=protected-access


# pylint: disable=too-many-instance-attributes
Expand Down Expand Up @@ -90,8 +91,6 @@ def __init__(self, interface: str, host: str, port: int, username: str, password
session.mount(self.url, adapter=http_adapter)
session.headers['User-Agent'] = client_name

if compress:
session.headers['Accept-Encoding'] = 'gzip, br'
if data_format == 'native':
self.read_format = self.write_format = 'Native'
self.build_insert = native.build_insert
Expand All @@ -106,16 +105,21 @@ def __init__(self, interface: str, host: str, port: int, username: str, password
self.session = session
self.connect_timeout = connect_timeout
self.read_timeout = send_receive_timeout
settings = kwargs.copy()
if send_progress:
self.session.params['send_progress_in_http_headers'] = '1'
self.session.params['wait_end_of_query'] = '1'
settings['send_progress_in_http_headers'] = '1'
settings['wait_end_of_query'] = '1'
if self.read_timeout > 10:
progress_interval = (self.read_timeout - 2) * 1000
else:
progress_interval = 120000 # Two minutes
self.session.params['http_headers_progress_interval_ms'] = str(progress_interval)
super().__init__(database=database, query_limit=query_limit, uri=self.url, settings=kwargs)
settings['http_headers_progress_interval_ms'] = str(progress_interval)
if compress:
session.headers['Accept-Encoding'] = 'gzip'
settings['enable_http_compression'] = '1'
super().__init__(database=database, query_limit=query_limit, uri=self.url, settings=settings)

# Note that this will stop any "readonly" settings from blowing up even if we set them in the constructor
def _apply_settings(self, settings: Dict[str, Any] = None):
valid_settings = self._validate_settings(settings)
for key, value in valid_settings.items():
Expand Down Expand Up @@ -247,7 +251,7 @@ def ping(self):
See BaseClient doc_string for this method
"""
try:
response = self.session.get(f'{self.url}/ping', timeout=3)
response = req_get(f'{self.url}/ping', timeout=3)
return 200 <= response.status_code < 300
except RequestException:
logger.debug('ping failed', exc_info=True)
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def run_setup(try_c: bool = True):
extras_require={
'sqlalchemy': ['sqlalchemy>1.3.21, <1.4'],
'superset': ['apache_superset>=1.4.1', 'sqlalchemy>1.3.21, <1.4'],
'brotli': ['brotli>=1.09'],
'numpy': ['numpy'],
'pandas': ['pandas']
},
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_insert(test_client: Client, test_table_engine: str):


def test_decimal_conv(test_client: Client, test_table_engine: str):
test_client.command('DROP TABLE IF EXISTS test_number_conv')
test_client.command('DROP TABLE IF EXISTS test_num_conv')
test_client.command('CREATE TABLE test_num_conv (col1 UInt64, col2 Int32, f1 Float64)' +
f' Engine {test_table_engine} ORDER BY col1')
data = [[Decimal(5), Decimal(-182), Decimal(55.2)], [Decimal(57238478234), Decimal(77), Decimal(-29.5773)]]
Expand Down

0 comments on commit 91c9f6a

Please sign in to comment.