提交 84ef0c10 编写于 作者: T terrymanu

add table owner and delimiter assertion

上级 51ad92f0
......@@ -20,6 +20,8 @@ package org.apache.shardingsphere.sql.parser.integrate.asserts.table;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.sql.parser.integrate.asserts.SQLStatementAssertMessage;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.table.ExpectedTable;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.table.ExpectedTableOwner;
import org.apache.shardingsphere.sql.parser.sql.segment.generic.SchemaSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment;
import java.util.Collection;
......@@ -48,11 +50,28 @@ public final class TableAssert {
assertThat(assertMessage.getText("Tables size assertion error: "), actual.size(), is(expected.size()));
int count = 0;
for (TableSegment each : actual) {
assertThat(assertMessage.getText("Table name assertion error: "), each.getTableName(), is(expected.get(count).getName()));
assertThat(assertMessage.getText("Table alias assertion error: "), each.getAlias().orNull(), is(expected.get(count).getAlias()));
assertThat(assertMessage.getText("Table start index assertion error: "), each.getStartIndex(), is(expected.get(count).getStartIndex()));
assertThat(assertMessage.getText("Table stop index assertion error: "), each.getStopIndex(), is(expected.get(count).getStopIndex()));
assertTable(each, expected.get(count));
count++;
}
}
private void assertTable(final TableSegment actual, final ExpectedTable expected) {
assertThat(assertMessage.getText("Table name assertion error: "), actual.getTableName(), is(expected.getName()));
assertThat(assertMessage.getText("Table alias assertion error: "), actual.getAlias().orNull(), is(expected.getAlias()));
if (actual.getOwner().isPresent()) {
assertOwner(actual.getOwner().get(), expected.getOwner());
}
assertThat(assertMessage.getText("Table start delimiter assertion error: "), actual.getTableQuoteCharacter().getStartDelimiter(), is(expected.getStartDelimiter()));
assertThat(assertMessage.getText("Table stop delimiter assertion error: "), actual.getTableQuoteCharacter().getEndDelimiter(), is(expected.getEndDelimiter()));
assertThat(assertMessage.getText("Table start index assertion error: "), actual.getStartIndex(), is(expected.getStartIndex()));
assertThat(assertMessage.getText("Table stop index assertion error: "), actual.getStopIndex(), is(expected.getStopIndex()));
}
private void assertOwner(final SchemaSegment actual, final ExpectedTableOwner expected) {
assertThat(assertMessage.getText("Table owner name assertion error: "), actual.getName(), is(expected.getName()));
assertThat(assertMessage.getText("Table owner start delimiter assertion error: "), actual.getQuoteCharacter().getStartDelimiter(), is(expected.getStartDelimiter()));
assertThat(assertMessage.getText("Table owner stop delimiter assertion error: "), actual.getQuoteCharacter().getEndDelimiter(), is(expected.getEndDelimiter()));
assertThat(assertMessage.getText("Table owner start index assertion error: "), actual.getStartIndex(), is(expected.getStartIndex()));
assertThat(assertMessage.getText("Table owner stop index assertion error: "), actual.getStopIndex(), is(expected.getStopIndex()));
}
}
......@@ -23,6 +23,7 @@ import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
@XmlAccessorType(XmlAccessType.FIELD)
@Getter
......@@ -35,9 +36,18 @@ public final class ExpectedTable {
@XmlAttribute
private String alias;
@XmlAttribute(name = "start-delimiter")
private String startDelimiter = "";
@XmlAttribute(name = "end-delimiter")
private String endDelimiter = "";
@XmlAttribute(name = "start-index")
private int startIndex;
@XmlAttribute(name = "stop-index")
private int stopIndex;
@XmlElement
private ExpectedTableOwner owner;
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.shardingsphere.sql.parser.integrate.jaxb.table;
import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@XmlAccessorType(XmlAccessType.FIELD)
@Getter
@Setter
public final class ExpectedTableOwner {
@XmlAttribute
private String name;
@XmlAttribute(name = "start-delimiter")
private String startDelimiter = "";
@XmlAttribute(name = "end-delimiter")
private String endDelimiter = "";
@XmlAttribute(name = "start-index")
private int startIndex;
@XmlAttribute(name = "stop-index")
private int stopIndex;
}
......@@ -34,13 +34,15 @@
<parser-result sql-case-id="show_index_with_keys_with_database_and_table">
<tables>
<table name="t_order" start-index="15" stop-index="33" />
<table name="t_order" start-index="15" stop-index="33">
<owner name="sharding_db" start-index="15" stop-index="25" />
</table>
</tables>
</parser-result>
<parser-result sql-case-id="show_index_with_table_back_quotes">
<tables>
<table name="t_order" start-index="18" stop-index="26" />
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="18" stop-index="26" />
</tables>
<schemas>
<schema name="sharding_db" />
......@@ -58,7 +60,9 @@
<parser-result sql-case-id="show_index_with_back_quotes">
<tables>
<table name="t_order" start-index="15" stop-index="37" />
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="15" stop-index="37">
<owner name="sharding_db" start-delimiter="`" end-delimiter="`" start-index="15" stop-index="27" />
</table>
</tables>
</parser-result>
......
......@@ -42,7 +42,9 @@
<parser-result sql-case-id="grant_user_on_db_and_table">
<tables>
<!-- TODO should be 25, because table name should start from real table name, not start from schema name. Need change ID definition of g4 -->
<table name="t_order" start-index="13" stop-index="31" />
<table name="t_order" start-index="13" stop-index="31">
<owner name="sharding_db" start-index="13" stop-index="23" />
</table>
</tables>
</parser-result>
......@@ -56,7 +58,9 @@
<parser-result sql-case-id="grant_select_column">
<tables>
<table name="t_order" start-index="27" stop-index="38" />
<table name="t_order" start-index="27" stop-index="38">
<owner name="ds_0" start-index="27" stop-index="30" />
</table>
</tables>
</parser-result>
......@@ -67,7 +71,9 @@
<parser-result sql-case-id="grant_all_on_table">
<tables>
<table name="t_order" start-index="24" stop-index="35" />
<table name="t_order" start-index="24" stop-index="35">
<owner name="ds_0" start-index="24" stop-index="27" />
</table>
</tables>
</parser-result>
......@@ -80,31 +86,41 @@
<parser-result sql-case-id="grant_object_privilege">
<tables>
<table name="t_order" start-index="16" stop-index="27" />
<table name="t_order" start-index="16" stop-index="27">
<owner name="ds_0" start-index="16" stop-index="19" />
</table>
</tables>
</parser-result>
<parser-result sql-case-id="grant_object_privileges">
<tables>
<table name="t_order" start-index="40" stop-index="51" />
<table name="t_order" start-index="40" stop-index="51">
<owner name="ds_0" start-index="40" stop-index="43" />
</table>
</tables>
</parser-result>
<parser-result sql-case-id="grant_all_object_privileges">
<tables>
<table name="t_order" start-index="24" stop-index="35" />
<table name="t_order" start-index="24" stop-index="35">
<owner name="ds_0" start-index="24" stop-index="27" />
</table>
</tables>
</parser-result>
<parser-result sql-case-id="grant_object_privilege_to_users">
<tables>
<table name="t_order" start-index="16" stop-index="27" />
<table name="t_order" start-index="16" stop-index="27">
<owner name="ds_0" start-index="16" stop-index="19" />
</table>
</tables>
</parser-result>
<parser-result sql-case-id="grant_object_privilege_column">
<tables>
<table name="t_order" start-index="27" stop-index="38" />
<table name="t_order" start-index="27" stop-index="38">
<owner name="ds_0" start-index="27" stop-index="30" />
</table>
</tables>
</parser-result>
......@@ -158,7 +174,9 @@
<parser-result sql-case-id="grant_select_column_on_table">
<tables>
<table name="t_order" start-index="33" stop-index="39" />
<table name="t_order" start-index="33" stop-index="39">
<owner name="ds_0" start-index="33" stop-index="36" />
</table>
</tables>
</parser-result>
......
......@@ -36,7 +36,9 @@
<parser-result sql-case-id="revoke_user_with_hostname_on_db_and_table">
<tables>
<table name="t_order" start-index="25" stop-index="38" />
<table name="t_order" start-index="25" stop-index="38">
<owner name="master" start-index="25" stop-index="30" />
</table>
</tables>
</parser-result>
......@@ -44,7 +46,9 @@
<parser-result sql-case-id="revoke_select_column">
<tables>
<table name="t_order" start-index="28" stop-index="39" />
<table name="t_order" start-index="28" stop-index="39">
<owner name="ds_0" start-index="28" stop-index="31" />
</table>
</tables>
</parser-result>
......@@ -55,7 +59,9 @@
<parser-result sql-case-id="revoke_all_on_table">
<tables>
<table name="t_order" start-index="25" stop-index="36" />
<table name="t_order" start-index="25" stop-index="36">
<owner name="ds_0" start-index="25" stop-index="28" />
</table>
</tables>
</parser-result>
......@@ -68,31 +74,41 @@
<parser-result sql-case-id="revoke_object_privilege">
<tables>
<table name="t_order" start-index="17" stop-index="28" />
<table name="t_order" start-index="17" stop-index="28">
<owner name="ds_0" start-index="17" stop-index="20" />
</table>
</tables>
</parser-result>
<parser-result sql-case-id="revoke_object_privileges">
<tables>
<table name="t_order" start-index="41" stop-index="52" />
<table name="t_order" start-index="41" stop-index="52">
<owner name="ds_0" start-index="41" stop-index="44" />
</table>
</tables>
</parser-result>
<parser-result sql-case-id="revoke_all_object_privileges">
<tables>
<table name="t_order" start-index="25" stop-index="36" />
<table name="t_order" start-index="25" stop-index="36">
<owner name="ds_0" start-index="25" stop-index="28" />
</table>
</tables>
</parser-result>
<parser-result sql-case-id="revoke_object_privilege_from_users">
<tables>
<table name="t_order" start-index="17" stop-index="28" />
<table name="t_order" start-index="17" stop-index="28">
<owner name="ds_0" start-index="17" stop-index="20" />
</table>
</tables>
</parser-result>
<parser-result sql-case-id="revoke_object_privilege_column">
<tables>
<table name="t_order" start-index="28" stop-index="39" />
<table name="t_order" start-index="28" stop-index="39">
<owner name="ds_0" start-index="28" stop-index="31" />
</table>
</tables>
</parser-result>
......
......@@ -43,7 +43,7 @@
<parser-result sql-case-id="alter_table_with_back_quota">
<tables>
<table name="t_order" start-index="12" stop-index="20" />
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="12" stop-index="20" />
</tables>
</parser-result>
......@@ -308,7 +308,7 @@
<parser-result sql-case-id="alter_table_with_quota">
<tables>
<table name="t_order" start-index="12" stop-index="20" />
<table name="t_order" start-delimiter="&quot;" end-delimiter="&quot;" start-index="12" stop-index="20" />
</tables>
</parser-result>
......@@ -407,7 +407,7 @@
<parser-result sql-case-id="alter_table_with_double_quota">
<tables>
<table name="t_order" start-index="12" stop-index="20" />
<table name="t_order" start-delimiter="&quot;" end-delimiter="&quot;" start-index="12" stop-index="20" />
</tables>
</parser-result>
......@@ -465,7 +465,7 @@
<parser-result sql-case-id="alter_table_with_bracket">
<tables>
<table name="t_order" start-index="12" stop-index="20" />
<table name="t_order" start-delimiter="[" end-delimiter="]" start-index="12" stop-index="20" />
</tables>
</parser-result>
......@@ -525,7 +525,7 @@
<parser-result sql-case-id="alter_index_with_quota_bracket">
<tables>
<table name="t_order" start-index="29" stop-index="37" />
<table name="t_order" start-delimiter="[" end-delimiter="]" start-index="29" stop-index="37" />
</tables>
<tokens>
<index-token start-index="12" stop-index="24" table-name="t_order"/>
......
......@@ -85,7 +85,7 @@
<parser-result sql-case-id="create_table_with_back_quota">
<tables>
<table name="t_order" start-index="13" stop-index="21" />
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="13" stop-index="21" />
</tables>
</parser-result>
......@@ -265,7 +265,7 @@
<parser-result sql-case-id="create_index_with_back_quota">
<tables>
<table name="t_order" start-index="30" stop-index="38" />
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="30" stop-index="38" />
</tables>
<tokens>
<index-token start-index="13" stop-index="25" table-name="t_order" />
......@@ -292,7 +292,7 @@
<parser-result sql-case-id="create_table_with_quota">
<tables>
<table name="t_order" start-index="13" stop-index="21" />
<table name="t_order" start-delimiter="&quot;" end-delimiter="&quot;" start-index="13" stop-index="21" />
</tables>
</parser-result>
......@@ -382,7 +382,7 @@
<parser-result sql-case-id="create_index_with_quota">
<tables>
<table name="t_order" start-index="30" stop-index="38" />
<table name="t_order" start-delimiter="&quot;" end-delimiter="&quot;" start-index="30" stop-index="38" />
</tables>
<tokens>
<index-token start-index="13" stop-index="25" table-name="t_order"/>
......@@ -400,7 +400,7 @@
<parser-result sql-case-id="create_table_with_double_quota">
<tables>
<table name="t_order" start-index="13" stop-index="21" />
<table name="t_order" start-delimiter="&quot;" end-delimiter="&quot;" start-index="13" stop-index="21" />
</tables>
</parser-result>
......@@ -438,7 +438,7 @@
<parser-result sql-case-id="create_index_with_double_quota">
<tables>
<table name="t_order" start-index="30" stop-index="38" />
<table name="t_order" start-delimiter="&quot;" end-delimiter="&quot;" start-index="30" stop-index="38" />
</tables>
<tokens>
<index-token start-index="13" stop-index="25" table-name="t_order"/>
......@@ -484,7 +484,7 @@
<parser-result sql-case-id="create_table_with_bracket">
<tables>
<table name="t_order" start-index="13" stop-index="21" />
<table name="t_order" start-delimiter="[" end-delimiter="]" start-index="13" stop-index="21" />
</tables>
</parser-result>
......@@ -548,7 +548,7 @@
<parser-result sql-case-id="create_index_with_bracket">
<tables>
<table name="t_order" start-index="30" stop-index="38" />
<table name="t_order" start-delimiter="[" end-delimiter="]" start-index="30" stop-index="38" />
</tables>
<tokens>
<index-token start-index="13" stop-index="25" table-name="t_order" />
......
......@@ -82,7 +82,7 @@
<parser-result sql-case-id="drop_table_with_back_quota">
<tables>
<table name="t_order" start-index="11" stop-index="19" />
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="11" stop-index="19" />
</tables>
</parser-result>
......@@ -116,7 +116,7 @@
<parser-result sql-case-id="drop_index_with_back_quota">
<tables>
<table name="t_order" start-index="28" stop-index="36" />
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="28" stop-index="36" />
</tables>
<tokens>
<index-token start-index="11" stop-index="23" table-name="t_order"/>
......@@ -125,7 +125,7 @@
<parser-result sql-case-id="drop_table_with_quota">
<tables>
<table name="t_order" start-index="11" stop-index="19" />
<table name="t_order" start-delimiter="&quot;" end-delimiter="&quot;" start-index="11" stop-index="19" />
</tables>
</parser-result>
......@@ -137,11 +137,11 @@
<parser-result sql-case-id="drop_table_with_double_quota">
<tables>
<table name="t_order" start-index="11" stop-index="19" />
<table name="t_order" start-delimiter="&quot;" end-delimiter="&quot;" start-index="11" stop-index="19" />
</tables>
</parser-result>
<parser-result sql-case-id="drop_index_with_double_quota">
<parser-result sql-case-id="drop_index_with_double_quota">
<tokens>
<index-token start-index="11" stop-index="23" table-name="t_order" />
</tokens>
......@@ -155,13 +155,13 @@
<parser-result sql-case-id="drop_table_with_bracket">
<tables>
<table name="t_order" start-index="11" stop-index="19" />
<table name="t_order" start-delimiter="[" end-delimiter="]" start-index="11" stop-index="19" />
</tables>
</parser-result>
<parser-result sql-case-id="drop_index_with_bracket">
<tables>
<table name="t_order" start-index="28" stop-index="36" />
<table name="t_order" start-delimiter="[" end-delimiter="]" start-index="28" stop-index="36" />
</tables>
<tokens>
<index-token start-index="11" stop-index="23" table-name="t_order" />
......
......@@ -37,7 +37,7 @@
<parser-result sql-case-id="truncate_table_with_back_quota">
<tables>
<table name="t_order" start-index="15" stop-index="23" />
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="15" stop-index="23" />
</tables>
</parser-result>
......@@ -49,13 +49,13 @@
<parser-result sql-case-id="truncate_table_with_quota">
<tables>
<table name="t_order" start-index="15" stop-index="23" />
<table name="t_order" start-delimiter="&quot;" end-delimiter="&quot;" start-index="15" stop-index="23" />
</tables>
</parser-result>
<parser-result sql-case-id="truncate_table_with_double_quota">
<tables>
<table name="t_order" start-index="15" stop-index="23" />
<table name="t_order" start-delimiter="&quot;" end-delimiter="&quot;" start-index="15" stop-index="23" />
</tables>
</parser-result>
......@@ -74,7 +74,7 @@
<parser-result sql-case-id="truncate_table_with_bracket">
<tables>
<table name="t_order" start-index="15" stop-index="23" />
<table name="t_order" start-delimiter="[" end-delimiter="]" start-index="15" stop-index="23" />
</tables>
</parser-result>
</parser-result-sets>
......@@ -51,7 +51,7 @@
<parser-result sql-case-id="delete_with_special_character_without_sharding_value">
<tables>
<table name="t_order" start-index="12" stop-index="20" />
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="12" stop-index="20" />
</tables>
<encrypt-conditions>
<condition column-name="status" table-name="t_order" operator="EQUAL">
......
......@@ -134,7 +134,7 @@
<parser-result sql-case-id="insert_with_special_characters">
<tables>
<table name="t_order" start-index="12" stop-index="20" />
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="12" stop-index="20" />
</tables>
<insert-columns-and-values column-names="order_id,user_id,status">
<insert-values>
......
......@@ -416,7 +416,7 @@
<tables>
<table name="t_order" alias="o" start-index="16" stop-index="22" />
<table name="t_order_item" alias="i" start-index="31" stop-index="42" />
<table name="select" alias="c" start-index="104" stop-index="111" />
<table name="select" alias="c" start-delimiter="`" end-delimiter="`" start-index="104" stop-index="111" />
</tables>
<sharding-conditions>
<and-condition>
......@@ -451,7 +451,7 @@
<tables>
<table name="t_order" alias="o" start-index="16" stop-index="22" />
<table name="t_order_item" alias="i" start-index="31" stop-index="42" />
<table name="select" alias="c" start-index="104" stop-index="111" />
<table name="select" alias="c" start-delimiter="&quot;" end-delimiter="&quot;" start-index="104" stop-index="111" />
</tables>
<sharding-conditions>
<and-condition>
......@@ -481,7 +481,7 @@
<tables>
<table name="t_order" alias="o" start-index="16" stop-index="22" />
<table name="t_order_item" alias="i" start-index="31" stop-index="42" />
<table name="select" alias="c" start-index="104" stop-index="111" />
<table name="select" alias="c" start-delimiter="[" end-delimiter="]" start-index="104" stop-index="111" />
</tables>
<sharding-conditions>
<and-condition>
......@@ -610,7 +610,7 @@
<parser-result sql-case-id="select_with_double_quotes" parameters="1">
<tables>
<table name="t_order_item" start-index="14" stop-index="27" />
<table name="t_order_item" start-delimiter="&quot;" end-delimiter="&quot;" start-index="14" stop-index="27" />
</tables>
<order-by-columns>
<order-by-column name="item_id" order-direction="ASC" />
......@@ -825,7 +825,9 @@
<parser-result sql-case-id="select_with_schema" >
<tables>
<table name="t_order" start-index="14" stop-index="24" />
<table name="t_order" start-index="14" stop-index="24">
<owner name="db1" start-index="14" stop-index="16" />
</table>
</tables>
<select-items start-index="7" stop-index="7">
<shorthand-select-items>
......
......@@ -33,7 +33,7 @@
<parser-result sql-case-id="select_with_date_function">
<tables>
<table name="t_order_item" alias="i" start-index="51" stop-index="64" />
<table name="t_order_item" alias="i" start-delimiter="`" end-delimiter="`" start-index="51" stop-index="64" />
</tables>
<order-by-columns>
<order-by-column name="DATE(i.creation_date)" order-direction="DESC" />
......
......@@ -229,7 +229,7 @@
<parser-result sql-case-id="select_group_by_with_date_function" parameters="1000, 1100">
<tables>
<table name="t_order_item" start-index="91" stop-index="104" />
<table name="t_order_item" start-delimiter="`" end-delimiter="`" start-index="91" stop-index="104" />
</tables>
<sharding-conditions>
<and-condition>
......
......@@ -79,8 +79,8 @@
<parser-result sql-case-id="select_pagination_with_limit_with_back_quotes" parameters="1, 2, 9, 10, 5, 3">
<tables>
<table name="t_order" alias="o" start-index="16" stop-index="24" />
<table name="t_order_item" alias="i" start-index="33" stop-index="46" />
<table name="t_order" alias="o" start-delimiter="`" end-delimiter="`" start-index="16" stop-index="24" />
<table name="t_order_item" alias="i" start-delimiter="`" end-delimiter="`" start-index="33" stop-index="46" />
</tables>
<sharding-conditions>
<and-condition>
......@@ -110,8 +110,8 @@
<parser-result sql-case-id="select_pagination_with_limit_and_offset_keyword" parameters="1, 2, 9, 10, 3, 5">
<tables>
<table name="t_order" alias="o" start-index="16" stop-index="24" />
<table name="t_order_item" alias="i" start-index="33" stop-index="46" />
<table name="t_order" alias="o" start-delimiter="`" end-delimiter="`" start-index="16" stop-index="24" />
<table name="t_order_item" alias="i" start-delimiter="`" end-delimiter="`" start-index="33" stop-index="46" />
</tables>
<sharding-conditions>
<and-condition>
......
......@@ -89,7 +89,7 @@
<parser-result sql-case-id="update_with_special_character" parameters="'update', 1, 1">
<tables>
<table name="t_order" start-index="7" stop-index="15" />
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="7" stop-index="15" />
</tables>
<sharding-conditions>
<and-condition>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册