diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-jdbc/src/main/java/io/datavines/connector/plugin/JdbcConnector.java b/datavines-connector/datavines-connector-plugins/datavines-connector-jdbc/src/main/java/io/datavines/connector/plugin/JdbcConnector.java index b0dce3e8a..f24398bb7 100644 --- a/datavines-connector/datavines-connector-plugins/datavines-connector-jdbc/src/main/java/io/datavines/connector/plugin/JdbcConnector.java +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-jdbc/src/main/java/io/datavines/connector/plugin/JdbcConnector.java @@ -60,7 +60,7 @@ public JdbcConnector(DataSourceClient dataSourceClient) { this.dataSourceClient = dataSourceClient; } - private Connection getConnection(String dataSourceParam, JdbcConnectionInfo jdbcConnectionInfo) throws SQLException { + public final Connection getConnection(String dataSourceParam, JdbcConnectionInfo jdbcConnectionInfo) throws SQLException { return dataSourceClient.getConnection(JdbcDataSourceInfoManager.getDatasourceInfo(dataSourceParam, getDatasourceInfo(jdbcConnectionInfo))); } diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-starrocks/src/main/java/io/datavines/connector/plugin/StarRocksConnector.java b/datavines-connector/datavines-connector-plugins/datavines-connector-starrocks/src/main/java/io/datavines/connector/plugin/StarRocksConnector.java index 39ad0cf34..639c7a6c6 100644 --- a/datavines-connector/datavines-connector-plugins/datavines-connector-starrocks/src/main/java/io/datavines/connector/plugin/StarRocksConnector.java +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-starrocks/src/main/java/io/datavines/connector/plugin/StarRocksConnector.java @@ -16,11 +16,76 @@ */ package io.datavines.connector.plugin; +import io.datavines.common.datasource.jdbc.JdbcConnectionInfo; +import io.datavines.common.datasource.jdbc.entity.TableInfo; +import io.datavines.common.datasource.jdbc.utils.JdbcDataSourceUtils; +import io.datavines.common.param.ConnectorResponse; +import io.datavines.common.param.GetTablesRequestParam; +import io.datavines.common.utils.JSONUtils; +import io.datavines.common.utils.StringUtils; import io.datavines.connector.api.DataSourceClient; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + public class StarRocksConnector extends MysqlConnector { public StarRocksConnector(DataSourceClient dataSourceClient) { super(dataSourceClient); } + + @Override + public ConnectorResponse getTables(GetTablesRequestParam param) throws SQLException { + ConnectorResponse.ConnectorResponseBuilder builder = ConnectorResponse.builder(); + String dataSourceParam = param.getDataSourceParam(); + + JdbcConnectionInfo jdbcConnectionInfo = JSONUtils.parseObject(dataSourceParam, JdbcConnectionInfo.class); + if (jdbcConnectionInfo == null) { + throw new SQLException("jdbc datasource param is no validate"); + } + + Connection connection = getConnection(dataSourceParam, jdbcConnectionInfo); + + List tableList = null; + ResultSet tables; + + try { + String schema = param.getDataBase(); + tableList = new ArrayList<>(); + tables = getMetadataTables(connection, schema); + + if (null == tables) { + return builder.result(tableList).build(); + } + + while (tables.next()) { + String name = tables.getString(TABLE_NAME); + if (!StringUtils.isEmpty(name)) { + String type = TABLE; + try { + type = tables.getString(TABLE_TYPE); + } catch (Exception e) { + // ignore + } + tableList.add(new TableInfo(schema, name, type, tables.getString("TABLE_COMMENT"))); + } + } + + } catch (Exception e) { + logger.error("get table list error: ", e); + } finally { + JdbcDataSourceUtils.releaseConnection(connection); + } + + return builder.result(tableList).build(); + } + + protected ResultSet getMetadataTables(Connection connection, String schema) throws SQLException { + java.sql.Statement stmt = connection.createStatement(); + return stmt.executeQuery("select TABLE_NAME, TABLE_TYPE, TABLE_COMMENT from information_schema.tables where TABLE_SCHEMA = '" + schema + "'"); + } } diff --git a/datavines-server/src/main/resources/application.yaml b/datavines-server/src/main/resources/application.yaml index 383521ff5..b9e5d38b0 100644 --- a/datavines-server/src/main/resources/application.yaml +++ b/datavines-server/src/main/resources/application.yaml @@ -89,7 +89,7 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/datavines?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai username: root - password: 123456 + password: admin123 quartz: properties: org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate \ No newline at end of file