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


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandler.java:
##########
@@ -134,115 +127,102 @@ public DdlCommandHandler(
 
     /** Handles create distribution zone command. */
     private CompletableFuture<@Nullable Long> 
handleCreateZone(CreateZoneCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifNotExists(), 
DistributionZoneExistsValidationException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** Handles rename zone command. */
     private CompletableFuture<@Nullable Long> 
handleRenameZone(RenameZoneCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** Handles alter zone command. */
     private CompletableFuture<@Nullable Long> handleAlterZone(AlterZoneCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** Handles alter zone set default command. */
     private CompletableFuture<@Nullable Long> 
handleAlterZoneSetDefault(AlterZoneSetDefaultCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** Handles drop distribution zone command. */
     private CompletableFuture<@Nullable Long> handleDropZone(DropZoneCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
DistributionZoneNotFoundValidationException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** Handles create table command. */
     private CompletableFuture<@Nullable Long> 
handleCreateTable(CreateTableCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableExistsValidationException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** Handles drop table command. */
     private CompletableFuture<@Nullable Long> handleDropTable(DropTableCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** Handles add column command. */
     private CompletableFuture<@Nullable Long> 
handleAlterAddColumn(AlterTableAddColumnCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** Handles drop column command. */
     private CompletableFuture<@Nullable Long> 
handleAlterDropColumn(AlterTableDropColumnCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** Handles drop column command. */
     private CompletableFuture<@Nullable Long> 
handleAlterColumn(AlterTableAlterColumnCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifTableExists(), 
TableNotFoundValidationException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** 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));
+                .thenCompose(applyResult -> inBusyLock(busyLock, () -> 
waitTillIndexBecomesAvailableOrRemoved(cmd, applyResult)))
+                .handle(handleModificationResult());
     }
 
     /** Handles drop index command. */
     private CompletableFuture<@Nullable Long> handleDropIndex(DropIndexCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
IndexNotFoundValidationException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** Handles create schema command. */
     private CompletableFuture<Long> handleCreateSchema(CreateSchemaCommand 
cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifNotExists(), 
SchemaExistsException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
     /** Handles drop schema command. */
     private CompletableFuture<Long> handleDropSchema(DropSchemaCommand cmd) {
-        return catalogManager.execute(cmd)
-                .handle(handleModificationResult(cmd.ifExists(), 
SchemaNotFoundException.class));
+        return catalogManager.execute(cmd).handle(handleModificationResult());
     }
 
-    private BiFunction<Integer, Throwable, @Nullable Long> 
handleModificationResult(boolean ignoreExpectedError, Class<?> expErrCls) {
-        return (ver, err) -> {
+    private BiFunction<CatalogApplyResult, Throwable, @Nullable Long> 
handleModificationResult() {
+        return (applyResult, err) -> {
             if (err == null) {
-                Catalog catalog = catalogManager.catalog(ver);
+                Catalog catalog = 
catalogManager.catalog(applyResult.getCatalogVersion());
 
                 assert catalog != null;
 
-                return catalog.time();
-            } else if (ignoreExpectedError) {
-                Throwable err0 = err instanceof CompletionException ? 
err.getCause() : err;
-
-                if (expErrCls.isAssignableFrom(err0.getClass())) {
-                    return null;
-                }
+                return applyResult.isApplied(0) ? catalog.time() : null;

Review Comment:
   @korlov42 Why do we need this? :thinking: 
   Previously we did not return the time if the command was not applied. 



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