Skip to content

Commit

Permalink
refactor(clickhouse): clean up session timezone handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Dec 18, 2023
1 parent 94ae16f commit 66220c7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ibis/backends/clickhouse/__init__.py
Expand Up @@ -3,7 +3,6 @@
import ast
import atexit
import glob
import warnings
from contextlib import closing, suppress
from functools import partial
from typing import TYPE_CHECKING, Any, Literal
Expand Down Expand Up @@ -123,6 +122,7 @@ def do_connect(
client_name: str = "ibis",
secure: bool | None = None,
compression: str | bool = True,
settings: Mapping[str, Any] | None = None,
**kwargs: Any,
):
"""Create a ClickHouse client for use with Ibis.
Expand All @@ -148,6 +148,8 @@ def do_connect(
The kind of compression to use for requests. See
https://clickhouse.com/docs/en/integrations/python#compression for
more information.
settings
ClickHouse session settings
kwargs
Client specific keyword arguments
Expand All @@ -158,6 +160,10 @@ def do_connect(
>>> client
<ibis.clickhouse.client.ClickhouseClient object at 0x...>
"""
if settings is None:
settings = {}
settings.setdefault("session_timezone", "UTC")

self.con = cc.get_client(
host=host,
# 8123 is the default http port 443 is https
Expand All @@ -170,11 +176,6 @@ def do_connect(
compress=compression,
**kwargs,
)
try:
with closing(self.raw_sql("SET session_timezone = 'UTC'")):
pass
except Exception as e: # noqa: BLE001
warnings.warn(f"Could not set timezone to UTC: {e}", category=UserWarning)
self._temp_views = set()

@property
Expand Down

0 comments on commit 66220c7

Please sign in to comment.