From 5b9ed06b29d023751da54451e1e28027bd1a5d52 Mon Sep 17 00:00:00 2001 From: Geoff Genz Date: Thu, 16 Nov 2023 10:33:47 -0700 Subject: [PATCH] Fix native column query --- dbt/adapters/clickhouse/nativeclient.py | 2 +- .../{contract_fixtures.py => constraint_fixtures.py} | 0 .../integration/adapter/constraints/test_constraints.py | 2 +- tests/integration/conftest.py | 9 ++++++--- 4 files changed, 8 insertions(+), 5 deletions(-) rename tests/integration/adapter/constraints/{contract_fixtures.py => constraint_fixtures.py} (100%) diff --git a/dbt/adapters/clickhouse/nativeclient.py b/dbt/adapters/clickhouse/nativeclient.py index da53db81..6fbff418 100644 --- a/dbt/adapters/clickhouse/nativeclient.py +++ b/dbt/adapters/clickhouse/nativeclient.py @@ -35,7 +35,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) - return [ClickHouseColumn.create(column.name, column.type) for column in columns] + 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 diff --git a/tests/integration/adapter/constraints/contract_fixtures.py b/tests/integration/adapter/constraints/constraint_fixtures.py similarity index 100% rename from tests/integration/adapter/constraints/contract_fixtures.py rename to tests/integration/adapter/constraints/constraint_fixtures.py diff --git a/tests/integration/adapter/constraints/test_constraints.py b/tests/integration/adapter/constraints/test_constraints.py index e1ad2f6c..d9781ac7 100644 --- a/tests/integration/adapter/constraints/test_constraints.py +++ b/tests/integration/adapter/constraints/test_constraints.py @@ -1,7 +1,7 @@ import pytest from dbt.tests.util import get_manifest, run_dbt, run_dbt_and_capture -from tests.integration.adapter.constraints.contract_fixtures import ( +from tests.integration.adapter.constraints.constraint_fixtures import ( model_schema_yml, my_model_wrong_name_sql, my_model_wrong_order_sql, diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index a656eed7..50b1af6a 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -32,7 +32,10 @@ def test_config(ch_test_users, ch_test_version): compose_file = f'{Path(__file__).parent}/docker-compose.yml' test_host = os.environ.get('DBT_CH_TEST_HOST', 'localhost') test_port = int(os.environ.get('DBT_CH_TEST_PORT', 8123)) - test_driver = 'native' if test_port in (10900, 9000, 9440) else 'http' + client_port = int(os.environ.get('DBT_CH_TEST_CLIENT_PORT', 0)) + test_driver = os.environ.get('DBT_CH_TEST_DRIVER', '').lower() + if test_driver == '': + test_driver = 'native' if test_port in (10900, 9000, 9440) else 'http' test_user = os.environ.get('DBT_CH_TEST_USER', 'default') test_password = os.environ.get('DBT_CH_TEST_PASSWORD', '') test_cluster = os.environ.get('DBT_CH_TEST_CLUSTER', '') @@ -49,7 +52,7 @@ def test_config(ch_test_users, ch_test_version): docker = os.environ.get('DBT_CH_TEST_USE_DOCKER', '').lower() in ('1', 'true', 'yes') if docker: - client_port = 10723 + client_port = client_port or 10723 test_port = 10900 if test_driver == 'native' else client_port try: run_cmd(['docker-compose', '-f', compose_file, 'down', '-v']) @@ -62,7 +65,7 @@ def test_config(ch_test_users, ch_test_version): wait_until_responsive(timeout=30.0, pause=0.5, check=lambda: is_responsive(url)) except Exception as e: raise Exception('Failed to run docker-compose: {}', str(e)) - else: + elif not client_port: if test_driver == 'native': client_port = 8443 if test_port == 9440 else 8123 else: