Skip to content

Commit

Permalink
Add tcp_keepalive to credentials and native connections
Browse files Browse the repository at this point in the history
  • Loading branch information
rjoelnorgren committed Jun 21, 2024
1 parent f1641fe commit 7e29053
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ your_profile_name:
check_exchange: [True] # Validate that clickhouse support the atomic EXCHANGE TABLES command. (Not needed for most ClickHouse versions)
local_suffix [_local] # Table suffix of local tables on shards for distributed materializations.
allow_automatic_deduplication [False] # Enable ClickHouse automatic deduplication for Replicated tables
tcp_keepalive [False]: # Native client only, specify TCP keepalive configuration. Specify custom keepalive settings as [idle_time_sec, interval_sec, probes].
custom_settings: [{}] # A dictionary/mapping of custom ClickHouse settings for the connection - default is empty.
# Native (clickhouse-driver) connection settings
Expand Down
6 changes: 6 additions & 0 deletions dbt/adapters/clickhouse/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ClickHouseCredentials(Credentials):
use_lw_deletes: bool = False
local_suffix: str = 'local'
allow_automatic_deduplication: bool = False
tcp_keepalive: Optional[bool | tuple[int, int, int]] = False

@property
def type(self):
Expand All @@ -54,6 +55,10 @@ def __post_init__(self):
)
self.database = ''

# clickhouse_driver expects tcp_keepalive to be a tuple if it's not a boolean
if isinstance(self.tcp_keepalive, list):
self.tcp_keepalive = tuple(self.tcp_keepalive)

def _connection_keys(self):
return (
'driver',
Expand All @@ -75,4 +80,5 @@ def _connection_keys(self):
'custom_settings',
'use_lw_deletes',
'allow_automatic_deduplication',
'tcp_keepalive',
)
1 change: 1 addition & 0 deletions dbt/adapters/clickhouse/nativeclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def _create_client(self, credentials: ClickHouseCredentials):
sync_request_timeout=credentials.sync_request_timeout,
compress_block_size=credentials.compress_block_size,
compression=False if credentials.compression == '' else credentials.compression,
tcp_keepalive=credentials.tcp_keepalive,
settings=self._conn_settings,
)
try:
Expand Down

0 comments on commit 7e29053

Please sign in to comment.