diff --git a/Dockerfile.superset b/Dockerfile.superset index ada0f89..e8608b3 100644 --- a/Dockerfile.superset +++ b/Dockerfile.superset @@ -8,4 +8,4 @@ RUN apt-get update && \ USER superset -RUN pip install clickhouse-connect==0.8.* psycopg2-binary==2.9.* +RUN pip install clickhouse-connect==0.8.* clickhouse-sqlalchemy==0.3.* psycopg2-binary==2.9.* diff --git a/superset/init_superset.py b/superset/init_superset.py index d4eb1c3..e3946cc 100644 --- a/superset/init_superset.py +++ b/superset/init_superset.py @@ -54,7 +54,7 @@ def build_clickhouse_uri() -> str: host = CLICKHOUSE_HOST port = CLICKHOUSE_PORT database = quote_plus(CLICKHOUSE_DATABASE) - return f"clickhousedb://{user}:{password}@{host}:{port}/{database}" + return f"clickhouse+connect://{user}:{password}@{host}:{port}/{database}" def run_superset_cli(args): @@ -139,6 +139,7 @@ def import_datasets(): # Создаем Python скрипт для выполнения внутри superset shell script_lines = [ + "import clickhouse_connect # Регистрирует диалект clickhouse+connect", "from superset.extensions import db", "from superset.models.core import Database", "from superset.connectors.sqla.models import SqlaTable", @@ -169,18 +170,7 @@ def import_datasets(): ").first()" ), "if existing:", - " try:", - " if not existing.columns:", - " existing.fetch_metadata()", - " db.session.commit()", - f" print('Refreshed dataset metadata: {table_name}')", - " refreshed += 1", - " else:", - f" print('Dataset {table_name} already exists')", - " except Exception as e:", - f" print(f'ERROR: failed to refresh {table_name}: {{e}}')", - " db.session.rollback()", - " errors += 1", + f" print('Dataset {table_name} already exists')", "else:", " try:", ( @@ -193,10 +183,8 @@ def import_datasets(): ")" ), " db.session.add(dataset)", - " db.session.flush()", - " dataset.fetch_metadata()", " db.session.commit()", - f" print('Created dataset: {table_name}')", + f" print('Created dataset: {table_name} (metadata will be fetched on first use)')", " imported += 1", " except Exception as e:", f" print(f'ERROR: failed to create {table_name}: {{e}}')",