From 99de43082d03e59fe98029eba2f72311bb92b597 Mon Sep 17 00:00:00 2001 From: ptemarvelde <45282601+ptemarvelde@users.noreply.github.com> Date: Wed, 13 Dec 2023 11:26:04 +0100 Subject: [PATCH 1/2] Wrap columns_in_query query in select statement --- dbt/adapters/clickhouse/httpclient.py | 2 +- dbt/adapters/clickhouse/nativeclient.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt/adapters/clickhouse/httpclient.py b/dbt/adapters/clickhouse/httpclient.py index 161d1256..68704dc5 100644 --- a/dbt/adapters/clickhouse/httpclient.py +++ b/dbt/adapters/clickhouse/httpclient.py @@ -25,7 +25,7 @@ def command(self, sql, **kwargs): def columns_in_query(self, sql: str, **kwargs) -> List[ClickHouseColumn]: try: - query_result = self._client.query(f'{sql} LIMIT 0', **kwargs) + query_result = self._client.query(f'SELECT * FROM ({sql}) LIMIT 0', **kwargs) return [ ClickHouseColumn.create(name, ch_type.name) for name, ch_type in zip(query_result.column_names, query_result.column_types) diff --git a/dbt/adapters/clickhouse/nativeclient.py b/dbt/adapters/clickhouse/nativeclient.py index d7532ef5..b2d264be 100644 --- a/dbt/adapters/clickhouse/nativeclient.py +++ b/dbt/adapters/clickhouse/nativeclient.py @@ -34,7 +34,7 @@ def command(self, sql, **kwargs): def columns_in_query(self, sql: str, **kwargs) -> List[ClickHouseColumn]: try: - _, columns = self._client.execute(f'{sql} LIMIT 0', with_column_types=True) + _, columns = self._client.execute(f'SELECT * FROM ({sql}) LIMIT 0', with_column_types=True) return [ClickHouseColumn.create(column[0], column[1]) for column in columns] except clickhouse_driver.errors.Error as ex: raise DbtDatabaseError(str(ex).strip()) from ex From 3c0e3ab3bedba00fc209895b736b46061b8105b0 Mon Sep 17 00:00:00 2001 From: ptemarvelde <45282601+ptemarvelde@users.noreply.github.com> Date: Wed, 13 Dec 2023 11:44:07 +0100 Subject: [PATCH 2/2] formatting --- dbt/adapters/clickhouse/httpclient.py | 2 +- dbt/adapters/clickhouse/nativeclient.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dbt/adapters/clickhouse/httpclient.py b/dbt/adapters/clickhouse/httpclient.py index 68704dc5..17795e44 100644 --- a/dbt/adapters/clickhouse/httpclient.py +++ b/dbt/adapters/clickhouse/httpclient.py @@ -25,7 +25,7 @@ def command(self, sql, **kwargs): def columns_in_query(self, sql: str, **kwargs) -> List[ClickHouseColumn]: try: - query_result = self._client.query(f'SELECT * FROM ({sql}) LIMIT 0', **kwargs) + query_result = self._client.query(f"SELECT * FROM ({sql}) LIMIT 0", **kwargs) return [ ClickHouseColumn.create(name, ch_type.name) for name, ch_type in zip(query_result.column_names, query_result.column_types) diff --git a/dbt/adapters/clickhouse/nativeclient.py b/dbt/adapters/clickhouse/nativeclient.py index b2d264be..aaec97f9 100644 --- a/dbt/adapters/clickhouse/nativeclient.py +++ b/dbt/adapters/clickhouse/nativeclient.py @@ -34,7 +34,9 @@ def command(self, sql, **kwargs): def columns_in_query(self, sql: str, **kwargs) -> List[ClickHouseColumn]: try: - _, columns = self._client.execute(f'SELECT * FROM ({sql}) LIMIT 0', with_column_types=True) + _, columns = self._client.execute( + f"SELECT * FROM ({sql}) LIMIT 0", with_column_types=True + ) return [ClickHouseColumn.create(column[0], column[1]) for column in columns] except clickhouse_driver.errors.Error as ex: raise DbtDatabaseError(str(ex).strip()) from ex