ruanwenjun commented on code in PR #5535:
URL: https://github.com/apache/seatunnel/pull/5535#discussion_r1360505621
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/Catalog.java:
##########
@@ -125,17 +124,14 @@ default Optional<Factory> getFactory() {
default List<CatalogTable> getTables(ReadonlyConfig config) throws
CatalogException {
// Get the list of specified tables
List<String> tableNames = config.get(CatalogOptions.TABLE_NAMES);
- List<CatalogTable> catalogTables = Collections.synchronizedList(new
ArrayList<>());
- if (CollectionUtils.isNotEmpty(tableNames)) {
- tableNames
- .parallelStream()
- .forEach(
- tableName -> {
- TablePath tablePath = TablePath.of(tableName);
- if (this.tableExists(tablePath)) {
-
catalogTables.add(this.getTable(tablePath));
- }
- });
+ List<CatalogTable> catalogTables = new ArrayList<>();
+ if (tableNames != null && !tableNames.isEmpty()) {
+ for (String tableName : tableNames) {
+ TablePath tablePath = TablePath.of(tableName);
Review Comment:
It's better to use parallelStream here, in the test, if we have many tables
this part might cost several minutes.
##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/sink/JdbcSinkFactory.java:
##########
@@ -167,6 +170,21 @@ public TableSink createSink(TableSinkFactoryContext
context) {
PrimaryKey primaryKey =
catalogTable.getTableSchema().getPrimaryKey();
if (primaryKey != null &&
!CollectionUtils.isEmpty(primaryKey.getColumnNames())) {
map.put(PRIMARY_KEYS.key(), String.join(",",
primaryKey.getColumnNames()));
+ } else {
+ Optional<ConstraintKey> keyOptional =
+
catalogTable.getTableSchema().getConstraintKeys().stream()
+ .filter(
+ key ->
+
ConstraintKey.ConstraintType.UNIQUE_KEY.equals(
+
key.getConstraintType()))
+ .findFirst();
+ if (keyOptional.isPresent()) {
+ map.put(
+ PRIMARY_KEYS.key(),
+ keyOptional.get().getColumnNames().stream()
+ .map(key -> key.getColumnName())
+ .collect(Collectors.joining(",")));
+ }
Review Comment:
This logic is strange, why you put unique_key into primary key?
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/table/catalog/Catalog.java:
##########
@@ -150,17 +146,11 @@ default List<CatalogTable> getTables(ReadonlyConfig
config) throws CatalogExcept
allDatabase.removeIf(s -> !databasePattern.matcher(s).matches());
for (String databaseName : allDatabase) {
tableNames = this.listTables(databaseName);
- tableNames
- .parallelStream()
- .forEach(
- tableName -> {
- if (tablePattern
- .matcher(databaseName + "." +
tableName)
- .matches()) {
- catalogTables.add(
-
this.getTable(TablePath.of(databaseName, tableName)));
- }
- });
+ for (String tableName : tableNames) {
+ if (tablePattern.matcher(databaseName + "." +
tableName).matches()) {
Review Comment:
ditto
--
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]