diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-06-05 07:36:16 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-06-05 07:42:42 +0300 |
commit | 18e6e1ed077f6c8502bb6951a1038be3ab063ecf (patch) | |
tree | 659fe8eced3538fa3e08d1daf118609ec8aa946a /contrib/python | |
parent | 902434a635e28f993f4f67c3db938e9441a36935 (diff) | |
download | ydb-18e6e1ed077f6c8502bb6951a1038be3ab063ecf.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/python')
8 files changed, 28 insertions, 19 deletions
diff --git a/contrib/python/clickhouse-connect/.dist-info/METADATA b/contrib/python/clickhouse-connect/.dist-info/METADATA index a652118c3c0..725bcd5664f 100644 --- a/contrib/python/clickhouse-connect/.dist-info/METADATA +++ b/contrib/python/clickhouse-connect/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: clickhouse-connect -Version: 0.7.8 +Version: 0.7.9 Summary: ClickHouse Database Core Driver for Python, Pandas, and Superset Home-page: https://github.com/ClickHouse/clickhouse-connect Author: ClickHouse Inc. diff --git a/contrib/python/clickhouse-connect/clickhouse_connect/__version__.py b/contrib/python/clickhouse-connect/clickhouse_connect/__version__.py index a83c69d4e1c..bebdf7d0bcb 100644 --- a/contrib/python/clickhouse-connect/clickhouse_connect/__version__.py +++ b/contrib/python/clickhouse-connect/clickhouse_connect/__version__.py @@ -1 +1 @@ -version = '0.7.8' +version = '0.7.9' diff --git a/contrib/python/clickhouse-connect/clickhouse_connect/driver/__init__.py b/contrib/python/clickhouse-connect/clickhouse_connect/driver/__init__.py index 1320c042138..2f0b11b1324 100644 --- a/contrib/python/clickhouse-connect/clickhouse_connect/driver/__init__.py +++ b/contrib/python/clickhouse-connect/clickhouse_connect/driver/__init__.py @@ -79,7 +79,8 @@ def create_client(*, if parsed.path and (not database or database == '__default__'): database = parsed.path[1:].split('/')[0] database = database or parsed.path - kwargs.update(dict(parse_qs(parsed.query))) + for k, v in parse_qs(parsed.query).items(): + kwargs[k] = v[0] use_tls = str(secure).lower() == 'true' or interface == 'https' or (not interface and port in (443, 8443)) if not host: host = 'localhost' diff --git a/contrib/python/clickhouse-connect/clickhouse_connect/driver/client.py b/contrib/python/clickhouse-connect/clickhouse_connect/driver/client.py index f329b396cb2..2817f1e1e6a 100644 --- a/contrib/python/clickhouse-connect/clickhouse_connect/driver/client.py +++ b/contrib/python/clickhouse-connect/clickhouse_connect/driver/client.py @@ -41,6 +41,7 @@ class Client(ABC): database = None max_error_message = 0 apply_server_timezone = False + show_clickhouse_errors = True def __init__(self, database: str, @@ -48,7 +49,8 @@ class Client(ABC): uri: str, query_retries: int, server_host_name: Optional[str], - apply_server_timezone: Optional[Union[str, bool]]): + apply_server_timezone: Optional[Union[str, bool]], + show_clickhouse_errors: Optional[bool]): """ Shared initialization of ClickHouse Connect client :param database: database name @@ -57,6 +59,8 @@ class Client(ABC): """ self.query_limit = coerce_int(query_limit) self.query_retries = coerce_int(query_retries) + if show_clickhouse_errors is not None: + self.show_clickhouse_errors = coerce_bool(show_clickhouse_errors) self.server_host_name = server_host_name self.server_tz, dst_safe = pytz.UTC, True self.server_version, server_tz = \ @@ -72,7 +76,7 @@ class Client(ABC): if not self.apply_server_timezone and not tzutil.local_tz_dst_safe: logger.warning('local timezone %s may return unexpected times due to Daylight Savings Time/' + - 'Summer Time differences', tzutil.local_tz.tzname()) + 'Summer Time differences', tzutil.local_tz.tzname(None)) readonly = 'readonly' if not self.min_version('19.17'): readonly = common.get_setting('readonly') diff --git a/contrib/python/clickhouse-connect/clickhouse_connect/driver/httpclient.py b/contrib/python/clickhouse-connect/clickhouse_connect/driver/httpclient.py index a98035d8398..0d7a6b7fdb6 100644 --- a/contrib/python/clickhouse-connect/clickhouse_connect/driver/httpclient.py +++ b/contrib/python/clickhouse-connect/clickhouse_connect/driver/httpclient.py @@ -22,7 +22,7 @@ from clickhouse_connect.driver.compression import available_compression from clickhouse_connect.driver.exceptions import DatabaseError, OperationalError, ProgrammingError from clickhouse_connect.driver.external import ExternalData from clickhouse_connect.driver.httputil import ResponseSource, get_pool_manager, get_response_data, \ - default_pool_manager, get_proxy_manager, all_managers, check_env_proxy, check_conn_reset + default_pool_manager, get_proxy_manager, all_managers, check_env_proxy, check_conn_expiration from clickhouse_connect.driver.insert import InsertContext from clickhouse_connect.driver.summary import QuerySummary from clickhouse_connect.driver.query import QueryResult, QueryContext, quote_identifier, bind_query @@ -68,7 +68,8 @@ class HttpClient(Client): http_proxy: Optional[str] = None, https_proxy: Optional[str] = None, server_host_name: Optional[str] = None, - apply_server_timezone: Optional[Union[str, bool]] = None): + apply_server_timezone: Optional[Union[str, bool]] = None, + show_clickhouse_errors: Optional[bool] = None): """ Create an HTTP ClickHouse Connect client See clickhouse_connect.get_client for parameters @@ -114,7 +115,7 @@ class HttpClient(Client): self._read_format = self._write_format = 'Native' self._transform = NativeTransform() - # There is use cases when client need to disable timeouts. + # There are use cases when the client needs to disable timeouts. if connect_timeout is not None: connect_timeout = coerce_int(connect_timeout) if send_receive_timeout is not None: @@ -147,7 +148,8 @@ class HttpClient(Client): query_limit=query_limit, query_retries=query_retries, server_host_name=server_host_name, - apply_server_timezone=apply_server_timezone) + apply_server_timezone=apply_server_timezone, + show_clickhouse_errors=show_clickhouse_errors) self.params = self._validate_settings(ch_settings) comp_setting = self._setting_status('enable_http_compression') self._send_comp_setting = not comp_setting.is_set and comp_setting.is_writable @@ -165,8 +167,7 @@ class HttpClient(Client): self.params[key] = str_value def get_client_setting(self, key) -> Optional[str]: - values = self.params.get(key) - return values[0] if values else None + return self.params.get(key) def _prep_query(self, context: QueryContext): final_query = super()._prep_query(context) @@ -357,8 +358,11 @@ class HttpClient(Client): response.close() if err_content: - err_msg = common.format_error(err_content.decode(errors='backslashreplace')) - err_str = f':{err_str}\n {err_msg}' + if self.show_clickhouse_errors: + err_msg = common.format_error(err_content.decode(errors='backslashreplace')) + err_str = f':{err_str}\n {err_msg}' + else: + err_str = 'The ClickHouse server returned an error.' raise OperationalError(err_str) if retried else DatabaseError(err_str) from None def _raw_request(self, @@ -399,7 +403,7 @@ class HttpClient(Client): kwargs['fields'] = fields else: kwargs['body'] = data - check_conn_reset(self.http) + check_conn_expiration(self.http) query_session = final_params.get('session_id') while True: attempts += 1 diff --git a/contrib/python/clickhouse-connect/clickhouse_connect/driver/httputil.py b/contrib/python/clickhouse-connect/clickhouse_connect/driver/httputil.py index 9bb8e26508a..9a2b835c658 100644 --- a/contrib/python/clickhouse-connect/clickhouse_connect/driver/httputil.py +++ b/contrib/python/clickhouse-connect/clickhouse_connect/driver/httputil.py @@ -20,7 +20,7 @@ from clickhouse_connect import common logger = logging.getLogger(__name__) -# We disable this warning. Verify must explicitly set to false, so we assume the user knows what they're doing +# We disable this warning. Verify must be explicitly set to false, so we assume the user knows what they're doing urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # Increase this number just to be safe when ClickHouse is returning progress headers @@ -118,13 +118,13 @@ def get_pool_manager(keep_interval: int = DEFAULT_KEEP_INTERVAL, return manager -def check_conn_reset(manager: PoolManager): +def check_conn_expiration(manager: PoolManager): reset_seconds = common.get_setting('max_connection_age') if reset_seconds: last_reset = all_managers.get(manager, 0) now = int(time.time()) if last_reset < now - reset_seconds: - logger.debug('connection reset') + logger.debug('connection expiration') manager.clear() all_managers[manager] = now diff --git a/contrib/python/clickhouse-connect/clickhouse_connect/driver/npquery.py b/contrib/python/clickhouse-connect/clickhouse_connect/driver/npquery.py index 64199e0b240..70fd455c349 100644 --- a/contrib/python/clickhouse-connect/clickhouse_connect/driver/npquery.py +++ b/contrib/python/clickhouse-connect/clickhouse_connect/driver/npquery.py @@ -101,7 +101,7 @@ class NumpyResult(Closable): chains = [chain(b) for b in zip(*bg)] new_df_series = [] for c in chains: - new_df_series.append(pd.concat([pd.Series(piece, copy=False) for piece in c], + new_df_series.append(pd.concat([pd.Series(piece, copy=False) for piece in c if len(piece) > 0], copy=False, ignore_index=True)) self._df_result = pd.DataFrame(dict(zip(self.column_names, new_df_series))) self.close() diff --git a/contrib/python/clickhouse-connect/ya.make b/contrib/python/clickhouse-connect/ya.make index 58d1ae9876f..562b734db02 100644 --- a/contrib/python/clickhouse-connect/ya.make +++ b/contrib/python/clickhouse-connect/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(0.7.8) +VERSION(0.7.9) LICENSE(Apache-2.0) |