fix(datasource): fix ClickHouse datasource get tables error

This commit is contained in:
junjun
2025-09-11 17:48:26 +08:00
parent ce96e06f77
commit 6e24ea91f9
2 changed files with 19 additions and 9 deletions
+1 -1
View File
@@ -254,7 +254,7 @@ def get_schema(ds: CoreDatasource):
def get_tables(ds: CoreDatasource):
conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if ds.type != "excel" else get_engine_config()
db = DB.get_db(ds.type)
sql = get_table_sql(ds, conf)
sql = get_table_sql(ds, conf, get_version(ds))
if db.connect_type == ConnectType.sqlalchemy:
with get_session(ds) as session:
with session.execute(text(sql)) as result:
+18 -8
View File
@@ -32,7 +32,7 @@ def get_version_sql(ds: CoreDatasource, conf: DatasourceConf):
return ''
def get_table_sql(ds: CoreDatasource, conf: DatasourceConf):
def get_table_sql(ds: CoreDatasource, conf: DatasourceConf, db_version: str = ''):
if ds.type == "mysql" or ds.type == "doris":
return f"""
SELECT
@@ -95,13 +95,23 @@ def get_table_sql(ds: CoreDatasource, conf: DatasourceConf):
ORDER BY t.TABLE_NAME
"""
elif ds.type == "ck":
return f"""
SELECT name, comment
FROM system.tables
WHERE database = '{conf.database}'
AND engine NOT IN ('Dictionary')
ORDER BY name
"""
version = int(db_version.split('.')[0])
if version < 22:
return f"""
SELECT name, null as comment
FROM system.tables
WHERE database = '{conf.database}'
AND engine NOT IN ('Dictionary')
ORDER BY name
"""
else:
return f"""
SELECT name, comment
FROM system.tables
WHERE database = '{conf.database}'
AND engine NOT IN ('Dictionary')
ORDER BY name
"""
elif ds.type == 'dm':
return f"""
select table_name, comments