You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/10/26 04:34:41 UTC

[GitHub] [shardingsphere] terrymanu commented on a change in pull request #7914: Refactor StandardSQLParserEngine and cacheEngine

terrymanu commented on a change in pull request #7914:
URL: https://github.com/apache/shardingsphere/pull/7914#discussion_r511710090



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/cache/SQLParsedResultCaches.java
##########
@@ -15,38 +15,36 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.sql.parser.engine.ast;
+package org.apache.shardingsphere.sql.parser.cache;
 
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorType;
 
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
- * AST SQL parser engine factory.
+ * SQL Parsed result caches.

Review comment:
       `Parsed` should be lower case

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/engine/SQLParserEngine.java
##########
@@ -17,17 +17,19 @@
 
 package org.apache.shardingsphere.sql.parser.engine;
 
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
 /**
- * SQL parser engine.
+ * Statement SQL parser engine.
  */
-public interface SQLParserEngine<T> {
+public interface SQLParserEngine {
     
     /**
-     * Parse SQL.
-     *
-     * @param sql SQL
-     * @param useCache use cache or not
-     * @return T
+     * Parse to SQL Statement.
+     * 
+     * @param sql sql 
+     * @param useCache use cache
+     * @return sql statement

Review comment:
       `sql` should be upper case

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/engine/SQLParserEngine.java
##########
@@ -17,17 +17,19 @@
 
 package org.apache.shardingsphere.sql.parser.engine;
 
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
 /**
- * SQL parser engine.
+ * Statement SQL parser engine.
  */
-public interface SQLParserEngine<T> {
+public interface SQLParserEngine {
     
     /**
-     * Parse SQL.
-     *
-     * @param sql SQL
-     * @param useCache use cache or not
-     * @return T
+     * Parse to SQL Statement.
+     * 
+     * @param sql sql 

Review comment:
       `sql` should be upper case

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/engine/standard/StandardSQLParserEngine.java
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.shardingsphere.sql.parser.engine.standard;
+
+import lombok.RequiredArgsConstructor;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.antlr.v4.runtime.tree.ParseTreeVisitor;
+import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorType;
+import org.apache.shardingsphere.sql.parser.cache.SQLParsedResultCaches;
+import org.apache.shardingsphere.sql.parser.core.parser.SQLParserExecutor;
+import org.apache.shardingsphere.sql.parser.core.visitor.SQLVisitorFactory;
+import org.apache.shardingsphere.sql.parser.core.visitor.SQLVisitorRule;
+import org.apache.shardingsphere.sql.parser.cache.SQLParsedResultCache;
+import org.apache.shardingsphere.sql.parser.engine.SQLParserEngine;
+import org.apache.shardingsphere.sql.parser.hook.ParsingHookRegistry;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.Optional;
+
+/**
+ * Standard SQL parser engine.
+ */
+@RequiredArgsConstructor
+public final class StandardSQLParserEngine implements SQLParserEngine {
+    
+    private final String databaseTypeName;
+    
+    private final SQLParsedResultCaches caches = new SQLParsedResultCaches();
+    
+    private final ParsingHookRegistry parsingHookRegistry = ParsingHookRegistry.getInstance();
+    
+    /**
+     * Parse to AST.
+     * @param sql sql 
+     * @param useCache user cache
+     * @return parse tree
+     */
+    public ParseTree parseToAST(final String sql, final boolean useCache) {
+        Optional<ParseTree> parseTree = getCache(sql, useCache, SQLVisitorType.FORMAT);
+        if (parseTree.isPresent()) {
+            return parseTree.get();
+        }
+        ParseTree result = parse0(sql);
+        putCache(sql, result, useCache, SQLVisitorType.FORMAT);
+        return result;
+    }
+    
+    // TODO check skywalking plugin
+    /**
+     * To make sure SkyWalking will be available at the next release of ShardingSphere,
+     * a new plugin should be provided to SkyWalking project if this API changed.
+     *
+     * @see <a href="https://github.com/apache/skywalking/blob/master/docs/en/guides/Java-Plugin-Development-Guide.md#user-content-plugin-development-guide">Plugin Development Guide</a>
+     */
+    @Override
+    public SQLStatement parseToSQLStatement(final String sql, final boolean useCache) {
+        parsingHookRegistry.start(sql);
+        try {
+            SQLStatement result = parseToSQLStatement0(sql, useCache);
+            parsingHookRegistry.finishSuccess(result);
+            return result;
+            // CHECKSTYLE:OFF
+        } catch (final Exception ex) {
+            // CHECKSTYLE:ON
+            parsingHookRegistry.finishFailure(ex);
+            throw ex;
+        }
+    }
+    
+    /**
+     * Parse.
+     *
+     * @param sql sql

Review comment:
       `sql` should be upper case

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/engine/SQLParserEngine.java
##########
@@ -17,17 +17,19 @@
 
 package org.apache.shardingsphere.sql.parser.engine;
 
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
 /**
- * SQL parser engine.
+ * Statement SQL parser engine.
  */
-public interface SQLParserEngine<T> {
+public interface SQLParserEngine {
     
     /**
-     * Parse SQL.
-     *
-     * @param sql SQL
-     * @param useCache use cache or not
-     * @return T
+     * Parse to SQL Statement.
+     * 
+     * @param sql sql 
+     * @param useCache use cache

Review comment:
       It is better to change java doc `use cache` to `whether use cache`

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/engine/standard/StandardSQLParserEngine.java
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.shardingsphere.sql.parser.engine.standard;
+
+import lombok.RequiredArgsConstructor;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.antlr.v4.runtime.tree.ParseTreeVisitor;
+import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorType;
+import org.apache.shardingsphere.sql.parser.cache.SQLParsedResultCaches;
+import org.apache.shardingsphere.sql.parser.core.parser.SQLParserExecutor;
+import org.apache.shardingsphere.sql.parser.core.visitor.SQLVisitorFactory;
+import org.apache.shardingsphere.sql.parser.core.visitor.SQLVisitorRule;
+import org.apache.shardingsphere.sql.parser.cache.SQLParsedResultCache;
+import org.apache.shardingsphere.sql.parser.engine.SQLParserEngine;
+import org.apache.shardingsphere.sql.parser.hook.ParsingHookRegistry;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.Optional;
+
+/**
+ * Standard SQL parser engine.
+ */
+@RequiredArgsConstructor
+public final class StandardSQLParserEngine implements SQLParserEngine {
+    
+    private final String databaseTypeName;
+    
+    private final SQLParsedResultCaches caches = new SQLParsedResultCaches();
+    
+    private final ParsingHookRegistry parsingHookRegistry = ParsingHookRegistry.getInstance();
+    
+    /**
+     * Parse to AST.
+     * @param sql sql 

Review comment:
       `sql` should be upper case




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

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