fix(superset): исправлена инициализация датасетов
- Добавлен clickhouse-sqlalchemy в Dockerfile для поддержки диалекта - Изменен URI с clickhousedb:// на clickhouse+connect:// - Убран вызов fetch_metadata() в init_superset.py (вызывал ошибку диалекта) - Датасеты создаются без предварительного fetch_metadata Тестирование: - Чистый запуск: ✅ - Перезапуск: ✅ - API: ✅
This commit is contained in:
+1
-1
@@ -8,4 +8,4 @@ RUN apt-get update && \
|
|||||||
|
|
||||||
USER superset
|
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.*
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ def build_clickhouse_uri() -> str:
|
|||||||
host = CLICKHOUSE_HOST
|
host = CLICKHOUSE_HOST
|
||||||
port = CLICKHOUSE_PORT
|
port = CLICKHOUSE_PORT
|
||||||
database = quote_plus(CLICKHOUSE_DATABASE)
|
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):
|
def run_superset_cli(args):
|
||||||
@@ -139,6 +139,7 @@ def import_datasets():
|
|||||||
|
|
||||||
# Создаем Python скрипт для выполнения внутри superset shell
|
# Создаем Python скрипт для выполнения внутри superset shell
|
||||||
script_lines = [
|
script_lines = [
|
||||||
|
"import clickhouse_connect # Регистрирует диалект clickhouse+connect",
|
||||||
"from superset.extensions import db",
|
"from superset.extensions import db",
|
||||||
"from superset.models.core import Database",
|
"from superset.models.core import Database",
|
||||||
"from superset.connectors.sqla.models import SqlaTable",
|
"from superset.connectors.sqla.models import SqlaTable",
|
||||||
@@ -169,18 +170,7 @@ def import_datasets():
|
|||||||
").first()"
|
").first()"
|
||||||
),
|
),
|
||||||
"if existing:",
|
"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')",
|
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",
|
|
||||||
"else:",
|
"else:",
|
||||||
" try:",
|
" try:",
|
||||||
(
|
(
|
||||||
@@ -193,10 +183,8 @@ def import_datasets():
|
|||||||
")"
|
")"
|
||||||
),
|
),
|
||||||
" db.session.add(dataset)",
|
" db.session.add(dataset)",
|
||||||
" db.session.flush()",
|
|
||||||
" dataset.fetch_metadata()",
|
|
||||||
" db.session.commit()",
|
" db.session.commit()",
|
||||||
f" print('Created dataset: {table_name}')",
|
f" print('Created dataset: {table_name} (metadata will be fetched on first use)')",
|
||||||
" imported += 1",
|
" imported += 1",
|
||||||
" except Exception as e:",
|
" except Exception as e:",
|
||||||
f" print(f'ERROR: failed to create {table_name}: {{e}}')",
|
f" print(f'ERROR: failed to create {table_name}: {{e}}')",
|
||||||
|
|||||||
Reference in New Issue
Block a user