sandynz commented on code in PR #20245:
URL: https://github.com/apache/shardingsphere/pull/20245#discussion_r947870787
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java:
##########
@@ -132,39 +134,38 @@ private Optional<String> decorate(final DatabaseType
databaseType, final String
}
private Collection<String> generateActualDDLSQL(final DatabaseType
databaseType, final String schemaName, final String actualTable, final
DataSource dataSource) throws SQLException {
- return
CreateTableSQLGeneratorFactory.findInstance(databaseType).orElseThrow(() -> new
ShardingSphereException("Failed to get dialect ddl sql generator"))
+ return
CreateTableSQLGeneratorFactory.findInstance(databaseType).orElseThrow(() -> new
ServiceProviderNotFoundException(DatabaseType.class))
.generate(actualTable, schemaName, dataSource);
}
Review Comment:
`new ServiceProviderNotFoundException(DatabaseType.class))` could be
improved, seems `new
ServiceProviderNotFoundException(CreateTableSQLGenerator.class, databaseType))`
could be used.
##########
shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/prepare/datasource/MySQLDataSourcePreparer.java:
##########
@@ -58,14 +61,14 @@ private List<String> getCreateTableSQL(final
PrepareTargetTablesParameter parame
PipelineDDLGenerator generator = new PipelineDDLGenerator();
ShardingSphereMetaData metaData =
PipelineContext.getContextManager().getMetaDataContexts().getMetaData();
ShardingSphereDatabase sphereDatabase =
metaData.getDatabases().get(parameter.getDatabaseName());
- ShardingSphereSQLParserEngine sqlParserEngine =
-
metaData.getGlobalRuleMetaData().getSingleRule(SQLParserRule.class)
-
.getSQLParserEngine(sphereDatabase.getProtocolType().getType());
+ ShardingSphereSQLParserEngine sqlParserEngine =
metaData.getGlobalRuleMetaData().getSingleRule(SQLParserRule.class).getSQLParserEngine(sphereDatabase.getProtocolType().getType());
List<String> result = new LinkedList<>();
for (JobDataNodeEntry each :
parameter.getTablesFirstDataNodes().getEntries()) {
String schemaName =
parameter.getTableNameSchemaNameMapping().getSchemaName(each.getLogicTableName());
String dataSourceName =
each.getDataNodes().get(0).getDataSourceName();
- result.add(generator.generateLogicDDLSQL(sphereDatabase,
dataSourceName, schemaName, each.getLogicTableName(),
+ DataSource dataSource =
sphereDatabase.getResource().getDataSources().get(dataSourceName);
+ DatabaseType databaseType =
DatabaseTypeEngine.getDatabaseType(Collections.singletonList(dataSource));
Review Comment:
Could we extract `sphereDatabase` to job preparer?
--
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]