mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
(improvement)(format)Follow the code style.
This commit is contained in:
@@ -109,7 +109,8 @@ public class SemanticParseInfo implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
private static class SchemaNameLengthComparator implements Comparator<SchemaElement>, Serializable {
|
||||
private static class SchemaNameLengthComparator
|
||||
implements Comparator<SchemaElement>, Serializable {
|
||||
@Override
|
||||
public int compare(SchemaElement o1, SchemaElement o2) {
|
||||
if (o1.getOrder() != o2.getOrder()) {
|
||||
|
||||
@@ -74,7 +74,8 @@ public abstract class BaseDbAdaptor implements DbAdaptor {
|
||||
List<String> tablesAndViews = new ArrayList<>();
|
||||
|
||||
try {
|
||||
try(ResultSet resultSet = getResultSet(schemaName, getDatabaseMetaData(connectionInfo))) {
|
||||
try (ResultSet resultSet =
|
||||
getResultSet(schemaName, getDatabaseMetaData(connectionInfo))) {
|
||||
while (resultSet.next()) {
|
||||
String name = resultSet.getString("TABLE_NAME");
|
||||
tablesAndViews.add(name);
|
||||
@@ -93,11 +94,12 @@ public abstract class BaseDbAdaptor implements DbAdaptor {
|
||||
|
||||
|
||||
|
||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName, String tableName)
|
||||
throws SQLException {
|
||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName,
|
||||
String tableName) throws SQLException {
|
||||
List<DBColumn> dbColumns = new ArrayList<>();
|
||||
// 确保连接会自动关闭
|
||||
try (ResultSet columns = getDatabaseMetaData(connectInfo).getColumns(catalog, schemaName, tableName, null)) {
|
||||
try (ResultSet columns =
|
||||
getDatabaseMetaData(connectInfo).getColumns(catalog, schemaName, tableName, null)) {
|
||||
while (columns.next()) {
|
||||
String columnName = columns.getString("COLUMN_NAME");
|
||||
String dataType = columns.getString("TYPE_NAME");
|
||||
|
||||
@@ -21,8 +21,8 @@ public interface DbAdaptor {
|
||||
List<String> getTables(ConnectInfo connectInfo, String catalog, String schemaName)
|
||||
throws SQLException;
|
||||
|
||||
List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName, String tableName)
|
||||
throws SQLException;
|
||||
List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName,
|
||||
String tableName) throws SQLException;
|
||||
|
||||
FieldType classifyColumnType(String typeName);
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ public class DuckdbAdaptor extends DefaultDbAdaptor {
|
||||
return metaData.getTables(schemaName, null, null, new String[] {"TABLE", "VIEW"});
|
||||
}
|
||||
|
||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName, String tableName)
|
||||
throws SQLException {
|
||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName,
|
||||
String tableName) throws SQLException {
|
||||
List<DBColumn> dbColumns = Lists.newArrayList();
|
||||
DatabaseMetaData metaData = getDatabaseMetaData(connectInfo);
|
||||
ResultSet columns = metaData.getColumns(schemaName, null, tableName, null);
|
||||
|
||||
@@ -46,8 +46,8 @@ public class H2Adaptor extends BaseDbAdaptor {
|
||||
return metaData.getTables(schemaName, null, null, new String[] {"TABLE", "VIEW"});
|
||||
}
|
||||
|
||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName, String tableName)
|
||||
throws SQLException {
|
||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName,
|
||||
String tableName) throws SQLException {
|
||||
List<DBColumn> dbColumns = Lists.newArrayList();
|
||||
DatabaseMetaData metaData = getDatabaseMetaData(connectInfo);
|
||||
ResultSet columns = metaData.getColumns(schemaName, null, tableName, null);
|
||||
|
||||
@@ -61,11 +61,13 @@ public class KyuubiAdaptor extends BaseDbAdaptor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTables(ConnectInfo connectInfo, String catalog, String schemaName) throws SQLException {
|
||||
public List<String> getTables(ConnectInfo connectInfo, String catalog, String schemaName)
|
||||
throws SQLException {
|
||||
List<String> tablesAndViews = new ArrayList<>();
|
||||
|
||||
try {
|
||||
try (ResultSet resultSet = getDatabaseMetaData(connectInfo).getTables(catalog, schemaName, null, new String[] {"TABLE", "VIEW"})) {
|
||||
try (ResultSet resultSet = getDatabaseMetaData(connectInfo).getTables(catalog,
|
||||
schemaName, null, new String[] {"TABLE", "VIEW"})) {
|
||||
while (resultSet.next()) {
|
||||
String name = resultSet.getString("TABLE_NAME");
|
||||
tablesAndViews.add(name);
|
||||
|
||||
@@ -99,8 +99,8 @@ public class PostgresqlAdaptor extends BaseDbAdaptor {
|
||||
return tablesAndViews;
|
||||
}
|
||||
|
||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName, String tableName)
|
||||
throws SQLException {
|
||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName,
|
||||
String tableName) throws SQLException {
|
||||
List<DBColumn> dbColumns = Lists.newArrayList();
|
||||
DatabaseMetaData metaData = getDatabaseMetaData(connectInfo);
|
||||
ResultSet columns = metaData.getColumns(null, null, tableName, null);
|
||||
|
||||
@@ -55,12 +55,11 @@ public class StarrocksAdaptor extends MysqlAdaptor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName, String tableName)
|
||||
throws SQLException {
|
||||
public List<DBColumn> getColumns(ConnectInfo connectInfo, String catalog, String schemaName,
|
||||
String tableName) throws SQLException {
|
||||
List<DBColumn> dbColumns = new ArrayList<>();
|
||||
|
||||
try (Connection con = getConnection(connectInfo);
|
||||
Statement st = con.createStatement()) {
|
||||
try (Connection con = getConnection(connectInfo); Statement st = con.createStatement()) {
|
||||
|
||||
// 切换到指定的 catalog(或 database/schema),这在某些 SQL 方言中很重要
|
||||
if (StringUtils.isNotBlank(catalog)) {
|
||||
|
||||
@@ -41,17 +41,19 @@ public class JdbcDataSourceUtils {
|
||||
return false;
|
||||
}
|
||||
// presto/trino ssl=false connection need password
|
||||
if (database.getUrl().startsWith("jdbc:presto") || database.getUrl().startsWith("jdbc:trino")) {
|
||||
if (database.getUrl().startsWith("jdbc:presto")
|
||||
|| database.getUrl().startsWith("jdbc:trino")) {
|
||||
if (database.getUrl().toLowerCase().contains("ssl=false")) {
|
||||
try (Connection con = DriverManager.getConnection(database.getUrl(), database.getUsername(), null)) {
|
||||
try (Connection con = DriverManager.getConnection(database.getUrl(),
|
||||
database.getUsername(), null)) {
|
||||
return con != null;
|
||||
} catch (SQLException e) {
|
||||
log.error(e.toString(), e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try (Connection con = DriverManager.getConnection(database.getUrl(), database.getUsername(),
|
||||
database.passwordDecrypt())) {
|
||||
try (Connection con = DriverManager.getConnection(database.getUrl(),
|
||||
database.getUsername(), database.passwordDecrypt())) {
|
||||
return con != null;
|
||||
} catch (SQLException e) {
|
||||
log.error(e.toString(), e);
|
||||
|
||||
@@ -97,8 +97,7 @@ public class DatabaseController {
|
||||
@RequestMapping("/getColumnsByName")
|
||||
public List<DBColumn> getColumnsByName(@RequestParam("databaseId") Long databaseId,
|
||||
@RequestParam(name = "catalog", required = false) String catalog,
|
||||
@RequestParam("db") String db,
|
||||
@RequestParam("table") String table)
|
||||
@RequestParam("db") String db, @RequestParam("table") String table)
|
||||
throws SQLException {
|
||||
return databaseService.getColumns(databaseId, catalog, db, table);
|
||||
}
|
||||
|
||||
@@ -233,8 +233,8 @@ public class DatabaseServiceImpl extends ServiceImpl<DatabaseDOMapper, DatabaseD
|
||||
dbColumnMap.put(modelBuildReq.getSql(), columns);
|
||||
} else {
|
||||
for (String table : modelBuildReq.getTables()) {
|
||||
List<DBColumn> columns =
|
||||
getColumns(modelBuildReq.getDatabaseId(), modelBuildReq.getCatalog(), modelBuildReq.getDb(), table);
|
||||
List<DBColumn> columns = getColumns(modelBuildReq.getDatabaseId(),
|
||||
modelBuildReq.getCatalog(), modelBuildReq.getDb(), table);
|
||||
dbColumnMap.put(table, columns);
|
||||
}
|
||||
}
|
||||
@@ -242,15 +242,17 @@ public class DatabaseServiceImpl extends ServiceImpl<DatabaseDOMapper, DatabaseD
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DBColumn> getColumns(Long id, String catalog, String db, String table) throws SQLException {
|
||||
public List<DBColumn> getColumns(Long id, String catalog, String db, String table)
|
||||
throws SQLException {
|
||||
DatabaseResp databaseResp = getDatabase(id);
|
||||
return getColumns(databaseResp, catalog, db, table);
|
||||
}
|
||||
|
||||
public List<DBColumn> getColumns(DatabaseResp databaseResp, String catalog, String db, String table)
|
||||
throws SQLException {
|
||||
public List<DBColumn> getColumns(DatabaseResp databaseResp, String catalog, String db,
|
||||
String table) throws SQLException {
|
||||
DbAdaptor engineAdaptor = DbAdaptorFactory.getEngineAdaptor(databaseResp.getType());
|
||||
return engineAdaptor.getColumns(DatabaseConverter.getConnectInfo(databaseResp), catalog, db, table);
|
||||
return engineAdaptor.getColumns(DatabaseConverter.getConnectInfo(databaseResp), catalog, db,
|
||||
table);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user