korlov42 commented on code in PR #1109:
URL: https://github.com/apache/ignite-3/pull/1109#discussion_r976736392


##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/configuration/IndexValidatorImpl.java:
##########
@@ -64,28 +62,77 @@ public void validate(IndexValidator annotation, 
ValidationContext<NamedListView<
 
             if (tableView == null) {
                 ctx.addIssue(new ValidationIssue(key, "Unable to create index 
[name=" + key + "]. Table not found."));
+
+                // no further validation required for current index
+                continue;
             }
 
-            IndexDefinition index = 
SchemaConfigurationConverter.convert(idxView);
+            List<String> colocationColumns;
+            if (tableView.primaryKey() != null) {
+                colocationColumns = 
List.of(tableView.primaryKey().colocationColumns());
+            } else {
+                colocationColumns = List.of();
+            }
 
-            TableDefinitionImpl tbl = 
SchemaConfigurationConverter.convert(tableView);
+            validate(ctx, idxView, tableView.columns().namedListKeys(), 
colocationColumns);
+        }
+    }
 
-            Set<String> tableColumns = 
tbl.columns().stream().map(ColumnDefinition::name).collect(Collectors.toSet());
+    private void validate(
+            ValidationContext<?> ctx,
+            TableIndexView indexView,
+            Collection<String> tableColumns,
+            Collection<String> collocationColumns
+    ) {
+        List<String> indexedColumns;
+        if (indexView instanceof HashIndexView) {
+            var index0 = (HashIndexView) indexView;
+
+            // we need modifiable list
+            indexedColumns = Arrays.asList(index0.columnNames());
+        } else if (indexView instanceof SortedIndexView) {
+            var index0 = (SortedIndexView) indexView;
+
+            // we need modifiable list
+            indexedColumns = new ArrayList<>(index0.columns().namedListKeys());
+        } else {
+            ctx.addIssue(new ValidationIssue(indexView.name(), "Index type is 
not supported [type=" + indexView.type() + "]"));
+
+            // no further validation required
+            return;
+        }
 
-            List<String> tableColocationColumns = tbl.colocationColumns();
+        if (indexedColumns.isEmpty()) {
+            ctx.addIssue(new ValidationIssue(indexView.name(), "Index must 
include at least one column"));
 
-            try {
-                SchemaValidationUtils.validateIndexes(index, tableColumns, 
tableColocationColumns);
-            } catch (IllegalStateException e) {
-                ctx.addIssue(new ValidationIssue(key, e.getMessage()));
-            }
+            // no further validation required
+            return;
+        }
 
-            try {
-                SchemaValidationUtils.validateColumns(idxView, tableColumns);
-            } catch (IgniteInternalException e) {
-                ctx.addIssue(new ValidationIssue(key, e.getMessage()));
+        // need check this first because later indexedColumns will be truncated
+        if (indexView.uniq()) {
+            if (collocationColumns.isEmpty()) {
+                ctx.addIssue(new ValidationIssue(indexView.name(), "Unique 
index is not supported fro tables without primary key"));

Review Comment:
   good catch!



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