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


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/fsm/DdlBatchingHelper.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.exec.fsm;
+
+import org.apache.calcite.sql.SqlNode;
+import org.apache.ignite.internal.sql.engine.sql.ParsedResult;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ *  Provide helper methods for batched DDL commands.
+ */
+public class DdlBatchingHelper {
+    /**
+     * Returns {@code true} if given statement is compatible with script 
statement.
+     * Node: the operation is not commutative.
+     */
+    static boolean isCompatible(ParsedResult scriptStatement, ParsedResult 
statement) {
+        @Nullable DdlBatchGroup batchGroup = scriptStatement.ddlBatchGroup();
+        @Nullable DdlBatchGroup statementGroup = statement.ddlBatchGroup();
+
+        if (batchGroup == null || statementGroup == null) {
+            // Actually, we should never get here, but If we missed smth, it 
is always safe to fallback to non-batched execution.
+            assert false : "DDL statement should be batch aware.";
+
+            return false;
+        }
+
+        return isCompatible(batchGroup, statementGroup);
+    }
+
+    /**
+     * Returns {@code true} if node group is compatible with batch group
+     * Node: the operation is not commutative.
+     */
+    static boolean isCompatible(DdlBatchGroup batchGroup, DdlBatchGroup 
nodeGroup) {
+        return (batchGroup != DdlBatchGroup.OTHER // OTHER group doesn't 
support batching.
+                && batchGroup == nodeGroup) // Groups matched.
+                || batchGroup == DdlBatchGroup.DROP;
+    }
+
+    /** Returns command kind or {@code null} if command is not batch aware. */

Review Comment:
   ```suggestion
       /** Returns command kind or {@code null} if command is not {@link 
DdlBatchAware batch aware}. */
   ```



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/ParsedResult.java:
##########
@@ -43,6 +45,17 @@ public interface ParsedResult {
     /** Returns the count of the dynamic params (specified by question marks 
in the query text) used in the query. */
     int dynamicParamsCount();
 
-    /** Returns the syntax tree of the query according to the grammar rules. */
+    /**
+     * Returns the syntax tree of the query according to the grammar rules for 
planning purposes.
+     *
+     * <p>Note: Each call should return new tree instance.
+     */
     SqlNode parsedTree();
+
+    /**
+     * Returns {@link 
org.apache.ignite.internal.sql.engine.exec.fsm.DdlBatchGroup} for batching 
purposes or {@code null} if unapplicable.

Review Comment:
   ```suggestion
        * Returns {@link DdlBatchGroup} for batching purposes or {@code null} 
if not applicable.
   ```



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/fsm/DdlBatchGroup.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.sql.engine.exec.fsm;
+
+/**
+ * Groups tha is used for DDL operations batching.

Review Comment:
   ```suggestion
    * Groups that is used for DDL operations batching.
   ```



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/ParserServiceImpl.java:
##########
@@ -164,19 +170,26 @@ static class ParsedResultImpl implements ParsedResult {
         private final String normalizedQuery;
         private final int dynamicParamCount;
         private final Supplier<SqlNode> parsedTreeSupplier;
+        private final DdlBatchGroup ddlBatchGroup;

Review Comment:
   ```suggestion
           private final @Nullable DdlBatchGroup ddlBatchGroup;
   ```



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/ParserServiceImpl.java:
##########
@@ -203,6 +216,12 @@ public int dynamicParamsCount() {
             return dynamicParamCount;
         }
 
+        /** {@inheritDoc} */
+        @Override
+        public DdlBatchGroup ddlBatchGroup() {

Review Comment:
   ```suggestion
           public @Nullable DdlBatchGroup ddlBatchGroup() {
   ```



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/fsm/DdlBatchingHelper.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.exec.fsm;
+
+import org.apache.calcite.sql.SqlNode;
+import org.apache.ignite.internal.sql.engine.sql.ParsedResult;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ *  Provide helper methods for batched DDL commands.
+ */
+public class DdlBatchingHelper {
+    /**
+     * Returns {@code true} if given statement is compatible with script 
statement.
+     * Node: the operation is not commutative.
+     */
+    static boolean isCompatible(ParsedResult scriptStatement, ParsedResult 
statement) {

Review Comment:
   tbh parameter names are confusing. In `MultiStatementHandler` we pass 
`currentStatement` and `nextStatement` as input, but semantically we need to 
check if two arbitrary statements are compatible. 
   
   Let's rename to something like thisStatement-thatStatement or 
statement1-statement2 or whatever neutral. Similar with batchGroup



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