Skip to content

Commit 6e24ea9

Browse files
committed
fix(datasource): fix ClickHouse datasource get tables error
1 parent ce96e06 commit 6e24ea9

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

backend/apps/db/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def get_schema(ds: CoreDatasource):
254254
def get_tables(ds: CoreDatasource):
255255
conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if ds.type != "excel" else get_engine_config()
256256
db = DB.get_db(ds.type)
257-
sql = get_table_sql(ds, conf)
257+
sql = get_table_sql(ds, conf, get_version(ds))
258258
if db.connect_type == ConnectType.sqlalchemy:
259259
with get_session(ds) as session:
260260
with session.execute(text(sql)) as result:

backend/apps/db/db_sql.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_version_sql(ds: CoreDatasource, conf: DatasourceConf):
3232
return ''
3333

3434

35-
def get_table_sql(ds: CoreDatasource, conf: DatasourceConf):
35+
def get_table_sql(ds: CoreDatasource, conf: DatasourceConf, db_version: str = ''):
3636
if ds.type == "mysql" or ds.type == "doris":
3737
return f"""
3838
SELECT
@@ -95,13 +95,23 @@ def get_table_sql(ds: CoreDatasource, conf: DatasourceConf):
9595
ORDER BY t.TABLE_NAME
9696
"""
9797
elif ds.type == "ck":
98-
return f"""
99-
SELECT name, comment
100-
FROM system.tables
101-
WHERE database = '{conf.database}'
102-
AND engine NOT IN ('Dictionary')
103-
ORDER BY name
104-
"""
98+
version = int(db_version.split('.')[0])
99+
if version < 22:
100+
return f"""
101+
SELECT name, null as comment
102+
FROM system.tables
103+
WHERE database = '{conf.database}'
104+
AND engine NOT IN ('Dictionary')
105+
ORDER BY name
106+
"""
107+
else:
108+
return f"""
109+
SELECT name, comment
110+
FROM system.tables
111+
WHERE database = '{conf.database}'
112+
AND engine NOT IN ('Dictionary')
113+
ORDER BY name
114+
"""
105115
elif ds.type == 'dm':
106116
return f"""
107117
select table_name, comments

0 commit comments

Comments
 (0)