[improvement](jdbc catalog) opt get db2 schema list & xml type mapping (#31856)
1. Trim Schema Names: Adapted the system to remove trailing spaces from DB2 schema names, ensuring compatibility without affecting query operations. 2. XML Mapping: Implemented a feature to directly map XML types to String.
This commit is contained in:
@ -21,17 +21,52 @@ import org.apache.doris.catalog.PrimitiveType;
|
||||
import org.apache.doris.catalog.ScalarType;
|
||||
import org.apache.doris.catalog.Type;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
|
||||
public class JdbcDB2Client extends JdbcClient {
|
||||
|
||||
protected JdbcDB2Client(JdbcClientConfig jdbcClientConfig) {
|
||||
super(jdbcClientConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDatabaseNameList() {
|
||||
Connection conn = getConnection();
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
if (isOnlySpecifiedDatabase && includeDatabaseMap.isEmpty() && excludeDatabaseMap.isEmpty()) {
|
||||
return getSpecifiedDatabase(conn);
|
||||
}
|
||||
List<String> remoteDatabaseNames = Lists.newArrayList();
|
||||
try {
|
||||
rs = conn.getMetaData().getSchemas(conn.getCatalog(), null);
|
||||
while (rs.next()) {
|
||||
remoteDatabaseNames.add(rs.getString("TABLE_SCHEM").trim());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new JdbcClientException("failed to get database name list from jdbc", e);
|
||||
} finally {
|
||||
close(rs, stmt, conn);
|
||||
}
|
||||
return filterDatabaseNames(remoteDatabaseNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDatabaseQuery() {
|
||||
return "SELECT schemaname FROM syscat.schemata WHERE DEFINER = CURRENT USER;";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCatalogName(Connection conn) throws SQLException {
|
||||
return conn.getCatalog();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Type jdbcTypeToDoris(JdbcFieldSchema fieldSchema) {
|
||||
String db2Type = fieldSchema.getDataTypeName();
|
||||
@ -75,6 +110,7 @@ public class JdbcDB2Client extends JdbcClient {
|
||||
case "CLOB":
|
||||
case "VARGRAPHIC":
|
||||
case "LONG VARGRAPHIC":
|
||||
case "XML":
|
||||
return ScalarType.createStringType();
|
||||
default:
|
||||
return Type.UNSUPPORTED;
|
||||
|
||||
@ -52,18 +52,18 @@ public class JdbcOracleClient extends JdbcClient {
|
||||
if (isOnlySpecifiedDatabase && includeDatabaseMap.isEmpty() && excludeDatabaseMap.isEmpty()) {
|
||||
return getSpecifiedDatabase(conn);
|
||||
}
|
||||
List<String> databaseNames = Lists.newArrayList();
|
||||
List<String> remoteDatabaseNames = Lists.newArrayList();
|
||||
try {
|
||||
rs = conn.getMetaData().getSchemas(conn.getCatalog(), null);
|
||||
while (rs.next()) {
|
||||
databaseNames.add(rs.getString("TABLE_SCHEM"));
|
||||
remoteDatabaseNames.add(rs.getString("TABLE_SCHEM"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new JdbcClientException("failed to get database name list from jdbc", e);
|
||||
} finally {
|
||||
close(rs, conn);
|
||||
}
|
||||
return filterDatabaseNames(databaseNames);
|
||||
return filterDatabaseNames(remoteDatabaseNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user