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


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/QueryPlan.java:
##########
@@ -29,6 +31,11 @@ enum Type {
         QUERY, FRAGMENT, DML, DDL, EXPLAIN
     }
 
+    /**
+     * All plan type except for {@code FRAGMENT}.
+     */
+    Set<Type> TOP_LEVEL_TYPES = EnumSet.of(Type.QUERY, Type.DDL, Type.DML, 
Type.EXPLAIN);

Review Comment:
   perhaps, it would be better to remove FRAGMENT type at all



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/SqlQueryProcessor.java:
##########
@@ -401,12 +407,14 @@ private CompletableFuture<AsyncSqlCursor<List<Object>>> 
querySingle0(
 
         CompletableFuture<AsyncSqlCursor<List<Object>>> stage = start
                 .thenApply(v -> {
-                    var nodes = Commons.parse(sql, Commons.PARSER_CONFIG);
+                    var nodes = IgniteSqlParser.parse(sql);

Review Comment:
   could you please also replace `var` with actual type? It's not allowed in 
such context



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlParser.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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 static org.apache.ignite.internal.util.ExceptionUtils.withCauseAndCode;
+import static org.apache.ignite.lang.ErrorGroup.extractCauseMessage;
+import static org.apache.ignite.lang.ErrorGroups.Sql.QUERY_INVALID_ERR;
+
+import java.io.Reader;
+import org.apache.calcite.config.Lex;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.parser.SqlAbstractParserImpl;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.SqlParserImplFactory;
+import org.apache.calcite.util.SourceStringReader;
+import 
org.apache.ignite.internal.generated.query.calcite.sql.IgniteSqlParserImpl;
+import org.apache.ignite.sql.SqlException;
+
+/**
+ * Implementation of SQL parser.
+ */
+public final class IgniteSqlParser extends IgniteSqlParserImpl {

Review Comment:
   do we really want to expose extended parser? I would prefer to hide it 
inside of IgniteSqlParser as a private static class. The same with FACTORY. In 
that case we will have the only possible way to use new parser - through static 
methods `parse` as it meant to be used.
   
   Secondly, what do you think about separating two different cases (single 
statement vs script) in parser as well? This let us avoid annoying validation 
of size of the returned nodeLIst every time. But we need to change API a bit: 
instead of IgniteSqlScriptNode extension we need to introduce ParsedResult 
encapsulating root of AST and count of dynamic parameters. As for now, code 
like below looks very confusing:
   
   ```                    
                       if (nodes.size() > 1) {
                           throw new SqlException(QUERY_INVALID_ERR, "Multiple 
statements aren't allowed.");
                       }
   
                       validateParsedStatement(context, nodes, nodes.get(0), 
params);
   
                       return nodes.get(0);
   ```



##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ClusterPerClassIntegrationTest.java:
##########
@@ -411,7 +412,7 @@ protected static List<List<Object>> sql(@Nullable 
Transaction tx, String sql, Ob
         ));
 
         try {
-            var context = tx != null ? QueryContext.of(tx) : QueryContext.of();
+            var context =  QueryContext.create(QueryPlan.TOP_LEVEL_TYPES, tx);

Review Comment:
   extra space before `QueryContext`



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/Commons.java:
##########
@@ -805,4 +762,42 @@ public static String shortRuleName(RelOptRule rule) {
 
         return ruleDescription.substring(0, pos);
     }
+
+    /**
+     * Returns a {@link QueryPlan.Type} for the given {@link SqlNode}.
+     * If the given node is neither {@code QUERY}, nor {@code DDL}, nor {@code 
DML}, this method returns {@code null}.

Review Comment:
   ```suggestion
        * 
        * <p>If the given node is neither {@code QUERY}, nor {@code DDL}, nor 
{@code DML}, this method returns {@code null}.
   ```



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/SqlQueryProcessor.java:
##########
@@ -664,4 +679,29 @@ public CompletableFuture<Boolean> notify(@NotNull 
IndexEventParameters parameter
     private static boolean dataModificationOp(SqlNode sqlNode) {
         return SqlKind.DML.contains(sqlNode.getKind());
     }
+
+    /** Performs additional validation of a parsed statement. **/
+    private static void validateParsedStatement(QueryContext context, 
IgniteSqlScriptNode nodes, SqlNode node, Object[] params) {
+        var allowedTypes = context.allowedQueryTypes();

Review Comment:
   'var' is not allowed in this context. Please refer to 
[this](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide#JavaCodeStyleGuide-3Usingvarkeyword)
 page for details 



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