xtern commented on code in PR #5121:
URL: https://github.com/apache/ignite-3/pull/5121#discussion_r1935313319


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandler.java:
##########
@@ -97,152 +73,34 @@ public DdlCommandHandler(
      *         catalog, the result will be {@code null}.
      */
     public CompletableFuture<@Nullable Long> handle(CatalogCommand cmd) {
-        if (cmd instanceof CreateSchemaCommand) {
-            return handleCreateSchema((CreateSchemaCommand) cmd);
-        } else if (cmd instanceof DropSchemaCommand) {
-            return handleDropSchema((DropSchemaCommand) cmd);
-        } else if (cmd instanceof CreateTableCommand) {
-            return handleCreateTable((CreateTableCommand) cmd);
-        } else if (cmd instanceof DropTableCommand) {
-            return handleDropTable((DropTableCommand) cmd);
-        } else if (cmd instanceof AlterTableAddColumnCommand) {
-            return handleAlterAddColumn((AlterTableAddColumnCommand) cmd);
-        } else if (cmd instanceof AlterTableDropColumnCommand) {
-            return handleAlterDropColumn((AlterTableDropColumnCommand) cmd);
-        } else if (cmd instanceof AlterTableAlterColumnCommand) {
-            return handleAlterColumn((AlterTableAlterColumnCommand) cmd);
-        } else if (cmd instanceof AbstractCreateIndexCommand) {
-            return handleCreateIndex((AbstractCreateIndexCommand) cmd);
-        } else if (cmd instanceof DropIndexCommand) {
-            return handleDropIndex((DropIndexCommand) cmd);
-        } else if (cmd instanceof CreateZoneCommand) {
-            return handleCreateZone((CreateZoneCommand) cmd);
-        } else if (cmd instanceof RenameZoneCommand) {
-            return handleRenameZone((RenameZoneCommand) cmd);
-        } else if (cmd instanceof AlterZoneCommand) {
-            return handleAlterZone((AlterZoneCommand) cmd);
-        } else if (cmd instanceof AlterZoneSetDefaultCommand) {
-            return handleAlterZoneSetDefault((AlterZoneSetDefaultCommand) cmd);
-        } else if (cmd instanceof DropZoneCommand) {
-            return handleDropZone((DropZoneCommand) cmd);
-        } else {
-            return failedFuture(new SqlException(STMT_VALIDATION_ERR, 
"Unsupported DDL operation ["
-                    + "cmdName=" + (cmd == null ? null : 
cmd.getClass().getSimpleName()) + "; "
-                    + "cmd=\"" + cmd + "\"]"));
-        }
-    }
-
-    /** Handles create distribution zone command. */
-    private CompletableFuture<@Nullable Long> 
handleCreateZone(CreateZoneCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifNotExists(), 
DistributionZoneExistsValidationException.class));
-    }
-
-    /** Handles rename zone command. */
-    private CompletableFuture<@Nullable Long> 
handleRenameZone(RenameZoneCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
-    }
-
-    /** Handles alter zone command. */
-    private CompletableFuture<@Nullable Long> handleAlterZone(AlterZoneCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
-    }
-
-    /** Handles alter zone set default command. */
-    private CompletableFuture<@Nullable Long> 
handleAlterZoneSetDefault(AlterZoneSetDefaultCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
-    }
+        CompletableFuture<CatalogApplyResult> fut = 
catalogManager.execute(cmd);
 
