tkalkirill commented on code in PR #2231:
URL: https://github.com/apache/ignite-3/pull/2231#discussion_r1237515837


##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogServiceImpl.java:
##########
@@ -277,82 +259,62 @@ private Catalog catalogAt(long timestamp) {
         return entry.getValue();
     }
 
-    /** {@inheritDoc} */
     @Override
     public CompletableFuture<Void> createTable(CreateTableParams params) {
         return saveUpdate(catalog -> {
-            String schemaName = 
Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
-
-            CatalogSchemaDescriptor schema = 
Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " + 
schemaName);
+            CatalogSchemaDescriptor schema = getSchema(catalog, 
params.schemaName());
 
             if (schema.table(params.tableName()) != null) {
-                throw new TableAlreadyExistsException(schemaName, 
params.tableName());
+                throw new TableAlreadyExistsException(schema.name(), 
params.tableName());
             }
 
-            
params.columns().stream().map(ColumnParams::name).filter(Predicate.not(new 
HashSet<>()::add))
-                    .findAny().ifPresent(columnName -> {
-                        throw new IgniteInternalException(
-                                
ErrorGroups.Index.INVALID_INDEX_DEFINITION_ERR, "Can't create table with 
duplicate columns: "
-                                + 
params.columns().stream().map(ColumnParams::name).collect(Collectors.joining(", 
"))
-                        );
-                    });
+            validateParams(params);
+
+            CatalogZoneDescriptor zone = getZone(catalog, 
Objects.requireNonNullElse(params.zone(), DEFAULT_ZONE_NAME));
 
-            String zoneName = Objects.requireNonNullElse(params.zone(), 
CatalogService.DEFAULT_ZONE_NAME);
+            int id = catalog.objectIdGenState();
 
-            CatalogZoneDescriptor zone = 
Objects.requireNonNull(catalog.zone(zoneName), "No zone found: " + zoneName);
+            CatalogTableDescriptor table = CatalogUtils.fromParams(id++, 
zone.id(), params);
 
-            CatalogTableDescriptor table = 
CatalogUtils.fromParams(catalog.objectIdGenState(), zone.id(), params);
+            CatalogHashIndexDescriptor pkIndex = 
createHashIndexDescriptor(createPkIndexParams(params), table, id++);
 
             return List.of(
                     new NewTableEntry(table),
-                    new ObjectIdGenUpdateEntry(1)
+                    new NewIndexEntry(pkIndex),
+                    new ObjectIdGenUpdateEntry(id - catalog.objectIdGenState())
             );
         });
     }
 
-    /** {@inheritDoc} */
     @Override
     public CompletableFuture<Void> dropTable(DropTableParams params) {
         return saveUpdate(catalog -> {
-            String schemaName = 
Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
-
-            CatalogSchemaDescriptor schema = 
Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " + 
schemaName);
+            CatalogSchemaDescriptor schema = getSchema(catalog, 
params.schemaName());
 
-            CatalogTableDescriptor table = schema.table(params.tableName());
-
-            if (table == null) {
-                throw new TableNotFoundException(schemaName, 
params.tableName());
-            }
+            CatalogTableDescriptor table = getTable(schema, 
params.tableName());
 
             List<UpdateEntry> updateEntries = new ArrayList<>();
 
             Arrays.stream(schema.indexes())
                     .filter(index -> index.tableId() == table.id())
-                    .forEach(index -> updateEntries.add(new 
DropIndexEntry(index.id())));
+                    .forEach(index -> updateEntries.add(new 
DropIndexEntry(index.id(), index.tableId())));

Review Comment:
   Made a separate ticket for this 
https://issues.apache.org/jira/browse/IGNITE-19798



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