Skip to content

Commit 2f34808

Browse files
mengnankkkkVLSMB
andauthored
fix: add hive support (#439)
* fix: add hive support * fix: fix ping * fix: ci * fix: ci * fix --------- Co-authored-by: VLSMB <36068250+VLSMB@users.noreply.github.com>
1 parent c9a1740 commit 2f34808

File tree

15 files changed

+725
-23
lines changed

15 files changed

+725
-23
lines changed

data-agent-frontend/src/components/agent/DataSourceConfig.vue

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,18 @@
259259
<el-col :span="12">
260260
<div class="form-item">
261261
<label>数据源类型 *</label>
262-
<!-- todo: 改为后端动态获取-->
263262
<el-select
264263
v-model="newDatasource.type"
265264
placeholder="请选择数据源类型"
266265
style="width: 100%"
267266
size="large"
268267
>
269-
<el-option key="mysql" label="MySQL" value="mysql" />
270-
<el-option key="postgresql" label="PostgreSQL" value="postgresql" />
271-
<el-option key="sqlserver" label="SQL Server" value="sqlserver" />
272-
<el-option key="dameng" label="达梦(Dameng)" value="dameng" />
273-
<el-option key="oracle" label="Oracle" value="oracle" />
268+
<el-option
269+
v-for="type in datasourceTypes"
270+
:key="type.typeName"
271+
:label="type.displayName"
272+
:value="type.typeName"
273+
/>
274274
</el-select>
275275
</div>
276276
</el-col>
@@ -402,9 +402,12 @@
402402
style="width: 100%"
403403
size="large"
404404
>
405-
<el-option key="mysql" label="MySQL" value="mysql" />
406-
<el-option key="postgresql" label="PostgreSQL" value="postgresql" />
407-
<el-option key="dameng" label="达梦(Dameng)" value="dameng" />
405+
<el-option
406+
v-for="type in datasourceTypes"
407+
:key="type.typeName"
408+
:label="type.displayName"
409+
:value="type.typeName"
410+
/>
408411
</el-select>
409412
</div>
410413
</el-col>
@@ -804,7 +807,7 @@
804807
Edit,
805808
} from '@element-plus/icons-vue';
806809
import datasourceService from '@/services/datasource';
807-
import { Datasource, AgentDatasource } from '@/services/datasource';
810+
import { Datasource, AgentDatasource, DatasourceType } from '@/services/datasource';
808811
import { ApiResponse } from '@/services/common';
809812
import { ElMessage, ElMessageBox } from 'element-plus';
810813
import agentDatasourceService from '@/services/agentDatasource';
@@ -860,14 +863,24 @@
860863
const targetColumnList: Ref<string[]> = ref([]);
861864
const savingForeignKeys: Ref<boolean> = ref(false);
862865
866+
// 数据源类型列表
867+
const datasourceTypes: Ref<DatasourceType[]> = ref([]);
868+
863869
watch(dialogVisible, newValue => {
864870
if (newValue) {
865871
loadAllDatasource();
872+
loadDatasourceTypes();
866873
newDatasource.value = { port: 3306 } as Datasource;
867874
schemaName.value = '';
868875
}
869876
});
870877
878+
watch(editDialogVisible, newValue => {
879+
if (newValue) {
880+
loadDatasourceTypes();
881+
}
882+
});
883+
871884
// 初始化Agent数据源列表
872885
const loadAgentDatasource = async () => {
873886
selectedDatasourceId.value = null;
@@ -910,6 +923,19 @@
910923
}
911924
};
912925
926+
// 加载数据源类型列表
927+
const loadDatasourceTypes = async () => {
928+
try {
929+
const response = await datasourceService.getDatasourceTypes();
930+
if (response.success && response.data) {
931+
datasourceTypes.value = response.data;
932+
}
933+
} catch (error) {
934+
ElMessage.error('加载数据源类型失败');
935+
console.error('Failed to load datasource types:', error);
936+
}
937+
};
938+
913939
// 初始化Agent数据源
914940
const initAgentDatasource = async () => {
915941
initStatus.value = true;
@@ -1586,6 +1612,9 @@
15861612
// PostgreSQL/Oracle Schema字段
15871613
schemaName,
15881614
schemaNameEdit,
1615+
// 数据源类型
1616+
datasourceTypes,
1617+
loadDatasourceTypes,
15891618
// 逻辑外键管理
15901619
Connection,
15911620
Link,

data-agent-frontend/src/services/datasource.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export interface AgentDatasource {
4747
selectTables?: string[];
4848
}
4949

50+
// 定义数据源类型接口
51+
export interface DatasourceType {
52+
code: number;
53+
typeName: string;
54+
dialect: string;
55+
protocol: string;
56+
displayName: string;
57+
}
58+
5059
const API_BASE_URL = '/api/datasource';
5160

5261
class DatasourceService {
@@ -111,6 +120,12 @@ class DatasourceService {
111120
const response = await axios.post<ApiResponse<boolean>>(`${API_BASE_URL}/${id}/test`);
112121
return response.data;
113122
}
123+
124+
// 8. 获取所有可用的数据源类型
125+
async getDatasourceTypes(): Promise<ApiResponse<DatasourceType[]>> {
126+
const response = await axios.get<ApiResponse<DatasourceType[]>>(`${API_BASE_URL}/types`);
127+
return response.data;
128+
}
114129
}
115130

116131
export default new DatasourceService();

data-agent-management/pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,62 @@
106106
<artifactId>h2</artifactId>
107107
<scope>runtime</scope>
108108
</dependency>
109+
110+
<!-- Hive JDBC 驱动 -->
111+
<dependency>
112+
<groupId>org.apache.hive</groupId>
113+
<artifactId>hive-jdbc</artifactId>
114+
<version>3.1.3</version>
115+
<scope>runtime</scope>
116+
<exclusions>
117+
<!-- 排除 Jetty 相关依赖,避免与 Tomcat 冲突 -->
118+
<exclusion>
119+
<groupId>org.eclipse.jetty.aggregate</groupId>
120+
<artifactId>*</artifactId>
121+
</exclusion>
122+
<exclusion>
123+
<groupId>org.eclipse.jetty</groupId>
124+
<artifactId>*</artifactId>
125+
</exclusion>
126+
<!-- 排除 Hadoop 相关依赖,减少依赖体积 -->
127+
<exclusion>
128+
<groupId>org.apache.hadoop</groupId>
129+
<artifactId>*</artifactId>
130+
</exclusion>
131+
<!-- 排除日志相关依赖,使用项目统一的日志框架 -->
132+
<exclusion>
133+
<groupId>org.slf4j</groupId>
134+
<artifactId>slf4j-log4j12</artifactId>
135+
</exclusion>
136+
<exclusion>
137+
<groupId>log4j</groupId>
138+
<artifactId>log4j</artifactId>
139+
</exclusion>
140+
<exclusion>
141+
<groupId>org.apache.logging.log4j</groupId>
142+
<artifactId>*</artifactId>
143+
</exclusion>
144+
<!-- 排除 Tomcat 相关依赖,避免版本冲突 -->
145+
<exclusion>
146+
<groupId>org.apache.tomcat</groupId>
147+
<artifactId>*</artifactId>
148+
</exclusion>
149+
<exclusion>
150+
<groupId>org.apache.tomcat.embed</groupId>
151+
<artifactId>*</artifactId>
152+
</exclusion>
153+
<!-- 排除 Servlet API,使用 Spring Boot 提供的版本 -->
154+
<exclusion>
155+
<groupId>javax.servlet</groupId>
156+
<artifactId>*</artifactId>
157+
</exclusion>
158+
<exclusion>
159+
<groupId>jakarta.servlet</groupId>
160+
<artifactId>*</artifactId>
161+
</exclusion>
162+
</exclusions>
163+
</dependency>
164+
109165
<!-- Swagger/OpenAPI 3 with WebFlux (no MVC) -->
110166
<dependency>
111167
<groupId>org.springdoc</groupId>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2024-2026 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.alibaba.cloud.ai.dataagent.connector.impls.hive;
17+
18+
import com.alibaba.cloud.ai.dataagent.connector.accessor.AbstractAccessor;
19+
import com.alibaba.cloud.ai.dataagent.connector.ddl.DdlFactory;
20+
import com.alibaba.cloud.ai.dataagent.connector.pool.DBConnectionPoolFactory;
21+
import com.alibaba.cloud.ai.dataagent.enums.BizDataSourceTypeEnum;
22+
import org.springframework.stereotype.Service;
23+
24+
/**
25+
* Hive 数据源访问器实现
26+
*/
27+
@Service("hiveAccessor")
28+
public class HiveDBAccessor extends AbstractAccessor {
29+
30+
private final static String ACCESSOR_TYPE = "Hive_Accessor";
31+
32+
protected HiveDBAccessor(DdlFactory ddlFactory, DBConnectionPoolFactory poolFactory) {
33+
super(ddlFactory, poolFactory.getPoolByDbType(BizDataSourceTypeEnum.HIVE.getTypeName()));
34+
}
35+
36+
@Override
37+
public String getAccessorType() {
38+
return ACCESSOR_TYPE;
39+
}
40+
41+
@Override
42+
public boolean supportedDataSourceType(String type) {
43+
return BizDataSourceTypeEnum.HIVE.getTypeName().equalsIgnoreCase(type);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)