Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for #1316, add select_in_with_geography test case. #1318

Merged
merged 15 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions sharding-core/src/test/resources/parser/select.xml
Original file line number Diff line number Diff line change
Expand Up @@ -413,34 +413,40 @@
</or-condition>
</parser-result>

<parser-result sql-case-id="select_equal_with_geography" parameters="'{&quot;rule2&quot;:&quot;null2&quot;}', 100, 200, 1">
<parser-result sql-case-id="select_equal_with_geography" parameters="'{&quot;rule2&quot;:&quot;null2&quot;}', 100, 200, 1, 2">
<tables>
<table name="t_place" />
<table name="t_order" />
</tables>
<tokens>
<table-token begin-position="14" original-literals="t_place" />
<table-token begin-position="14" original-literals="t_order" />
</tokens>
<or-condition>
<and-condition>
<condition column-name="user_new_id" table-name="t_place" operator="EQUAL">
<condition column-name="user_id" table-name="t_order" operator="EQUAL">
<value index="3" literal="1" type="int" />
</condition>
<condition column-name="order_id" table-name="t_order" operator="EQUAL">
<value index="4" literal="2" type="int" />
</condition>
</and-condition>
</or-condition>
</parser-result>

<parser-result sql-case-id="select_in_with_geography" parameters="'{&quot;rule2&quot;:&quot;null2&quot;}', '{&quot;rule3&quot;:&quot;null3&quot;}', 100, 200, 1">
<parser-result sql-case-id="select_in_with_geography" parameters="'{&quot;rule2&quot;:&quot;null2&quot;}', '{&quot;rule3&quot;:&quot;null3&quot;}', 100, 200, 1, 2">
<tables>
<table name="t_place" />
<table name="t_order" />
</tables>
<tokens>
<table-token begin-position="14" original-literals="t_place" />
<table-token begin-position="14" original-literals="t_order" />
</tokens>
<or-condition>
<and-condition>
<condition column-name="user_new_id" table-name="t_place" operator="EQUAL">
<condition column-name="user_id" table-name="t_order" operator="EQUAL">
<value index="4" literal="1" type="int" />
</condition>
<condition column-name="order_id" table-name="t_order" operator="EQUAL">
<value index="5" literal="2" type="int" />
</condition>
</and-condition>
</or-condition>
</parser-result>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public final Collection<SQLValue> getSQLValues() throws ParseException {
Collection<SQLValue> result = new LinkedList<>();
int count = 0;
for (String each : Splitter.on(",").trimResults().splitToList(parameters)) {
// TODO improve the implement way
if (each.startsWith("'")) {
String value = each.substring(each.indexOf("'") + 1, each.lastIndexOf("'"));
result.add(new SQLValue(value, "json", ++count));
continue;
}
List<String> parameterPair = Splitter.on(":").trimResults().splitToList(each);
result.add(new SQLValue(parameterPair.get(0), parameterPair.get(1), ++count));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public SQLValue(final String value, final String type, final int index) throws P
}

private Object getValue(final String value, final String type) throws ParseException {
if (null == type || "varchar".equals(type) || "char".equals(type) || "String".equals(type)) {
if (null == type || "varchar".equals(type) || "char".equals(type) || "String".equals(type) || "json".equals(type)) {
return value;
}
if ("int".equals(type)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<dataset>
<metadata>
<column name="user_id" />
</metadata>
<row values="19" />
<row values="19" />
<row values="19" />
<row values="10" />
<row values="10" />
<row values="10" />
<row values="10" />
</dataset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<dataset>
<metadata>
<column name="user_id" />
</metadata>
<row values="19" />
<row values="19" />
<row values="19" />
<row values="19" />
<row values="19" />
<row values="19" />
<row values="19" />
<row values="19" />
<row values="19" />
<row values="19" />
</dataset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<dataset>
<metadata>
<column name="user_id" />
</metadata>
<row values="19" />
<row values="19" />
<row values="19" />
<row values="10" />
<row values="10" />
<row values="10" />
<row values="10" />
</dataset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<dataset>
<metadata>
<column name="user_id" />
</metadata>
<row values="10" />
<row values="10" />
<row values="10" />
<row values="10" />
<row values="10" />
<row values="10" />
<row values="10" />
<row values="10" />
<row values="10" />
<row values="10" />
</dataset>
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,17 @@
<dql-test-case sql-case-id="select_with_force_index_join">
<assertion parameters="1000:int" expected-data-file="select_with_force_index_join.xml" />
</dql-test-case>


<dql-test-case sql-case-id="select_equal_with_geography">
<assertion parameters="'{&quot;rule2&quot;:&quot;null&quot;}', 100:int, 200:int, 10:int, 1000:int" expected-data-file="select_equal_with_single_table.xml" />
<assertion parameters="'{&quot;rule2&quot;:&quot;null&quot;}', 100:int, 200:int, 12:int, 1000:int" expected-data-file="empty_order.xml" />
</dql-test-case>

<dql-test-case sql-case-id="select_in_with_geography">
<assertion parameters="'{&quot;rule2&quot;:&quot;null&quot;}', '{&quot;rule2&quot;:&quot;null&quot;}', 100:int, 200:int, 10:int, 1000:int" expected-data-file="select_equal_with_single_table.xml" />
<assertion parameters="'{&quot;rule2&quot;:&quot;null&quot;}', '{&quot;rule2&quot;:&quot;null&quot;}', 100:int, 200:int, 12:int, 1000:int" expected-data-file="empty_order.xml" />
</dql-test-case>

<dql-test-case sql-case-id="select_sum">
<assertion expected-data-file="select_sum.xml" />
</dql-test-case>
Expand Down Expand Up @@ -334,6 +344,10 @@
<assertion parameters="10:int, 19:int, 1000:int, 1909:int, 1:int, 10:int" expected-data-file="select_pagination_with_group_by_and_order_by.xml" />
</dql-test-case>

<dql-test-case sql-case-id="select_pagination_with_diff_group_by_and_order_by">
<assertion parameters="10:int, 19:int, 1000:int, 1909:int, 1:int, 10:int" expected-data-file="select_pagination_with_diff_group_by_and_order_by.xml" />
</dql-test-case>

<dql-test-case sql-case-id="select_inner_join_related_with_alias">
<assertion parameters="1000:int" expected-data-file="select_inner_join.xml" />
</dql-test-case>
Expand All @@ -353,7 +367,7 @@
<!--<dql-test-case sql-case-id="select_sub_query_with_multiple_tables">-->
<!--<assertion parameters="1000:int, 1001:int" expected-data-file="select_sub_query_with_multiple_tables.xml" />-->
<!--</dql-test-case>-->

<dql-test-case sql-case-id="select_sub_query_with_order_by">
<assertion expected-data-file="select_sub_query_with_order_by.xml" />
</dql-test-case>
Expand Down
4 changes: 2 additions & 2 deletions sharding-sql-test/src/main/resources/sql/dql/select.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<sql-case id="select_keyword_table_name_with_square_brackets" value="SELECT i.* FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id JOIN [select] c ON o.status = c.status WHERE o.user_id IN (?, ?) AND o.order_id BETWEEN ? AND ? AND c.status = ? ORDER BY i.item_id" db-types="SQLServer" />
<sql-case id="select_alias_as_keyword" value="SELECT length.item_id password FROM t_order_item length where length.item_id = ? " db-types="MySQL,H2,SQLServer,Oracle" />
<sql-case id="select_with_force_index_join" value="SELECT i.* FROM t_order o FORCE INDEX(order_index) JOIN t_order_item i ON o.order_id=i.order_id WHERE o.order_id = ?" db-types="MySQL" />
<sql-case id="select_equal_with_geography" value="SELECT * FROM t_place WHERE rule = ?::jsonb AND start_point=ST_GeographyFromText('SRID=4326;POINT('||?||' '||?||')') AND user_new_id = ?" db-types="PostgreSQL" />
<sql-case id="select_in_with_geography" value="SELECT * FROM t_place WHERE rule IN (?::jsonb, ?::jsonb) AND start_point=ST_GeographyFromText('SRID=4326;POINT('||?||' '||?||')') AND user_new_id = ?" db-types="PostgreSQL" />
<sql-case id="select_equal_with_geography" value="SELECT * FROM t_order WHERE rule = ?::jsonb AND start_point=ST_GeographyFromText('SRID=4326;POINT('||?||' '||?||')') AND user_id = ? AND order_id = ?" db-types="PostgreSQL" />
<sql-case id="select_in_with_geography" value="SELECT * FROM t_order WHERE rule IN (?::jsonb, ?::jsonb) AND start_point=ST_GeographyFromText('SRID=4326;POINT('||?||' '||?||')') AND user_id = ? AND order_id = ?" db-types="PostgreSQL" />
<sql-case id="select_between_with_geography" value="SELECT * FROM t_place WHERE rule BETWEEN ?::jsonb AND ?::jsonb AND start_point=ST_GeographyFromText('SRID=4326;POINT('||?||' '||?||')') AND user_new_id = ?" db-types="PostgreSQL" />
<sql-case id="select_with_double_quotes" value="SELECT * FROM &quot;t_order_item&quot; WHERE &quot;item_id&quot; != ? ORDER BY &quot;item_id&quot;" db-types="PostgreSQL" />
</sql-cases>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<sql-cases>
<sql-case id="select_pagination_with_group_by_and_order_by" value="SELECT i.user_id FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (?, ?) AND o.order_id BETWEEN ? AND ? GROUP BY i.item_id ORDER BY i.item_id DESC LIMIT ?, ?" db-types="MySQL,H2" />
<sql-case id="select_pagination_with_diff_group_by_and_order_by" value="SELECT i.user_id FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (?, ?) AND o.order_id BETWEEN ? AND ? GROUP BY i.user_id ORDER BY i.item_id DESC LIMIT ?, ?" db-types="MySQL,H2" />
<sql-case id="select_pagination_with_diff_group_by_and_order_by" value="SELECT i.user_id FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (?, ?) AND o.order_id BETWEEN ? AND ? GROUP BY i.user_id ORDER BY i.item_id DESC LIMIT ?, ?" db-types="MySQL" />
<sql-case id="select_pagination_with_top_and_group_by_and_order_by" value="SELECT * FROM (SELECT TOP ? row_number() OVER (ORDER BY i.item_id DESC) AS rownum_, i.item_id, o.order_id as order_id, o.status as status, o.user_id as user_id FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (?, ?) AND o.order_id BETWEEN ? AND ? GROUP BY i.item_id) AS row_ WHERE row_.rownum_ &gt; ?" db-types="SQLServer" />
<sql-case id="select_pagination_with_top_and_group_by_and_order_by_and_parentheses" value="SELECT * FROM (SELECT TOP (?) row_number() OVER (ORDER BY i.item_id DESC) AS rownum_, i.item_id, o.order_id as order_id, o.status as status, o.user_id as user_id FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (?, ?) AND o.order_id BETWEEN ? AND ? GROUP BY i.item_id) AS row_ WHERE row_.rownum_ &gt; ?" db-types="SQLServer" />
<sql-case id="select_pagination_with_top_and_diff_group_by_and_order_by" value="SELECT * FROM (SELECT TOP ? row_number() OVER (ORDER BY i.item_id DESC) AS rownum_, i.item_id, o.order_id as order_id, o.status as status, o.user_id as user_id FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (?, ?) AND o.order_id BETWEEN ? AND ? GROUP BY i.user_id ) AS row_ WHERE row_.rownum_ &gt; ?" db-types="SQLServer" />
Expand Down