rpuch commented on code in PR #3223:
URL: https://github.com/apache/ignite-3/pull/3223#discussion_r1496147583


##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/AlterTableDropColumnCommand.java:
##########
@@ -98,24 +96,39 @@ public List<UpdateEntry> get(Catalog catalog) {
             }
 
             if (indexedColumns.contains(columnName)) {
-                List<String> indexesNames = Arrays.stream(schema.indexes())
-                        .filter(index -> index.tableId() == table.id())
-                        .filter(index -> index instanceof 
CatalogHashIndexDescriptor
-                                ? ((CatalogHashIndexDescriptor) 
index).columns().contains(columnName)
-                                : ((CatalogSortedIndexDescriptor) 
index).columns().stream().map(CatalogIndexColumnDescriptor::name)
-                                        .anyMatch(column -> 
column.equals(columnName))
-                
).map(CatalogIndexDescriptor::name).collect(Collectors.toList());
+                List<String> indexesNames = indexesForTable(schema, table)
+                        .filter(index -> 
indexColumnNames(index).anyMatch(columnName::equals))
+                        .map(CatalogIndexDescriptor::name)
+                        .collect(Collectors.toList());
 
                 throw new CatalogValidationException(format(
                         "Deleting column '{}' used by index(es) {}, it is not 
allowed", columnName, indexesNames));
             }
-        }
+        });
 
         return List.of(
                 new DropColumnsEntry(table.id(), columns, schemaName)
         );
     }
 
+    private static Stream<CatalogIndexDescriptor> 
indexesForTable(CatalogSchemaDescriptor schema, CatalogTableDescriptor table) {
+        return Arrays.stream(schema.indexes())
+                .filter(index -> index.tableId() == table.id() && 
index.status() != CatalogIndexStatus.STOPPING);

Review Comment:
   I'm not insisting, this is a little thing anyway, but adding an instance 
method seems easy, like
   
   ```
       public boolean alive() {
           return this == STOPPING;
       }
   ```



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/AlterTableDropColumnCommand.java:
##########
@@ -98,24 +96,39 @@ public List<UpdateEntry> get(Catalog catalog) {
             }
 
             if (indexedColumns.contains(columnName)) {
-                List<String> indexesNames = Arrays.stream(schema.indexes())
-                        .filter(index -> index.tableId() == table.id())
-                        .filter(index -> index instanceof 
CatalogHashIndexDescriptor
-                                ? ((CatalogHashIndexDescriptor) 
index).columns().contains(columnName)
-                                : ((CatalogSortedIndexDescriptor) 
index).columns().stream().map(CatalogIndexColumnDescriptor::name)
-                                        .anyMatch(column -> 
column.equals(columnName))
-                
).map(CatalogIndexDescriptor::name).collect(Collectors.toList());
+                List<String> indexesNames = indexesForTable(schema, table)
+                        .filter(index -> 
indexColumnNames(index).anyMatch(columnName::equals))
+                        .map(CatalogIndexDescriptor::name)
+                        .collect(Collectors.toList());
 
                 throw new CatalogValidationException(format(
                         "Deleting column '{}' used by index(es) {}, it is not 
allowed", columnName, indexesNames));
             }
-        }
+        });
 
         return List.of(
                 new DropColumnsEntry(table.id(), columns, schemaName)
         );
     }
 
+    private static Stream<CatalogIndexDescriptor> 
indexesForTable(CatalogSchemaDescriptor schema, CatalogTableDescriptor table) {
+        return Arrays.stream(schema.indexes())
+                .filter(index -> index.tableId() == table.id() && 
index.status() != CatalogIndexStatus.STOPPING);

Review Comment:
   I'm not insisting, this is a little thing anyway, but adding an instance 
method seems easy, like
   
   ```
       public boolean alive() {
           return this != STOPPING;
       }
   ```



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