SQL Parser Test

Prepare Data

Not like Integration test, 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:

  1. <parser-result-sets>
  2. <parser-result sql-case-id="insert_with_multiple_values">
  3. <tables>
  4. <table name="t_order" />
  5. </tables>
  6. <tokens>
  7. <table-token start-index="12" table-name="t_order" length="7" />
  8. </tokens>
  9. <sharding-conditions>
  10. <and-condition>
  11. <condition column-name="order_id" table-name="t_order" operator="EQUAL">
  12. <value literal="1" type="int" />
  13. </condition>
  14. <condition column-name="user_id" table-name="t_order" operator="EQUAL">
  15. <value literal="1" type="int" />
  16. </condition>
  17. </and-condition>
  18. <and-condition>
  19. <condition column-name="order_id" table-name="t_order" operator="EQUAL">
  20. <value literal="2" type="int" />
  21. </condition>
  22. <condition column-name="user_id" table-name="t_order" operator="EQUAL">
  23. <value literal="2" type="int" />
  24. </condition>
  25. </and-condition>
  26. </sharding-conditions>
  27. </parser-result>
  28. </parser-result-sets>

When these configs are ready, launch the test engine in shardingsphere-sql-parser/shardingsphere-sql-parser-test to test SQL parse.