-    /** Handles drop distribution zone command. */
-    private CompletableFuture<@Nullable Long> handleDropZone(DropZoneCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
-    }
-
-    /** Handles create table command. */
-    private CompletableFuture<@Nullable Long> 
handleCreateTable(CreateTableCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableExistsValidationException.class));
-    }
-
-    /** Handles drop table command. */
-    private CompletableFuture<@Nullable Long> handleDropTable(DropTableCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
-    }
-
-    /** Handles add column command. */
-    private CompletableFuture<@Nullable Long> 
handleAlterAddColumn(AlterTableAddColumnCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
-    }
-
-    /** Handles drop column command. */
-    private CompletableFuture<@Nullable Long> 
handleAlterDropColumn(AlterTableDropColumnCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
-    }
-
-    /** Handles drop column command. */
-    private CompletableFuture<@Nullable Long> 
handleAlterColumn(AlterTableAlterColumnCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
-    }
-
-    /** Handles create index command. */
-    private CompletableFuture<@Nullable Long> 
handleCreateIndex(AbstractCreateIndexCommand cmd) {
-        return catalogManager.execute(cmd)
-                .thenCompose(catalogVersion -> inBusyLock(busyLock, () -> 
waitTillIndexBecomesAvailableOrRemoved(cmd, catalogVersion)))
-                .handle(handleModificationResult(cmd.ifNotExists(), 
IndexExistsValidationException.class));
-    }
-
-    /** Handles drop index command. */
-    private CompletableFuture<@Nullable Long> handleDropIndex(DropIndexCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
IndexNotFoundValidationException.class));
-    }
-
-    /** Handles create schema command. */
-    private CompletableFuture<Long> handleCreateSchema(CreateSchemaCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifNotExists(), 
SchemaExistsException.class));
-    }
-
-    /** Handles drop schema command. */
-    private CompletableFuture<Long> handleDropSchema(DropSchemaCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
SchemaNotFoundException.class));
-    }
+        if (cmd instanceof AbstractCreateIndexCommand) {
+            fut = fut.thenCompose(applyResult ->
+                    inBusyLock(busyLock, () -> 
waitTillIndexBecomesAvailableOrRemoved((AbstractCreateIndexCommand) cmd, 
applyResult)));
+        }
 
