From 59da90b2b046a2475fe6dce8dc5f9a4f4cb2ff06 Mon Sep 17 00:00:00 2001 From: junjun Date: Tue, 14 Oct 2025 14:05:21 +0800 Subject: [PATCH] feat: support starrocks datasource --- backend/apps/datasource/crud/datasource.py | 2 +- backend/apps/db/constant.py | 1 + backend/apps/db/db.py | 10 +++++----- backend/apps/db/db_sql.py | 6 +++--- frontend/src/assets/datasource/icon_starrocks.png | Bin 0 -> 974 bytes frontend/src/views/ds/js/ds-type.ts | 3 +++ 6 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 frontend/src/assets/datasource/icon_starrocks.png diff --git a/backend/apps/datasource/crud/datasource.py b/backend/apps/datasource/crud/datasource.py index de24251c..c2303776 100644 --- a/backend/apps/datasource/crud/datasource.py +++ b/backend/apps/datasource/crud/datasource.py @@ -290,7 +290,7 @@ def preview(session: SessionDep, current_user: CurrentUser, id: int, data: Table conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if ds.type != "excel" else get_engine_config() sql: str = "" - if ds.type == "mysql" or ds.type == "doris": + if ds.type == "mysql" or ds.type == "doris" or ds.type == "starrocks": sql = f"""SELECT `{"`, `".join(fields)}` FROM `{data.table.table_name}` {where} LIMIT 100""" diff --git a/backend/apps/db/constant.py b/backend/apps/db/constant.py index 28d1ad0b..3df5a14b 100644 --- a/backend/apps/db/constant.py +++ b/backend/apps/db/constant.py @@ -24,6 +24,7 @@ class DB(Enum): redshift = ('redshift', 'AWS Redshift', '"', '"', ConnectType.py_driver) es = ('es', 'Elasticsearch', '"', '"', ConnectType.py_driver) kingbase = ('kingbase', 'Kingbase', '"', '"', ConnectType.py_driver) + starrocks = ('starrocks', 'StarRocks', '"', '"', ConnectType.py_driver) def __init__(self, type, db_name, prefix, suffix, connect_type: ConnectType): self.type = type diff --git a/backend/apps/db/db.py b/backend/apps/db/db.py index c428a576..8aaebeaa 100644 --- a/backend/apps/db/db.py +++ b/backend/apps/db/db.py @@ -164,7 +164,7 @@ def check_connection(trans: Optional[Trans], ds: CoreDatasource | AssistantOutDs if is_raise: raise HTTPException(status_code=500, detail=trans('i18n_ds_invalid') + f': {e.args}') return False - elif ds.type == 'doris': + elif ds.type == 'doris' or ds.type == "starrocks": with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host, port=conf.port, db=conf.database, connect_timeout=10, read_timeout=10, **extra_config_dict) as conn, conn.cursor() as cursor: @@ -259,7 +259,7 @@ def get_version(ds: CoreDatasource | AssistantOutDsSchema): cursor.execute(sql, timeout=10, **extra_config_dict) res = cursor.fetchall() version = res[0][0] - elif ds.type == 'doris': + elif ds.type == 'doris' or ds.type == "starrocks": with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host, port=conf.port, db=conf.database, connect_timeout=10, read_timeout=10, **extra_config_dict) as conn, conn.cursor() as cursor: @@ -337,7 +337,7 @@ def get_tables(ds: CoreDatasource): res = cursor.fetchall() res_list = [TableSchema(*item) for item in res] return res_list - elif ds.type == 'doris': + elif ds.type == 'doris' or ds.type == "starrocks": with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host, port=conf.port, db=conf.database, connect_timeout=conf.timeout, read_timeout=conf.timeout, **extra_config_dict) as conn, conn.cursor() as cursor: @@ -387,7 +387,7 @@ def get_fields(ds: CoreDatasource, table_name: str = None): res = cursor.fetchall() res_list = [ColumnSchema(*item) for item in res] return res_list - elif ds.type == 'doris': + elif ds.type == 'doris' or ds.type == "starrocks": with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host, port=conf.port, db=conf.database, connect_timeout=conf.timeout, read_timeout=conf.timeout, **extra_config_dict) as conn, conn.cursor() as cursor: @@ -459,7 +459,7 @@ def exec_sql(ds: CoreDatasource | AssistantOutDsSchema, sql: str, origin_column= "sql": bytes.decode(base64.b64encode(bytes(sql, 'utf-8')))} except Exception as ex: raise ParseSQLResultError(str(ex)) - elif ds.type == 'doris': + elif ds.type == 'doris' or ds.type == "starrocks": with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host, port=conf.port, db=conf.database, connect_timeout=conf.timeout, read_timeout=conf.timeout, **extra_config_dict) as conn, conn.cursor() as cursor: diff --git a/backend/apps/db/db_sql.py b/backend/apps/db/db_sql.py index b8fda58f..46745bca 100644 --- a/backend/apps/db/db_sql.py +++ b/backend/apps/db/db_sql.py @@ -4,7 +4,7 @@ def get_version_sql(ds: CoreDatasource, conf: DatasourceConf): - if ds.type == "mysql" or ds.type == "doris": + if ds.type == "mysql" or ds.type == "doris" or ds.type == "starrocks": return """ SELECT VERSION() """ @@ -134,7 +134,7 @@ def get_table_sql(ds: CoreDatasource, conf: DatasourceConf, db_version: str = '' relkind in ('r','p', 'f') AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = %s) """, conf.dbSchema - elif ds.type == "doris": + elif ds.type == "doris" or ds.type == "starrocks": return """ SELECT TABLE_NAME, @@ -281,7 +281,7 @@ def get_field_sql(ds: CoreDatasource, conf: DatasourceConf, table_name: str = No """ sql2 = " AND c.TABLE_NAME = :param2" if table_name is not None and table_name != "" else "" return sql1 + sql2, conf.dbSchema, table_name - elif ds.type == "doris": + elif ds.type == "doris" or ds.type == "starrocks": sql1 = """ SELECT COLUMN_NAME, diff --git a/frontend/src/assets/datasource/icon_starrocks.png b/frontend/src/assets/datasource/icon_starrocks.png new file mode 100644 index 0000000000000000000000000000000000000000..5983fd08ebcf6fb146bba3ba747f28c68e7b0462 GIT binary patch literal 974 zcmV;<12O!GP)6$^BPr#z1?l)ZqRl1?Ce5mXLJEx$dK10AI>cA2AIjGHL?GLQoV zP~P^0k^2`Zta05yRtGvx(4S(j5js&et>g~y1bSU}|?JGi(l)Vof_`UIG7kBTZU+g{?E&EarPQXpPrKQR$27^oj>J*y(; z5p)T$Faw+pIFvg(IJ0m?<3^96`gGb!lxK?W`Hv+9>_prK&HLq_;_jW1uAkz5;M78? zz$K$pJGFcuFY@OCM^#7fc94c;tcoLQB?T5G>>1x_-X7^L{dMl~7T{czs}umx@=JFs2dmt^ovE4K z_T(7Ihk(BZ0RT#jG2d-He6k7GP1d@uYoeVkC&AhcdVehf00D(?g?Zp^=(wyi40meLWc7)Rs` zU>4T}0Q`XCV-lIqF47to^i3+!O7we~^i1hzQzFdeZ%qh8F4ZH3fqztw)*LCttVZA{Qf_!T!pBeNR z!fRxH6BfrE%c8?ir?Xy9^hDcanx~bJ z&mZd9WGw4A$Xl8|cYI(lXj$!}Zu6bxII=$4s7giXRIO#q2~{fRQP+UBXsBfvk+fO$ wa02tO`TcNC(K>INSeDK*`NIv@jjsmxFFib6Zh>c#@Bjb+07*qoM6N<$f}Qft%>V!Z literal 0 HcmV?d00001 diff --git a/frontend/src/views/ds/js/ds-type.ts b/frontend/src/views/ds/js/ds-type.ts index f99a03a4..800fdefd 100644 --- a/frontend/src/views/ds/js/ds-type.ts +++ b/frontend/src/views/ds/js/ds-type.ts @@ -9,6 +9,7 @@ import doris from '@/assets/datasource/icon_doris.png' import redshift from '@/assets/datasource/icon_redshift.png' import es from '@/assets/datasource/icon_es.png' import kingbase from '@/assets/datasource/icon_kingbase.png' +import starrocks from '@/assets/datasource/icon_starrocks.png' import { i18n } from '@/i18n' const t = i18n.global.t @@ -24,6 +25,7 @@ export const dsType = [ { label: 'AWS Redshift', value: 'redshift' }, { label: 'Elasticsearch', value: 'es' }, { label: 'Kingbase', value: 'kingbase' }, + { label: 'StarRocks', value: 'starrocks' }, ] export const dsTypeWithImg = [ @@ -38,6 +40,7 @@ export const dsTypeWithImg = [ { name: 'AWS Redshift', type: 'redshift', img: redshift }, { name: 'Elasticsearch', type: 'es', img: es }, { name: 'Kingbase', type: 'kingbase', img: kingbase }, + { name: 'StarRocks', type: 'starrocks', img: starrocks }, ] export const haveSchema = ['sqlServer', 'pg', 'oracle', 'dm', 'redshift', 'kingbase']