From 30580d2515b36947cb4af2a36733f118325d5d70 Mon Sep 17 00:00:00 2001 From: ptemarvelde <45282601+ptemarvelde@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:52:31 +0100 Subject: [PATCH] Wrap columns_in_query query in select statement (#222) * Wrap columns_in_query query in select statement * 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 161d1256..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'{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..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'{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