Skip to content

Commit

Permalink
remove ExpectedProjection.getText() and getParameterMarkerText()
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Jan 18, 2020
1 parent a6d3305 commit 4b53f23
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void assertIs(final SQLStatementAssertMessage assertMessage, final
}

private static void assertSelectStatement(final SQLStatementAssertMessage assertMessage, final SelectStatement actual, final ParserResult expected, final SQLCaseType sqlCaseType) {
ProjectionAssert.assertIs(assertMessage, actual.getProjections(), expected.getProjections(), sqlCaseType);
ProjectionAssert.assertIs(assertMessage, actual.getProjections(), expected.getProjections());
Optional<GroupBySegment> groupBySegment = actual.getGroupBy();
if (groupBySegment.isPresent()) {
GroupByAssert.assertIs(assertMessage, groupBySegment.get().getGroupByItems(), expected.getGroupByColumns());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.rownum.ParameterMarkerRowNumberValueSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.pagination.top.TopProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.test.sql.SQLCaseType;

import java.util.List;

Expand All @@ -63,14 +62,13 @@ public final class ProjectionAssert {
* @param assertMessage assert message
* @param actual actual projection
* @param expected expected projections
* @param sqlCaseType SQL case type
*/
public static void assertIs(final SQLStatementAssertMessage assertMessage, final ProjectionsSegment actual, final ExpectedProjections expected, final SQLCaseType sqlCaseType) {
public static void assertIs(final SQLStatementAssertMessage assertMessage, final ProjectionsSegment actual, final ExpectedProjections expected) {
assertProjections(assertMessage, actual, expected);
List<ExpectedProjection> expectedProjections = expected.getExpectedProjections();
int count = 0;
for (ProjectionSegment each : actual.getProjections()) {
assertProjection(assertMessage, each, expectedProjections.get(count), sqlCaseType);
assertProjection(assertMessage, each, expectedProjections.get(count));
count++;
}
}
Expand All @@ -82,8 +80,7 @@ private static void assertProjections(final SQLStatementAssertMessage assertMess
assertThat(assertMessage.getText("Projections stop index assertion error: "), actual.getStopIndex(), is(expected.getStopIndex()));
}

private static void assertProjection(final SQLStatementAssertMessage assertMessage, final ProjectionSegment actual, final ExpectedProjection expected, final SQLCaseType sqlCaseType) {
String expectedText = SQLCaseType.Placeholder == sqlCaseType && null != expected.getParameterMarkerText() ? expected.getParameterMarkerText() : expected.getText();
private static void assertProjection(final SQLStatementAssertMessage assertMessage, final ProjectionSegment actual, final ExpectedProjection expected) {
if (actual instanceof ShorthandProjectionSegment) {
assertThat(assertMessage.getText("Projection type assertion error: "), expected, instanceOf(ExpectedShorthandProjection.class));
assertShorthandProjection(assertMessage, (ShorthandProjectionSegment) actual, (ExpectedShorthandProjection) expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,4 @@ public abstract class AbstractExpectedProjection implements ExpectedProjection {

@XmlAttribute(name = "stop-index")
private int stopIndex;

@XmlAttribute
private String text;

@XmlAttribute(name = "parameter-marker-text")
private String parameterMarkerText;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,4 @@ public interface ExpectedProjection {
* @return stop index
*/
int getStopIndex();

/**
* Get text.
*
* @return text
*/
String getText();

/**
* Get parameter marker text.
*
* @return parameter marker text
*/
String getParameterMarkerText();
}
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@
<table name="t_order" start-index="31" stop-index="37" />
</tables>
<projections start-index="7" stop-index="24">
<column-projection start-index="7" stop-index="12" text="status" alias="status" name="status" />
<column-projection name="status" alias="status" start-index="7" stop-index="12" />
</projections>
</parser-result>

Expand All @@ -829,7 +829,7 @@
<table name="t_order" start-index="48" stop-index="54" />
</tables>
<projections start-index="7" stop-index="41">
<aggregation-projection type="SUM" text="sum(if(status=0,1,0))" inner-expression-start-index="10" alias="func_status" start-index="7" stop-index="29" />
<aggregation-projection type="SUM" inner-expression-start-index="10" alias="func_status" start-index="7" stop-index="29" />
</projections>
<sharding-conditions>
<and-condition>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<table name="t_order" start-index="40" stop-index="46" />
</tables>
<projections start-index="7" stop-index="33">
<aggregation-projection type="MAX" text="MAX(user_id)" inner-expression-start-index="10" alias="max_user_id" start-index="7" stop-index="18" />
<aggregation-projection type="MAX" inner-expression-start-index="10" alias="max_user_id" start-index="7" stop-index="18" />
</projections>
</parser-result>

Expand All @@ -76,7 +76,7 @@
<table name="t_order" start-index="40" stop-index="46" />
</tables>
<projections start-index="7" stop-index="33">
<aggregation-projection type="AVG" text="AVG(user_id)" inner-expression-start-index="10" alias="user_id_avg" start-index="7" stop-index="18" />
<aggregation-projection type="AVG" inner-expression-start-index="10" alias="user_id_avg" start-index="7" stop-index="18" />
</projections>
</parser-result>

Expand All @@ -86,7 +86,7 @@
<table name="t_order_item" alias="i" start-index="47" stop-index="58" />
</tables>
<projections start-index="7" stop-index="29">
<aggregation-projection type="COUNT" text="COUNT(*)" inner-expression-start-index="12" alias="items_count" start-index="7" stop-index="14" />
<aggregation-projection type="COUNT" inner-expression-start-index="12" alias="items_count" start-index="7" stop-index="14" />
</projections>
<sharding-conditions>
<and-condition>
Expand All @@ -108,7 +108,7 @@
<table name="t_order_item" alias="i" start-index="51" stop-index="62" />
</tables>
<projections start-index="7" stop-index="29">
<aggregation-projection type="COUNT" text="COUNT(*)" inner-expression-start-index="12" alias="items_count" start-index="7" stop-index="14" />
<aggregation-projection type="COUNT" inner-expression-start-index="12" alias="items_count" start-index="7" stop-index="14" />
</projections>
<sharding-conditions>
<and-condition>
Expand All @@ -129,7 +129,7 @@
<table name="t_order" start-index="46" stop-index="52" />
</tables>
<projections start-index="7" stop-index="39">
<aggregation-projection type="COUNT" inner-expression-start-index="12" text="COUNT(`order_id`)" alias="orders_count" start-index="7" stop-index="23" />
<aggregation-projection type="COUNT" inner-expression-start-index="12" alias="orders_count" start-index="7" stop-index="23" />
</projections>
</parser-result>
</parser-result-sets>
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<table name="t_order" start-index="49" stop-index="55" />
</tables>
<projections start-index="7" stop-index="42">
<aggregation-projection start-index="7" stop-index="19" type="SUM" inner-expression-start-index="10" text="SUM(order_id)" alias="orders_sum" />
<aggregation-projection type="SUM" inner-expression-start-index="10" alias="orders_sum" start-index="7" stop-index="19" />
<column-projection name="user_id" start-index="36" stop-index="42" />
</projections>
<group-by-columns>
Expand All @@ -119,7 +119,7 @@
<table name="t_order_item" alias="i" start-index="51" stop-index="62" />
</tables>
<projections start-index="7" stop-index="29">
<aggregation-projection type="COUNT" start-index="7" stop-index="14" inner-expression-start-index="12" text="count(*)" alias="items_count" />
<aggregation-projection type="COUNT" inner-expression-start-index="12" alias="items_count" start-index="7" stop-index="14" />
</projections>
<sharding-conditions>
<and-condition>
Expand Down Expand Up @@ -160,7 +160,7 @@
</tables>
<projections start-index="7" stop-index="42">
<column-projection name="user_id" start-index="7" stop-index="13" />
<aggregation-projection start-index="16" stop-index="28" inner-expression-start-index="19" type="SUM" text="SUM(order_id)" alias="orders_sum" />
<aggregation-projection type="SUM" inner-expression-start-index="19" alias="orders_sum" start-index="16" stop-index="28" />
</projections>
<group-by-columns>
<group-by-column name="user_id" order-direction="ASC" />
Expand Down Expand Up @@ -194,7 +194,7 @@
</tables>
<projections start-index="7" stop-index="84">
<expression-projection alias="creation_date" start-index="7" stop-index="45" />
<aggregation-projection start-index="65" stop-index="72" inner-expression-start-index="70" type="COUNT" text="count(*)" alias="c_number" />
<aggregation-projection type="COUNT" inner-expression-start-index="70" alias="c_number" start-index="65" stop-index="72" />
</projections>
<sharding-conditions>
<and-condition>
Expand All @@ -214,7 +214,7 @@
<table name="t_order" start-index="58" stop-index="64" />
</tables>
<projections start-index="7" stop-index="51">
<aggregation-projection type="SUM" start-index="7" stop-index="19" inner-expression-start-index="10" text="SUM(order_id)" alias="orders_sum" />
<aggregation-projection type="SUM" inner-expression-start-index="10" alias="orders_sum" start-index="7" stop-index="19" />
<column-projection name="user_id" alias="key" start-index="36" stop-index="42" />
</projections>
<group-by-columns>
Expand All @@ -227,7 +227,7 @@
<table name="t_order" start-index="53" stop-index="59" />
</tables>
<projections start-index="7" stop-index="46">
<aggregation-projection start-index="7" stop-index="21" inner-expression-start-index="12" type="COUNT" text="COUNT(order_id)" alias="orders_count" />
<aggregation-projection inner-expression-start-index="12" type="COUNT" alias="orders_count" start-index="7" stop-index="21" />
<column-projection name="user_id" start-index="40" stop-index="46" />
</projections>
<group-by-columns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
</and-condition>
</sharding-conditions>
<projections start-index="7" stop-index="9">
<shorthand-projection start-index="7" stop-index="9" text="i.*">
<owner start-index="7" stop-index="7" name="i" />
<shorthand-projection start-index="7" stop-index="9">
<owner name="i" start-index="7" stop-index="7" />
</shorthand-projection>
</projections>
</parser-result>
Expand All @@ -42,8 +42,8 @@
<table name="t_order_item" start-index="40" stop-index="51" />
</tables>
<projections start-index="7" stop-index="20">
<shorthand-projection start-index="7" stop-index="20" text="t_order_item.*">
<owner start-index="7" stop-index="18" name="t_order_item" />
<shorthand-projection start-index="7" stop-index="20">
<owner name="t_order_item" start-index="7" stop-index="18" />
</shorthand-projection>
</projections>
<sharding-conditions>
Expand All @@ -61,8 +61,8 @@
<table name="t_order_item" alias="i" start-index="31" stop-index="42" />
</tables>
<projections start-index="7" stop-index="9">
<shorthand-projection start-index="7" stop-index="9" text="i.*">
<owner start-index="7" stop-index="7" name="i" />
<shorthand-projection start-index="7" stop-index="9">
<owner name="i" start-index="7" stop-index="7" />
</shorthand-projection>
</projections>
<sharding-conditions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@
<table name="t_order_item" alias="i" start-index="36" stop-index="47" />
</tables>
<projections start-index="7" stop-index="14">
<shorthand-projection start-index="7" stop-index="9" text="i.*">
<shorthand-projection start-index="7" stop-index="9">
<owner name="i" start-index="7" stop-index="7" />
</shorthand-projection>
<shorthand-projection start-index="12" stop-index="14" text="o.*">
<shorthand-projection start-index="12" stop-index="14">
<owner name="o" start-index="12" stop-index="12" />
</shorthand-projection>
</projections>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<table name="t_order" start-index="52" stop-index="58" />
</tables>
<projections start-index="45" stop-index="45">
<aggregation-projection type="COUNT" inner-expression="(1)" alias="orders_count" />
<shorthand-projection start-index="45" text="*" stop-index="45" />
<aggregation-projection type="COUNT" alias="orders_count" />
<shorthand-projection start-index="45" stop-index="45" />
</projections>
<order-by-columns>
<order-by-column name="order_id" order-direction="DESC" />
Expand All @@ -51,7 +51,7 @@
<table name="t_order_item" start-index="64" stop-index="75" />
</tables>
<projections start-index="50" stop-index="57">
<column-projection start-index="50" stop-index="57" text="order_id" name="order_id" />
<column-projection name="order_id" start-index="50" stop-index="57" />
</projections>
<group-by-columns>
<group-by-column name="order_id" order-direction="ASC" />
Expand Down

0 comments on commit 4b53f23

Please sign in to comment.