-    private BiFunction<Integer, Throwable, @Nullable Long> 
handleModificationResult(boolean ignoreExpectedError, Class<?> expErrCls) {
-        return (ver, err) -> {
+        return fut.handle((applyResult, err) -> {

Review Comment:
   return fut.thenApply(applyResult -> applyResult.isApplied(0) ? 
applyResult.getCatalogTime() : null);



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandler.java:
##########
@@ -97,152 +73,34 @@ public DdlCommandHandler(
      *         catalog, the result will be {@code null}.
      */
     public CompletableFuture<@Nullable Long> handle(CatalogCommand cmd) {
-        if (cmd instanceof CreateSchemaCommand) {
-            return handleCreateSchema((CreateSchemaCommand) cmd);
-        } else if (cmd instanceof DropSchemaCommand) {
-            return handleDropSchema((DropSchemaCommand) cmd);
-        } else if (cmd instanceof CreateTableCommand) {
-            return handleCreateTable((CreateTableCommand) cmd);
-        } else if (cmd instanceof DropTableCommand) {
-            return handleDropTable((DropTableCommand) cmd);
-        } else if (cmd instanceof AlterTableAddColumnCommand) {
-            return handleAlterAddColumn((AlterTableAddColumnCommand) cmd);
-        } else if (cmd instanceof AlterTableDropColumnCommand) {
-            return handleAlterDropColumn((AlterTableDropColumnCommand) cmd);
-        } else if (cmd instanceof AlterTableAlterColumnCommand) {
-            return handleAlterColumn((AlterTableAlterColumnCommand) cmd);
-        } else if (cmd instanceof AbstractCreateIndexCommand) {
-            return handleCreateIndex((AbstractCreateIndexCommand) cmd);
-        } else if (cmd instanceof DropIndexCommand) {
-            return handleDropIndex((DropIndexCommand) cmd);
-        } else if (cmd instanceof CreateZoneCommand) {
-            return handleCreateZone((CreateZoneCommand) cmd);
-        } else if (cmd instanceof RenameZoneCommand) {
-            return handleRenameZone((RenameZoneCommand) cmd);
-        } else if (cmd instanceof AlterZoneCommand) {
-            return handleAlterZone((AlterZoneCommand) cmd);
-        } else if (cmd instanceof AlterZoneSetDefaultCommand) {
-            return handleAlterZoneSetDefault((AlterZoneSetDefaultCommand) cmd);
-        } else if (cmd instanceof DropZoneCommand) {
-            return handleDropZone((DropZoneCommand) cmd);
-        } else {
-            return failedFuture(new SqlException(STMT_VALIDATION_ERR, 
"Unsupported DDL operation ["
-                    + "cmdName=" + (cmd == null ? null : 
cmd.getClass().getSimpleName()) + "; "
-                    + "cmd=\"" + cmd + "\"]"));
-        }
-    }
-
-    /** Handles create distribution zone command. */
-    private CompletableFuture<@Nullable Long> 
handleCreateZone(CreateZoneCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifNotExists(), 
DistributionZoneExistsValidationException.class));
-    }
-
-    /** Handles rename zone command. */
-    private CompletableFuture<@Nullable Long> 
handleRenameZone(RenameZoneCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
-    }
-
-    /** Handles alter zone command. */
-    private CompletableFuture<@Nullable Long> handleAlterZone(AlterZoneCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
-    }
-
-    /** Handles alter zone set default command. */
-    private CompletableFuture<@Nullable Long> 
handleAlterZoneSetDefault(AlterZoneSetDefaultCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
-    }
+        CompletableFuture<CatalogApplyResult> fut = 
catalogManager.execute(cmd);
 
-    /** Handles drop distribution zone command. */
-    private CompletableFuture<@Nullable Long> handleDropZone(DropZoneCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
-    }
-
-    /** Handles create table command. */
-    private CompletableFuture<@Nullable Long> 
handleCreateTable(CreateTableCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableExistsValidationException.class));
-    }
-
-    /** Handles drop table command. */
-    private CompletableFuture<@Nullable Long> handleDropTable(DropTableCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
-    }
-
-    /** Handles add column command. */
-    private CompletableFuture<@Nullable Long> 
handleAlterAddColumn(AlterTableAddColumnCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
-    }
-
-    /** Handles drop column command. */
-    private CompletableFuture<@Nullable Long> 
handleAlterDropColumn(AlterTableDropColumnCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
-    }
-
-    /** Handles drop column command. */
-    private CompletableFuture<@Nullable Long> 
handleAlterColumn(AlterTableAlterColumnCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
-    }
-
-    /** Handles create index command. */
-    private CompletableFuture<@Nullable Long> 
handleCreateIndex(AbstractCreateIndexCommand cmd) {
-        return catalogManager.execute(cmd)
-                .thenCompose(catalogVersion -> inBusyLock(busyLock, () -> 
waitTillIndexBecomesAvailableOrRemoved(cmd, catalogVersion)))
-                .handle(handleModificationResult(cmd.ifNotExists(), 
IndexExistsValidationException.class));
-    }
-
-    /** Handles drop index command. */
-    private CompletableFuture<@Nullable Long> handleDropIndex(DropIndexCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
IndexNotFoundValidationException.class));
-    }
-
-    /** Handles create schema command. */
-    private CompletableFuture<Long> handleCreateSchema(CreateSchemaCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifNotExists(), 
SchemaExistsException.class));
-    }
-
-    /** Handles drop schema command. */
-    private CompletableFuture<Long> handleDropSchema(DropSchemaCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
SchemaNotFoundException.class));
-    }
+        if (cmd instanceof AbstractCreateIndexCommand) {
+            fut = fut.thenCompose(applyResult ->
+                    inBusyLock(busyLock, () -> 
waitTillIndexBecomesAvailableOrRemoved((AbstractCreateIndexCommand) cmd, 
applyResult)));
+        }
 
-    private BiFunction<Integer, Throwable, @Nullable Long> 
handleModificationResult(boolean ignoreExpectedError, Class<?> expErrCls) {
-        return (ver, err) -> {
+        return fut.handle((applyResult, err) -> {

Review Comment:
   ```suggestion
           return fut.thenApply(applyResult -> applyResult.isApplied(0) ? 
applyResult.getCatalogTime() : null);
   ```



-- 
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]

Reply via email to