strongduanmu opened a new issue #10385:
URL: https://github.com/apache/shardingsphere/issues/10385


   # Backgroud
   
   After PR #10377 was merged, the `explain` statement of PG and MySQL has been 
fully supported. In order to ensure the correctness of the parse results, we 
need to implement the logic in ExplainStatementAssert.
   
   Through this issue, you can learn more about how a SQL is parsed and how to 
verify the parsing result of a SQL in Apache ShardingSphere.
   
   # How to solve this issue
   
   First, find our target class `ExplainStatementAssert`, we need to add some 
assertion implementation to this class.
   
   The following methods are declared in the ExplainStatementAssert class. The 
`actual` parameter is the SQL parsing result, and the `expected` parameter is 
our expected result.
   
   ```java
   /**
    * Assert explain statement is correct with expected parser result.
    * 
    * @param assertContext assert context
    * @param actual actual explain statement
    * @param expected expected explain statement test case
    */
   public static void assertIs(final SQLCaseAssertContext assertContext, final 
ExplainStatement actual, final ExplainStatementTestCase expected) {
   }
   ```
   
   Second, write some cases for the expected parameter. 
   
   In order to finish this step, we need to add an `explain.xml` file in the 
`resources/sql/supported/dal` directory of the `shardingsphere-sql-parser-test` 
module, and declare the SQL we want to test in it. 
   
   Then add the `explain.xml` file in the `resources/case/dal` directory of the 
same module to declare the expected parse result.
   
   Because the `explain` statement contains `select`, `update`, `insert` and 
`delete` statements, the core logic is to make assertions on these clauses. For 
details, you can refer to `SelectStatementAssert` or `UpdateStatementAssert`.
   
   Finally, execute `SQLParserParameterizedTest` to verify whether the test 
logic we wrote is correct.
   
   If you want to try this issue, please leave a comment. BTW, If you need any 
help, please ping me. 🤣
   


-- 
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:
[email protected]


Reply via email to