You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "tkalkirill (via GitHub)" <gi...@apache.org> on 2023/06/09 09:32:11 UTC

[GitHub] [ignite-3] tkalkirill commented on a diff in pull request #2094: IGNITE-18537 Add add/drop distribution zone DDL commands

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


##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/Catalog.java:
##########
@@ -63,25 +66,33 @@ public Catalog(
             long activationTimestamp,
             int objectIdGen,
             Collection<CatalogZoneDescriptor> zones,
-            CatalogSchemaDescriptor... schemas
+            Collection<CatalogSchemaDescriptor> schemas
     ) {
         this.version = version;
         this.activationTimestamp = activationTimestamp;
         this.objectIdGen = objectIdGen;
 
         Objects.requireNonNull(schemas, "schemas");
+        Objects.requireNonNull(zones, "zones");
 
-        assert schemas.length > 0 : "No schemas found";
-        assert Arrays.stream(schemas).allMatch(t -> t.version() == version) : "Invalid schema version";
+        this.schemasByName = schemas.stream().collect(Collectors.toUnmodifiableMap(CatalogSchemaDescriptor::name, t -> t));
+        this.zonesByName = zones.stream().collect(Collectors.toUnmodifiableMap(CatalogZoneDescriptor::name, t -> t));
 
-        this.schemas = Arrays.stream(schemas).collect(Collectors.toUnmodifiableMap(CatalogSchemaDescriptor::name, t -> t));
-        this.zones = zones.stream().collect(Collectors.toUnmodifiableMap(CatalogZoneDescriptor::name, t -> t));
+        tablesById = schemas.stream().flatMap(s -> Arrays.stream(s.tables()))
+                .collect(intMapCollector(CatalogObjectDescriptor::id, Function.identity()));
+        indexesById = schemas.stream().flatMap(s -> Arrays.stream(s.indexes()))
+                .collect(intMapCollector(CatalogObjectDescriptor::id, Function.identity()));
+        zonesById = zones.stream()
+                .collect(intMapCollector(CatalogObjectDescriptor::id, Function.identity()));
+    }
 
-        tablesMap = Arrays.stream(schemas).flatMap(s -> Arrays.stream(s.tables()))
-                .collect(Collectors.toUnmodifiableMap(CatalogObjectDescriptor::id, Function.identity()));
-        indexesMap = Arrays.stream(schemas).flatMap(s -> Arrays.stream(s.indexes()))
-                .collect(Collectors.toUnmodifiableMap(CatalogObjectDescriptor::id, Function.identity()));
-        zonesMap = zones.stream().collect(Collectors.toUnmodifiableMap(CatalogZoneDescriptor::id, t -> t));
+    private static <T, V> Collector<T, ?, Int2ObjectArrayMap<V>> intMapCollector(

Review Comment:
   Maybe move to **org.apache.ignite.internal.util.CollectionUtils** ?



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org