SQL Parser Test #
Prepare Data #
Unlike the Integration test, the SQL parse test does not need a specific database environment, just define the sql to parse, and the assert data:
SQL Data #
As mentioned sql-case-id
in Integration test,test-case-id could be shared in different module to test, and the file is at shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/sql/supported/${SQL-TYPE}/*.xml
Assert Data #
The assert data is at shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/main/resources/case/${SQL-TYPE}/*.xml
in that xml file, it could assert against the table name, token or sql condition and so on. For example:
<parser-result-sets>
<parser-result sql-case-id="insert_with_multiple_values">
<tables>
<table name="t_order" />
</tables>
<tokens>
<table-token start-index="12" table-name="t_order" length="7" />
</tokens>
<sharding-conditions>
<and-condition>
<condition column-name="order_id" table-name="t_order" operator="EQUAL">
<value literal="1" type="int" />
</condition>
<condition column-name="user_id" table-name="t_order" operator="EQUAL">
<value literal="1" type="int" />
</condition>
</and-condition>
<and-condition>
<condition column-name="order_id" table-name="t_order" operator="EQUAL">
<value literal="2" type="int" />
</condition>
<condition column-name="user_id" table-name="t_order" operator="EQUAL">
<value literal="2" type="int" />
</condition>
</and-condition>
</sharding-conditions>
</parser-result>
</parser-result-sets>
When these configs are ready, launch the test engine in shardingsphere-sql-parser/shardingsphere-sql-parser-test
to test SQL parse.