You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2023/01/10 10:09:50 UTC

[GitHub] [ignite-3] xtern commented on a diff in pull request #1477: IGNITE-18141 Added ability to bind tables with distribution zones on table creation.

xtern commented on code in PR #1477:
URL: https://github.com/apache/ignite-3/pull/1477#discussion_r1065571895


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/ddl/DdlCommandHandlerExceptionHandlingTest.java:
##########
@@ -89,8 +97,21 @@ void before() {
 
         DistributionZonesConfiguration zonesConfiguration = registry.getConfiguration(DistributionZonesConfiguration.KEY);
 
+        TablesConfiguration tablesConfiguration = mock(TablesConfiguration.class);
+
+        NamedConfigurationTree<TableConfiguration, TableView, TableChange> tables = mock(NamedConfigurationTree.class);
+
+        when(tablesConfiguration.tables()).thenReturn(tables);
+
+        NamedListView<TableView> value = mock(NamedListView.class);
+
+        when(tables.value()).thenReturn(value);
+
+        when(value.namedListKeys()).thenReturn(new ArrayList<>());
+
         distributionZoneManager = new DistributionZoneManager(
                 zonesConfiguration,
+                tablesConfiguration,

Review Comment:
   ```suggestion
                   null,
   ```
   Can you see the difference in test behavior without the `tableConfiguration` mock?



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/DdlSqlToCommandConverter.java:
##########
@@ -132,6 +133,7 @@ public DdlSqlToCommandConverter(
 
         this.tableOptionInfos = Map.of(
                 REPLICAS.name(), new DdlOptionInfo<>(Integer.class, this::checkPositiveNumber, CreateTableCommand::replicas),
+                PRIMARY_ZONE.name(), new DdlOptionInfo<>(String.class, null, CreateTableCommand::zone),
                 PARTITIONS.name(), new DdlOptionInfo<>(Integer.class, this::checkPositiveNumber, CreateTableCommand::partitions)
         );

Review Comment:
   ```suggestion
           this.tableOptionInfos = Map.of(
                   "PRIMARY_ZONE", new DdlOptionInfo<>(String.class, null, CreateTableCommand::zone),
                   REPLICAS.name(), new DdlOptionInfo<>(Integer.class, this::checkPositiveNumber, CreateTableCommand::replicas),
                   PARTITIONS.name(), new DdlOptionInfo<>(Integer.class, this::checkPositiveNumber, CreateTableCommand::partitions)
           );
   ```



##########
modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/exception/DistributionZoneBindTableException.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.distributionzones.exception;
+
+import static org.apache.ignite.lang.ErrorGroups.DistributionZones.ZONE_BIND_TABLE_ERR;
+
+import java.util.UUID;
+import org.apache.ignite.lang.IgniteInternalException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Exception is thrown when the distribution zone cannot be dropped because there is a table bound to the distribution zone.
+ */
+public class DistributionZoneBindTableException extends IgniteInternalException {
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     */
+    public DistributionZoneBindTableException(String zoneName) {
+        this(zoneName, null);
+    }
+
+    /**
+     * The constructor.
+     *
+     * @param zoneName Zone name.
+     * @param cause Optional nested exception (can be {@code null}).
+     */
+    public DistributionZoneBindTableException(String zoneName, @Nullable Throwable cause) {
+        super(ZONE_BIND_TABLE_ERR, "Distribution zone is assigned to the table [zoneName=" + zoneName + ']', cause);

Review Comment:
   I don't insist, but I would also suggest listing all the related tables in the exception message. It seems that this may make life easier for someone in the future.



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlCreateTableOptionEnum.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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.sql.engine.sql;
+
+/**
+ * Enumerates the options for CREATE TABLE statement.
+ */
+public enum IgniteSqlCreateTableOptionEnum {
+    /** Distribution zone. */
+    PRIMARY_ZONE

Review Comment:
   Personally, it seems to me that it is not worth creating this enumerator yet.
   When we remove unnecessary options for creating a table (partitions, replicas, etc.), we will probably do refactoring and, if necessary, add such an enum.



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/ddl/CreateTableCommand.java:
##########
@@ -164,4 +167,20 @@ public void addDataStorageOption(String name, Object value) {
 
         dataStorageOptions.put(name, value);
     }
+
+    /**
+     * Get zone name.
+     */
+    @Nullable
+    public String zone() {
+        return zone;
+    }
+
+    /**
+     * Set zone name.
+     */
+    @Nullable

Review Comment:
   do not forget to remove



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