sandynz commented on code in PR #20443:
URL: https://github.com/apache/shardingsphere/pull/20443#discussion_r952170992
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineSchemaTableUtil.java:
##########
@@ -45,24 +46,44 @@ private PipelineSchemaTableUtil() {
* Get schema tables map from actual data source.
*
* @param pipelineDataSourceConfig pipeline data source config
+ * @param schemaName schema name,
* @param tableName table name
* @return schema tables map
*/
- public static Map<String, List<String>> getSchemaTablesMapFromActual(final
PipelineDataSourceConfiguration pipelineDataSourceConfig, final String
tableName) {
+ public static Map<String, List<String>> getSchemaTablesMapFromActual(final
PipelineDataSourceConfiguration pipelineDataSourceConfig, final String
schemaName, final String tableName) {
+ log.info("start get schema tables from actual, begin:{}",
LocalDateTime.now());
Map<String, List<String>> result = new HashMap<>();
try (PipelineDataSourceWrapper dataSource =
PipelineDataSourceFactory.newInstance(pipelineDataSourceConfig)) {
try (Connection connection = dataSource.getConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
- ResultSet resultSet = metaData.getTables(null, null,
tableName, new String[]{"TABLE"});
+ String targetSchema = ObjectUtils.defaultIfNull(schemaName,
connection.getSchema());
+ ResultSet resultSet =
metaData.getTables(connection.getCatalog(), targetSchema, tableName, new
String[]{"TABLE"});
while (resultSet.next()) {
- String schemaName = resultSet.getString("TABLE_SCHEM");
- result.computeIfAbsent(schemaName, k -> new
ArrayList<>()).add(resultSet.getString("TABLE_NAME"));
+ result.computeIfAbsent(targetSchema, k -> new
ArrayList<>()).add(resultSet.getString("TABLE_NAME"));
}
+ log.info("get schema tables success, catalog:{}, schema:{},
table:{}, result:{}, end:{}", targetSchema, connection.getCatalog(), tableName,
resultSet, LocalDateTime.now());
}
} catch (final SQLException ex) {
- log.error("Get schema name map error", ex);
- throw new AddMigrationSourceResourceException(ex.getMessage());
+ log.error("get schema name map error", ex);
+ throw new RuntimeException(ex.getMessage());
}
return result;
}
+
+ /**
+ * get default schema by connection.getSchema().
+ *
+ * @param pipelineDataSourceConfig pipeline data source config
+ * @return schema
+ */
+ public static String getDefaultSchema(final
PipelineDataSourceConfiguration pipelineDataSourceConfig) {
+ try (PipelineDataSourceWrapper dataSource =
PipelineDataSourceFactory.newInstance(pipelineDataSourceConfig)) {
+ try (Connection connection = dataSource.getConnection()) {
+ return connection.getSchema();
+ }
+ } catch (final SQLException ex) {
+ log.error("get default schema name error", ex);
+ throw new RuntimeException(ex.getMessage());
+ }
Review Comment:
SQLException could be thrown
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]