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


##########
modules/client-handler/src/testFixtures/java/org/apache/ignite/client/handler/FakeCatalogService.java:
##########
@@ -161,6 +161,11 @@ public CompletableFuture<Void> catalogReadyFuture(int 
version) {
         return null;
     }
 
+    @Override
+    public CompletableFuture<Void> catalogInitializationFuture() {
+        return null;

Review Comment:
   it's better to either return completed future or throw an exception



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateSchemaCommand.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog.commands;
+
+import java.util.List;
+import org.apache.ignite.internal.catalog.Catalog;
+import org.apache.ignite.internal.catalog.CatalogCommand;
+import org.apache.ignite.internal.catalog.CatalogValidationException;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
+import org.apache.ignite.internal.catalog.descriptors.CatalogSchemaDescriptor;
+import 
org.apache.ignite.internal.catalog.descriptors.CatalogSystemViewDescriptor;
+import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor;
+import org.apache.ignite.internal.catalog.storage.NewSchemaEntry;
+import org.apache.ignite.internal.catalog.storage.ObjectIdGenUpdateEntry;
+import org.apache.ignite.internal.catalog.storage.UpdateEntry;
+
+/**
+ * Command to create a new schema.
+ */
+public class CreateSchemaCommand implements CatalogCommand {
+
+    private final String schemaName;
+
+    private CreateSchemaCommand(String schemaName) {
+        this.schemaName = schemaName;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public List<UpdateEntry> get(Catalog catalog) {
+        int id = catalog.objectIdGenState();
+
+        if (schemaName == null) {
+            throw new CatalogValidationException("Schema name is null");
+        }
+
+        CatalogSchemaDescriptor schema = new CatalogSchemaDescriptor(
+                id,
+                schemaName,
+                new CatalogTableDescriptor[0],
+                new CatalogIndexDescriptor[0],
+                new CatalogSystemViewDescriptor[0],
+                0
+        );
+
+        return List.of(
+                new NewSchemaEntry(schema),
+                new ObjectIdGenUpdateEntry(1)
+                );

Review Comment:
   ```suggestion
           );
   ```



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateSchemaCommand.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog.commands;
+
+import java.util.List;
+import org.apache.ignite.internal.catalog.Catalog;
+import org.apache.ignite.internal.catalog.CatalogCommand;
+import org.apache.ignite.internal.catalog.CatalogValidationException;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
+import org.apache.ignite.internal.catalog.descriptors.CatalogSchemaDescriptor;
+import 
org.apache.ignite.internal.catalog.descriptors.CatalogSystemViewDescriptor;
+import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor;
+import org.apache.ignite.internal.catalog.storage.NewSchemaEntry;
+import org.apache.ignite.internal.catalog.storage.ObjectIdGenUpdateEntry;
+import org.apache.ignite.internal.catalog.storage.UpdateEntry;
+
+/**
+ * Command to create a new schema.
+ */
+public class CreateSchemaCommand implements CatalogCommand {
+
+    private final String schemaName;
+
+    private CreateSchemaCommand(String schemaName) {
+        this.schemaName = schemaName;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public List<UpdateEntry> get(Catalog catalog) {
+        int id = catalog.objectIdGenState();
+
+        if (schemaName == null) {
+            throw new CatalogValidationException("Schema name is null");

Review Comment:
   we also have to check for schemas with similar name



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/NewSchemaEntry.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog.storage;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.ignite.internal.catalog.Catalog;
+import org.apache.ignite.internal.catalog.descriptors.CatalogSchemaDescriptor;
+import 
org.apache.ignite.internal.catalog.storage.serialization.CatalogObjectSerializer;
+import 
org.apache.ignite.internal.catalog.storage.serialization.MarshallableEntryType;
+import org.apache.ignite.internal.util.io.IgniteDataInput;
+import org.apache.ignite.internal.util.io.IgniteDataOutput;
+
+/**
+ * New schema entry.
+ */
+public class NewSchemaEntry implements UpdateEntry {
+    public static final CatalogObjectSerializer<NewSchemaEntry> SERIALIZER = 
new Serializer();
+
+    private final CatalogSchemaDescriptor descriptor;
+
+    public NewSchemaEntry(CatalogSchemaDescriptor descriptor) {
+        this.descriptor = descriptor;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public Catalog applyUpdate(Catalog catalog, long causalityToken) {
+        CatalogSchemaDescriptor schema = catalog.schema(descriptor.name());
+        if (schema != null) {
+            return catalog;
+        }

Review Comment:
   this should not happen. It's better to throw assertion here



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateSchemaCommandBuilder.java:
##########
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog.commands;
+
+import org.apache.ignite.internal.catalog.CatalogCommand;
+
+/**
+ * Builder for a {@link CreateSchemaCommand}.
+ */
+public interface CreateSchemaCommandBuilder {
+
+    /** Sets schema name. */

Review Comment:
   let's provide restrictions applied to `name` argument



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CreateSchemaCommand.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog.commands;
+
+import java.util.List;
+import org.apache.ignite.internal.catalog.Catalog;
+import org.apache.ignite.internal.catalog.CatalogCommand;
+import org.apache.ignite.internal.catalog.CatalogValidationException;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
+import org.apache.ignite.internal.catalog.descriptors.CatalogSchemaDescriptor;
+import 
org.apache.ignite.internal.catalog.descriptors.CatalogSystemViewDescriptor;
+import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor;
+import org.apache.ignite.internal.catalog.storage.NewSchemaEntry;
+import org.apache.ignite.internal.catalog.storage.ObjectIdGenUpdateEntry;
+import org.apache.ignite.internal.catalog.storage.UpdateEntry;
+
+/**
+ * Command to create a new schema.
+ */
+public class CreateSchemaCommand implements CatalogCommand {
+
+    private final String schemaName;
+
+    private CreateSchemaCommand(String schemaName) {
+        this.schemaName = schemaName;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public List<UpdateEntry> get(Catalog catalog) {
+        int id = catalog.objectIdGenState();
+
+        if (schemaName == null) {

Review Comment:
   common patter is to validate identifiers in constructor. See 
AbstractTableCommand for example. Also, let's add validation test for this 
command (see CreateTableCommandValidationTest for example)



##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/storage/serialization/CatalogEntrySerializerProvider.java:
##########
@@ -81,6 +82,7 @@ public interface CatalogEntrySerializerProvider {
             serializers[MarshallableEntryType.SET_DEFAULT_ZONE.id()] = 
SetDefaultZoneEntry.SERIALIZER;
             //noinspection ThisEscapedInObjectConstruction
             serializers[MarshallableEntryType.VERSIONED_UPDATE.id()] = new 
VersionedUpdateSerializer(this);
+            serializers[MarshallableEntryType.NEW_SCHEMA.id()] = 
NewSchemaEntry.SERIALIZER;

Review Comment:
   please move it above MarshallableEntryType.VERSIONED_UPDATE



-- 
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-unsubscr...@ignite.apache.org

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

Reply via email to