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


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlZoneOptionV2.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.util.Litmus;
+import org.apache.ignite.internal.sql.engine.prepare.ddl.ZoneOptionEnum;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+/** An AST node representing option in CREATE ZONE statement. */
+public class IgniteSqlZoneOptionV2 extends IgniteSqlZoneOption {

Review Comment:
   I don't think we need second implementation of `ZoneOption`. They are almost 
identical



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlCreateZoneV2.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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;
+
+import java.util.List;
+import java.util.Objects;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlCreate;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlLiteral;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.SqlWriter.FrameTypeEnum;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.util.ImmutableNullableList;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Parse tree for {@code CREATE ZONE} statement with Ignite specific features.
+ */
+public class IgniteSqlCreateZoneV2 extends SqlCreate {

Review Comment:
   we don't need second implementation of `CreateZone` either



##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/sql/DistributionZoneSqlDdlParserTest.java:
##########
@@ -48,48 +48,89 @@ public class DistributionZoneSqlDdlParserTest extends 
AbstractParserTest {
     @Test
     public void createZoneNoOptions() {
         // Simple name.
-        IgniteSqlCreateZone createZone = parseCreateZone("create zone 
test_zone");
+        IgniteSqlCreateZoneV2 createZone = parseCreateZoneV2("create zone 
test_zone storage profiles['p']");
 
         assertThat(createZone.name().names, is(List.of("TEST_ZONE")));
         assertFalse(createZone.ifNotExists());
         assertNull(createZone.createOptionList());
-        expectUnparsed(createZone, "CREATE ZONE \"TEST_ZONE\"");
+        expectUnparsed(createZone, "CREATE ZONE \"TEST_ZONE\" \"STORAGE 
PROFILES\"['p']");
 
         // Fully qualified name.
-        createZone = parseCreateZone("create zone public.test_zone");
+        createZone = parseCreateZoneV2("create zone public.test_zone storage 
profiles['p']");
         assertThat(createZone.name().names, is(List.of("PUBLIC", 
"TEST_ZONE")));
-        expectUnparsed(createZone, "CREATE ZONE \"PUBLIC\".\"TEST_ZONE\"");
+        expectUnparsed(createZone, "CREATE ZONE \"PUBLIC\".\"TEST_ZONE\" 
\"STORAGE PROFILES\"['p']");
 
         // Quoted identifier.
-        createZone = parseCreateZone("create zone \"public\".\"test_Zone\"");
+        createZone = parseCreateZoneV2("create zone \"public\".\"test_Zone\" 
storage profiles['p']");
         assertThat(createZone.name().names, is(List.of("public", 
"test_Zone")));
-        expectUnparsed(createZone, "CREATE ZONE \"public\".\"test_Zone\"");
+        expectUnparsed(createZone, "CREATE ZONE \"public\".\"test_Zone\" 
\"STORAGE PROFILES\"['p']");
 
-        createZone = parseCreateZone("create zone \"public-test_Zone\"");
+        createZone = parseCreateZoneV2("create zone \"public-test_Zone\" 
storage profiles['p']");
         assertThat(createZone.name().names, is(List.of("public-test_Zone")));
-        expectUnparsed(createZone, "CREATE ZONE \"public-test_Zone\"");
+        expectUnparsed(createZone, "CREATE ZONE \"public-test_Zone\" \"STORAGE 
PROFILES\"['p']");
     }
 
     /**
      * Parse CREATE ZONE IF NOT EXISTS statement.
      */
     @Test
     public void createZoneIfNotExists() {
-        IgniteSqlCreateZone createZone = parseCreateZone("create zone if not 
exists test_zone");
+        IgniteSqlCreateZoneV2 createZone = parseCreateZoneV2("create zone if 
not exists test_zone storage profiles['p']");
 
         assertTrue(createZone.ifNotExists());
         assertNull(createZone.createOptionList());
 
-        expectUnparsed(createZone, "CREATE ZONE IF NOT EXISTS \"TEST_ZONE\"");
+        expectUnparsed(createZone, "CREATE ZONE IF NOT EXISTS \"TEST_ZONE\" 
\"STORAGE PROFILES\"['p']");
+    }
+
+    @Test
+    public void createZoneWithOptions() {
+        IgniteSqlCreateZoneV2 createZone = parseCreateZoneV2(
+                "create zone test_zone "
+                        + "(replicas 2, "
+                        + "partitions 3, "
+                        + "nodes filter '(\"US\" || \"EU\") && \"SSD\"', "
+                        + "distribution algorithm 'test_Distribution', "
+                        + "auto adjust 1, "
+                        + "auto scale up 2, "
+                        + "auto scale down 3, "
+                        + "consistency mode 'HIGH_AVAILABILITY') "
+                        + "storage profiles ['default', 'new']"
+        );
+
+        assertNotNull(createZone.createOptionList());
+
+        List<SqlNode> optList = createZone.createOptionList().getList();
+
+        assertThatZoneOptionPresent(optList, ZoneOptionEnum.REPLICAS, 2);
+        assertThatZoneOptionPresent(optList, ZoneOptionEnum.PARTITIONS, 3);
+        assertThatZoneOptionPresent(optList, 
ZoneOptionEnum.DISTRIBUTION_ALGORITHM, "test_Distribution");
+        assertThatZoneOptionPresent(optList, ZoneOptionEnum.DATA_NODES_FILTER, 
"(\"US\" || \"EU\") && \"SSD\"");
+        assertThatZoneOptionPresent(optList, 
ZoneOptionEnum.DATA_NODES_AUTO_ADJUST, 1);
+        assertThatZoneOptionPresent(optList, 
ZoneOptionEnum.DATA_NODES_AUTO_ADJUST_SCALE_UP, 2);
+        assertThatZoneOptionPresent(optList, 
ZoneOptionEnum.DATA_NODES_AUTO_ADJUST_SCALE_DOWN, 3);
+        assertThatZoneOptionPresent(optList, ZoneOptionEnum.CONSISTENCY_MODE, 
"HIGH_AVAILABILITY");
+
+        expectUnparsed(createZone, "CREATE ZONE \"TEST_ZONE\" ("
+                + "\"REPLICAS\" 2, "
+                + "\"PARTITIONS\" 3, "
+                + "\"NODES FILTER\" '(\"US\" || \"EU\") && \"SSD\"', "

Review Comment:
   `unparse` must return string representation of AST, i.e. you should be able 
to parse result of unparse, and the resulting AST must be equal to original one



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