ShardingSphere 4.x Test engine-SQL case/SQL parse test engine/SQL rewrite test engine

whenever describe the sub-path under a specific path, there may be more than one, here represent SQL-TYPE and SHARDING-TYPE as following :

SQL-TYPE : is one of or collection of dal,dcl,ddl,dml,dql,tcl

SHARDING-TYPE : is one of or collection of db,dbtbl_with_masterslave,masterslave,tbl

SQL Case

Target

<sql-cases>
<sql-case id="select_constant_without_table" value="SELECT 1 as a" />
<sql-case id="select_with_same_table_name_and_alias" value="SELECT t_order.* FROM t_order t_order WHERE user_id = ? AND order_id = ?" />
<sql-case id="select_with_same_table_name_and_alias_column_with_owner" value="SELECT t_order.order_id,t_order.user_id,status FROM t_order t_order WHERE t_order.user_id = ? AND order_id = ?" db-types="MySQL,H2"/>
</sql-cases>

Process

SQL Parse Test Engine

Prepare Data

SQL Data

Parser Assert Data

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

SQL Rewrite Test Engine Target

Test

dataSources:
db: !!com.zaxxer.hikari.HikariDataSource
driverClassName: org.h2.Driver
jdbcUrl: jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
username: sa
password:
## sharding Rules
shardingRule:
tables:
t_account:
actualDataNodes: db.t_account_${0..1}
tableStrategy:
inline:
shardingColumn: account_id
algorithmExpression: t_account_${account_id % 2}
keyGenerator:
type: TEST
column: account_id
t_account_detail:
actualDataNodes: db.t_account_detail_${0..1}
tableStrategy:
inline:
shardingColumn: order_id
algorithmExpression: t_account_detail_${account_id % 2}
bindingTables:
- t_account, t_account_detail
<rewrite-assertions yaml-rule="yaml/sharding/sharding-rule.yaml">
<!-- to change SQL parse type, change db-type -->
<rewrite-assertion id="create_index_for_mysql" db-type="MySQL">
<input sql="CREATE INDEX index_name ON t_account ('status')" />
<output sql="CREATE INDEX index_name ON t_account_0 ('status')" />
<output sql="CREATE INDEX index_name ON t_account_1 ('status')" />
</rewrite-assertion>
</rewrite-assertions>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store