Skip to content

Commit 6ae32a8

Browse files
committed
feat: support starrocks datasource
1 parent 855afd5 commit 6ae32a8

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

backend/apps/datasource/crud/datasource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def preview(session: SessionDep, current_user: CurrentUser, id: int, data: Table
290290

291291
conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if ds.type != "excel" else get_engine_config()
292292
sql: str = ""
293-
if ds.type == "mysql" or ds.type == "doris":
293+
if ds.type == "mysql" or ds.type == "doris" or ds.type == "starrocks":
294294
sql = f"""SELECT `{"`, `".join(fields)}` FROM `{data.table.table_name}`
295295
{where}
296296
LIMIT 100"""

backend/apps/db/constant.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class DB(Enum):
2424
redshift = ('redshift', 'AWS Redshift', '"', '"', ConnectType.py_driver)
2525
es = ('es', 'Elasticsearch', '"', '"', ConnectType.py_driver)
2626
kingbase = ('kingbase', 'Kingbase', '"', '"', ConnectType.py_driver)
27+
starrocks = ('starrocks', 'StarRocks', '"', '"', ConnectType.py_driver)
2728

2829
def __init__(self, type, db_name, prefix, suffix, connect_type: ConnectType):
2930
self.type = type

backend/apps/db/db.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def check_connection(trans: Optional[Trans], ds: CoreDatasource | AssistantOutDs
164164
if is_raise:
165165
raise HTTPException(status_code=500, detail=trans('i18n_ds_invalid') + f': {e.args}')
166166
return False
167-
elif ds.type == 'doris':
167+
elif ds.type == 'doris' or ds.type == "starrocks":
168168
with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host,
169169
port=conf.port, db=conf.database, connect_timeout=10,
170170
read_timeout=10, **extra_config_dict) as conn, conn.cursor() as cursor:
@@ -259,7 +259,7 @@ def get_version(ds: CoreDatasource | AssistantOutDsSchema):
259259
cursor.execute(sql, timeout=10, **extra_config_dict)
260260
res = cursor.fetchall()
261261
version = res[0][0]
262-
elif ds.type == 'doris':
262+
elif ds.type == 'doris' or ds.type == "starrocks":
263263
with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host,
264264
port=conf.port, db=conf.database, connect_timeout=10,
265265
read_timeout=10, **extra_config_dict) as conn, conn.cursor() as cursor:
@@ -337,7 +337,7 @@ def get_tables(ds: CoreDatasource):
337337
res = cursor.fetchall()
338338
res_list = [TableSchema(*item) for item in res]
339339
return res_list
340-
elif ds.type == 'doris':
340+
elif ds.type == 'doris' or ds.type == "starrocks":
341341
with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host,
342342
port=conf.port, db=conf.database, connect_timeout=conf.timeout,
343343
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):
387387
res = cursor.fetchall()
388388
res_list = [ColumnSchema(*item) for item in res]
389389
return res_list
390-
elif ds.type == 'doris':
390+
elif ds.type == 'doris' or ds.type == "starrocks":
391391
with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host,
392392
port=conf.port, db=conf.database, connect_timeout=conf.timeout,
393393
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=
459459
"sql": bytes.decode(base64.b64encode(bytes(sql, 'utf-8')))}
460460
except Exception as ex:
461461
raise ParseSQLResultError(str(ex))
462-
elif ds.type == 'doris':
462+
elif ds.type == 'doris' or ds.type == "starrocks":
463463
with pymysql.connect(user=conf.username, passwd=conf.password, host=conf.host,
464464
port=conf.port, db=conf.database, connect_timeout=conf.timeout,
465465
read_timeout=conf.timeout, **extra_config_dict) as conn, conn.cursor() as cursor:

backend/apps/db/db_sql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def get_version_sql(ds: CoreDatasource, conf: DatasourceConf):
7-
if ds.type == "mysql" or ds.type == "doris":
7+
if ds.type == "mysql" or ds.type == "doris" or ds.type == "starrocks":
88
return """
99
SELECT VERSION()
1010
"""
@@ -134,7 +134,7 @@ def get_table_sql(ds: CoreDatasource, conf: DatasourceConf, db_version: str = ''
134134
relkind in ('r','p', 'f')
135135
AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = %s)
136136
""", conf.dbSchema
137-
elif ds.type == "doris":
137+
elif ds.type == "doris" or ds.type == "starrocks":
138138
return """
139139
SELECT
140140
TABLE_NAME,
@@ -281,7 +281,7 @@ def get_field_sql(ds: CoreDatasource, conf: DatasourceConf, table_name: str = No
281281
"""
282282
sql2 = " AND c.TABLE_NAME = :param2" if table_name is not None and table_name != "" else ""
283283
return sql1 + sql2, conf.dbSchema, table_name
284-
elif ds.type == "doris":
284+
elif ds.type == "doris" or ds.type == "starrocks":
285285
sql1 = """
286286
SELECT
287287
COLUMN_NAME,
974 Bytes
Loading

frontend/src/views/ds/js/ds-type.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import doris from '@/assets/datasource/icon_doris.png'
99
import redshift from '@/assets/datasource/icon_redshift.png'
1010
import es from '@/assets/datasource/icon_es.png'
1111
import kingbase from '@/assets/datasource/icon_kingbase.png'
12+
import starrocks from '@/assets/datasource/icon_starrocks.png'
1213
import { i18n } from '@/i18n'
1314

1415
const t = i18n.global.t
@@ -24,6 +25,7 @@ export const dsType = [
2425
{ label: 'AWS Redshift', value: 'redshift' },
2526
{ label: 'Elasticsearch', value: 'es' },
2627
{ label: 'Kingbase', value: 'kingbase' },
28+
{ label: 'StarRocks', value: 'starrocks' },
2729
]
2830

2931
export const dsTypeWithImg = [
@@ -38,6 +40,7 @@ export const dsTypeWithImg = [
3840
{ name: 'AWS Redshift', type: 'redshift', img: redshift },
3941
{ name: 'Elasticsearch', type: 'es', img: es },
4042
{ name: 'Kingbase', type: 'kingbase', img: kingbase },
43+
{ name: 'StarRocks', type: 'starrocks', img: starrocks },
4144
]
4245

4346
export const haveSchema = ['sqlServer', 'pg', 'oracle', 'dm', 'redshift', 'kingbase']

0 commit comments

Comments
 (0)