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 2021/05/18 09:56:34 UTC

[GitHub] [shardingsphere] strongduanmu opened a new pull request #10377: extract abstract explain statement & support postgresql explain statement

strongduanmu opened a new pull request #10377:
URL: https://github.com/apache/shardingsphere/pull/10377


   Ref #10368.
   
   Changes proposed in this pull request:
   - rename mysql describe to explain
   - extract abstract explain statement
   - support postgresql explain statement
   - correct mysql explain statement


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



[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #10377: extract abstract explain statement & support postgresql explain statement

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #10377:
URL: https://github.com/apache/shardingsphere/pull/10377#discussion_r634273477



##########
File path: shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dal/ExplainStatementContext.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.infra.binder.statement.dal;
+
+import lombok.Getter;
+import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
+import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
+import org.apache.shardingsphere.infra.binder.type.TableAvailable;
+import org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ExplainStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.handler.dal.ExplainStatementHandler;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * Explain statement context.
+ */
+@Getter
+public final class ExplainStatementContext extends CommonSQLStatementContext<ExplainStatement> implements TableAvailable {
+    
+    private final TablesContext tablesContext;
+    
+    public ExplainStatementContext(final ExplainStatement sqlStatement) {
+        super(sqlStatement);
+        tablesContext = new TablesContext(extractTablesFromExplain(sqlStatement));
+    }
+    
+    private Collection<SimpleTableSegment> extractTablesFromExplain(final ExplainStatement sqlStatement) {
+        Collection<SimpleTableSegment> result = new LinkedList<>();
+        ExplainStatementHandler.getSimpleTableSegment(sqlStatement).ifPresent(result::add);
+        SQLStatement explainableStatement = sqlStatement.getStatement().orElse(null);
+        TableExtractor extractor = new TableExtractor();
+        if (explainableStatement instanceof SelectStatement) {
+            extractor.extractTablesFromSelect((SelectStatement) explainableStatement);
+        } else if (explainableStatement instanceof InsertStatement) {
+            extractor.extractTablesFromInsert((InsertStatement) explainableStatement);
+        } else if (explainableStatement instanceof UpdateStatement) {
+            extractor.extractTablesFromUpdate((UpdateStatement) explainableStatement);
+        } else if (explainableStatement instanceof DeleteStatement) {
+            extractor.extractTablesFromDelete((DeleteStatement) explainableStatement);

Review comment:
       > extractTablesFromSQLStatement
   
   @tristaZero This is a great suggestion. There are similar logic in other places. Extracting to TableExtractor will make the code clearer. πŸ‘




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



[GitHub] [shardingsphere] codecov-commenter commented on pull request #10377: extract abstract explain statement & support postgresql explain statement

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #10377:
URL: https://github.com/apache/shardingsphere/pull/10377#issuecomment-843107458


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/10377?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#10377](https://codecov.io/gh/apache/shardingsphere/pull/10377?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (be64e20) into [master](https://codecov.io/gh/apache/shardingsphere/commit/33cfc3a3e6a4bfc13c3beed86857953e9b99dc60?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (33cfc3a) will **decrease** coverage by `0.11%`.
   > The diff coverage is `7.69%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/10377/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/10377?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #10377      +/-   ##
   ============================================
   - Coverage     68.93%   68.82%   -0.12%     
   - Complexity      694      696       +2     
   ============================================
     Files          1729     1732       +3     
     Lines         29498    29553      +55     
     Branches       5300     5318      +18     
   ============================================
   + Hits          20335    20339       +4     
   - Misses         7591     7641      +50     
   - Partials       1572     1573       +1     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/10377?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Ξ” | Complexity Ξ” | |
   |---|---|---|---|
   | [...phere/infra/binder/SQLStatementContextFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/10377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtYmluZGVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9iaW5kZXIvU1FMU3RhdGVtZW50Q29udGV4dEZhY3RvcnkuamF2YQ==) | `9.52% <0.00%> (ΓΈ)` | `0.00 <0.00> (ΓΈ)` | |
   | [.../binder/statement/dal/ExplainStatementContext.java](https://codecov.io/gh/apache/shardingsphere/pull/10377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtYmluZGVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9iaW5kZXIvc3RhdGVtZW50L2RhbC9FeHBsYWluU3RhdGVtZW50Q29udGV4dC5qYXZh) | `0.00% <0.00%> (ΓΈ)` | `0.00 <0.00> (?)` | |
   | [...or/statement/impl/MySQLDALStatementSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/10377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1teXNxbC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9teXNxbC92aXNpdG9yL3N0YXRlbWVudC9pbXBsL015U1FMREFMU3RhdGVtZW50U1FMVmlzaXRvci5qYXZh) | `31.81% <0.00%> (-3.19%)` | `1.00 <0.00> (ΓΈ)` | |
   | [...atement/impl/PostgreSQLDALStatementSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/10377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1wb3N0Z3Jlc3FsL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9zcWwvcGFyc2VyL3Bvc3RncmVzcWwvdmlzaXRvci9zdGF0ZW1lbnQvaW1wbC9Qb3N0Z3JlU1FMREFMU3RhdGVtZW50U1FMVmlzaXRvci5qYXZh) | `57.44% <0.00%> (-35.66%)` | `1.00 <0.00> (ΓΈ)` | |
   | [...atement/impl/PostgreSQLDDLStatementSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/10377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1wb3N0Z3Jlc3FsL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9zcWwvcGFyc2VyL3Bvc3RncmVzcWwvdmlzaXRvci9zdGF0ZW1lbnQvaW1wbC9Qb3N0Z3JlU1FMRERMU3RhdGVtZW50U1FMVmlzaXRvci5qYXZh) | `86.00% <ΓΈ> (+0.56%)` | `1.00 <0.00> (ΓΈ)` | |
   | [.../statement/impl/PostgreSQLStatementSQLVisitor.java](https://codecov.io/gh/apache/shardingsphere/pull/10377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLWRpYWxlY3Qvc2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci1wb3N0Z3Jlc3FsL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9zcWwvcGFyc2VyL3Bvc3RncmVzcWwvdmlzaXRvci9zdGF0ZW1lbnQvaW1wbC9Qb3N0Z3JlU1FMU3RhdGVtZW50U1FMVmlzaXRvci5qYXZh) | `83.16% <0.00%> (-0.17%)` | `1.00 <0.00> (ΓΈ)` | |
   | [...ql/parser/sql/common/extractor/TableExtractor.java](https://codecov.io/gh/apache/shardingsphere/pull/10377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvY29tbW9uL2V4dHJhY3Rvci9UYWJsZUV4dHJhY3Rvci5qYXZh) | `5.47% <0.00%> (-0.36%)` | `0.00 <0.00> (ΓΈ)` | |
   | [...ent/postgresql/dal/PostgreSQLExplainStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/10377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvZGlhbGVjdC9zdGF0ZW1lbnQvcG9zdGdyZXNxbC9kYWwvUG9zdGdyZVNRTEV4cGxhaW5TdGF0ZW1lbnQuamF2YQ==) | `0.00% <0.00%> (ΓΈ)` | `0.00 <0.00> (?)` | |
   | [...l/dialect/handler/dal/ExplainStatementHandler.java](https://codecov.io/gh/apache/shardingsphere/pull/10377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvZGlhbGVjdC9oYW5kbGVyL2RhbC9FeHBsYWluU3RhdGVtZW50SGFuZGxlci5qYXZh) | `33.33% <33.33%> (ΓΈ)` | `0.00 <0.00> (?)` | |
   | [...ser/sql/common/statement/dal/ExplainStatement.java](https://codecov.io/gh/apache/shardingsphere/pull/10377/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtc3FsLXBhcnNlci9zaGFyZGluZ3NwaGVyZS1zcWwtcGFyc2VyLXN0YXRlbWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvc3FsL3BhcnNlci9zcWwvY29tbW9uL3N0YXRlbWVudC9kYWwvRXhwbGFpblN0YXRlbWVudC5qYXZh) | `50.00% <50.00%> (ΓΈ)` | `1.00 <1.00> (?)` | |
   | ... and [5 more](https://codecov.io/gh/apache/shardingsphere/pull/10377/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/10377?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Ξ” = absolute <relative> (impact)`, `ΓΈ = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/10377?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [33cfc3a...be64e20](https://codecov.io/gh/apache/shardingsphere/pull/10377?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


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



[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #10377: extract abstract explain statement & support postgresql explain statement

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #10377:
URL: https://github.com/apache/shardingsphere/pull/10377#discussion_r634279314



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ExplainStatementTestCase.java
##########
@@ -22,5 +22,5 @@
 /**
  * Describe statement test case.
  */
-public final class DescribeStatementTestCase extends SQLParserTestCase {
+public final class ExplainStatementTestCase extends SQLParserTestCase {

Review comment:
       > We do not have tests to assert its `SQLStatement` field currently, which is possible to be some community issues for our volunteers.
   
   @tristaZero Great suggestion, I will create some community issues later. πŸ‘




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



[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #10377: extract abstract explain statement & support postgresql explain statement

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #10377:
URL: https://github.com/apache/shardingsphere/pull/10377#discussion_r634279314



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ExplainStatementTestCase.java
##########
@@ -22,5 +22,5 @@
 /**
  * Describe statement test case.
  */
-public final class DescribeStatementTestCase extends SQLParserTestCase {
+public final class ExplainStatementTestCase extends SQLParserTestCase {

Review comment:
       > We do not have tests to assert its `SQLStatement` field currently, which is possible to be some community issues for our volunteers.
   
   @tristaZero Great suggestion, I will create some community tasks later. πŸ‘




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



[GitHub] [shardingsphere] tristaZero commented on a change in pull request #10377: extract abstract explain statement & support postgresql explain statement

Posted by GitBox <gi...@apache.org>.
tristaZero commented on a change in pull request #10377:
URL: https://github.com/apache/shardingsphere/pull/10377#discussion_r634267871



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dal/ExplainStatementHandler.java
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.sql.dialect.handler.dal;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ExplainStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.handler.SQLStatementHandler;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLExplainStatement;
+
+import java.util.Optional;
+
+/**
+ * Explain statement handler for different dialect SQL statements.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ExplainStatementHandler implements SQLStatementHandler {
+    
+    /**
+     * Get simple table segment.
+     *
+     * @param explainStatement explain statement
+     * @return simple table segment
+     */
+    public static Optional<SimpleTableSegment> getSimpleTableSegment(final ExplainStatement explainStatement) {
+        if (explainStatement instanceof MySQLStatement) {
+            return ((MySQLExplainStatement) explainStatement).getTable();
+        }
+        return Optional.empty();

Review comment:
       So `PostgreSQLExplainStatement` is to-do one?

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ExplainStatementTestCase.java
##########
@@ -22,5 +22,5 @@
 /**
  * Describe statement test case.
  */
-public final class DescribeStatementTestCase extends SQLParserTestCase {
+public final class ExplainStatementTestCase extends SQLParserTestCase {

Review comment:
       We do not have tests to assert its `SQLStatement` field currently, which is possible to be some community issues for our volunteers.

##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLExplainStatement.java
##########
@@ -17,21 +17,29 @@
 
 package org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal;
 
-import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ExplainStatement;
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
 
+import java.util.Optional;
+
 /**
- * MySQL describe statement.
+ * MySQL explain statement.
  */
-@Getter
 @Setter
 @ToString
-public final class MySQLDescribeStatement extends AbstractSQLStatement implements DALStatement, MySQLStatement {
+public final class MySQLExplainStatement extends ExplainStatement implements MySQLStatement {
     
     private SimpleTableSegment table;

Review comment:
       This field will be removed `SQLStatement` later on, won't it?

##########
File path: shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dal/ExplainStatementContext.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.infra.binder.statement.dal;
+
+import lombok.Getter;
+import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
+import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
+import org.apache.shardingsphere.infra.binder.type.TableAvailable;
+import org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ExplainStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
+import org.apache.shardingsphere.sql.parser.sql.dialect.handler.dal.ExplainStatementHandler;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * Explain statement context.
+ */
+@Getter
+public final class ExplainStatementContext extends CommonSQLStatementContext<ExplainStatement> implements TableAvailable {
+    
+    private final TablesContext tablesContext;
+    
+    public ExplainStatementContext(final ExplainStatement sqlStatement) {
+        super(sqlStatement);
+        tablesContext = new TablesContext(extractTablesFromExplain(sqlStatement));
+    }
+    
+    private Collection<SimpleTableSegment> extractTablesFromExplain(final ExplainStatement sqlStatement) {
+        Collection<SimpleTableSegment> result = new LinkedList<>();
+        ExplainStatementHandler.getSimpleTableSegment(sqlStatement).ifPresent(result::add);
+        SQLStatement explainableStatement = sqlStatement.getStatement().orElse(null);
+        TableExtractor extractor = new TableExtractor();
+        if (explainableStatement instanceof SelectStatement) {
+            extractor.extractTablesFromSelect((SelectStatement) explainableStatement);
+        } else if (explainableStatement instanceof InsertStatement) {
+            extractor.extractTablesFromInsert((InsertStatement) explainableStatement);
+        } else if (explainableStatement instanceof UpdateStatement) {
+            extractor.extractTablesFromUpdate((UpdateStatement) explainableStatement);
+        } else if (explainableStatement instanceof DeleteStatement) {
+            extractor.extractTablesFromDelete((DeleteStatement) explainableStatement);

Review comment:
       Maybe `TableExtractor` could provide a `extractTablesFromDML` or `extractTablesFromSQLStatement` function to hide these calls.




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



[GitHub] [shardingsphere] tristaZero merged pull request #10377: extract abstract explain statement & support postgresql explain statement

Posted by GitBox <gi...@apache.org>.
tristaZero merged pull request #10377:
URL: https://github.com/apache/shardingsphere/pull/10377


   


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



[GitHub] [shardingsphere] strongduanmu commented on a change in pull request #10377: extract abstract explain statement & support postgresql explain statement

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on a change in pull request #10377:
URL: https://github.com/apache/shardingsphere/pull/10377#discussion_r634278568



##########
File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLExplainStatement.java
##########
@@ -17,21 +17,29 @@
 
 package org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal;
 
-import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ExplainStatement;
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
 
+import java.util.Optional;
+
 /**
- * MySQL describe statement.
+ * MySQL explain statement.
  */
-@Getter
 @Setter
 @ToString
-public final class MySQLDescribeStatement extends AbstractSQLStatement implements DALStatement, MySQLStatement {
+public final class MySQLExplainStatement extends ExplainStatement implements MySQLStatement {
     
     private SimpleTableSegment table;

Review comment:
       > This field will be removed `SQLStatement` later on, won't it?
   
   @tristaZero In MySQL, explain also has the describe function. When explain is used in this scenario, a `table` field will be parsed, so this field is necessary. 
   
   You can refer to the explain grammar:
   ```
   {EXPLAIN | DESCRIBE | DESC}
       tbl_name [col_name | wild]
   
   {EXPLAIN | DESCRIBE | DESC}
       [explain_type]
       {explainable_stmt | FOR CONNECTION connection_id}
   
   {EXPLAIN | DESCRIBE | DESC} ANALYZE [FORMAT = TREE] select_statement
   
   explain_type: {
       FORMAT = format_name
   }
   
   format_name: {
       TRADITIONAL
     | JSON
     | TREE
   }
   
   explainable_stmt: {
       SELECT statement
     | TABLE statement
     | DELETE statement
     | INSERT statement
     | REPLACE statement
     | UPDATE statement
   }
   ```
   




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