You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/07/23 06:03:58 UTC
[shardingsphere] branch master updated: fix sql test (#6370)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 417433e fix sql test (#6370)
417433e is described below
commit 417433e5ad89832ebb3744e9c8e34893fcc81987
Author: JingShang Lu <ji...@gmail.com>
AuthorDate: Thu Jul 23 14:03:42 2020 +0800
fix sql test (#6370)
* fix sql test for select_with_expression and select_pagination_with_offset_fetch
* fix
* fix
* fix
* simplify code
---
.../sql/parser/postgresql/visitor/PostgreSQLVisitor.java | 10 +---------
.../sql/parser/sqlserver/visitor/SQLServerVisitor.java | 5 +++++
.../segment/dml/item/ExpressionProjectionSegment.java | 5 +++++
.../integrate/engine/SQLParserParameterizedTest.java | 4 ----
.../src/test/resources/case/dml/select-expression.xml | 16 +++++++++-------
.../src/test/resources/case/dml/select-group-by.xml | 2 +-
.../src/test/resources/case/dml/select-pagination.xml | 10 ++++++----
.../src/test/resources/case/dml/select.xml | 2 +-
8 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/PostgreSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/PostgreSQLVisitor.java
index 6210cd2..65f083a 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/PostgreSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/PostgreSQLVisitor.java
@@ -262,15 +262,7 @@ public abstract class PostgreSQLVisitor extends PostgreSQLStatementBaseVisitor<A
private Collection<ExpressionSegment> getExpressionSegments(final AExprContext ctx) {
Collection<ExpressionSegment> result = new LinkedList<>();
-// if (null != ctx.cExpr() && null != ctx.cExpr().select_with_parens()) {
-// Select_with_parensContext subquery = ctx.cExpr().select_with_parens();
-// result.add(new SubqueryExpressionSegment(new SubquerySegment(subquery.getStart().getStartIndex(), subquery.getStop().getStopIndex(),
-// (SelectStatement) visit(ctx.cExpr().select_with_parens()))));
-// return result;
-// }
-// for (AExprContext each : ctx.aExpr()) {
-// result.add(new CommonExpressionSegment(each.start.getStartIndex(), each.stop.getStopIndex(), each.getText()));
-// }
+// TODO deal with sqlExpressions in PredicateInRightValue
return result;
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/SQLServerVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/SQLServerVisitor.java
index c466a39..2cd6948 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/SQLServerVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/SQLServerVisitor.java
@@ -490,6 +490,11 @@ public abstract class SQLServerVisitor extends SQLServerStatementBaseVisitor<AST
for (OrderByItemContext each : ctx.orderByItem()) {
items.add((OrderByItemSegment) visit(each));
}
+ if (null != ctx.expr()) {
+ for (ExprContext each : ctx.expr()) {
+ visit(each);
+ }
+ }
return new OrderBySegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), items);
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/item/ExpressionProjectionSegment.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/item/ExpressionProjectionSegment.java
index 412d580..3acc7da 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/item/ExpressionProjectionSegment.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/segment/dml/item/ExpressionProjectionSegment.java
@@ -51,4 +51,9 @@ public final class ExpressionProjectionSegment implements ProjectionSegment, Com
public Optional<String> getAlias() {
return null == alias ? Optional.empty() : Optional.ofNullable(alias.getIdentifier().getValue());
}
+
+ @Override
+ public int getStopIndex() {
+ return null != alias ? alias.getStopIndex() : stopIndex;
+ }
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/engine/SQLParserParameterizedTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/engine/SQLParserParameterizedTest.java
index 3b03d06..f76117c 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/engine/SQLParserParameterizedTest.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/java/org/apache/shardingsphere/sql/parser/integrate/engine/SQLParserParameterizedTest.java
@@ -98,10 +98,6 @@ public final class SQLParserParameterizedTest {
sqlCases.add("show_index_with_indexes_with_table_and_database");
sqlCases.add("show_index_with_database_back_quotes");
sqlCases.add("show_index_with_table_back_quotes");
- // TODO Sub query is necessary
- sqlCases.add("select_pagination_with_offset_fetch");
- // TODO Stop index is wrong
- sqlCases.add("select_with_expression");
// TODO Alter statement needs new segment
sqlCases.add("alter_table_add_foreign_key");
sqlCases.add("alter_table_add_primary_foreign_key");
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-expression.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-expression.xml
index 428ec2f..02ec64e 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-expression.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-expression.xml
@@ -18,15 +18,17 @@
<sql-parser-test-cases>
<select sql-case-id="select_with_expression">
- <tables>
- <simple-table name="t_order" alias="o" start-index="38" stop-index="44" />
- </tables>
+ <table-reference>
+ <table-factor>
+ <table name="t_order" alias="o" start-index="38" stop-index="49" />
+ </table-factor>
+ </table-reference>
<projections start-index="7" stop-index="31">
<!-- TODO check expression-projection's stop-index whether include alias -->
- <expression-projection alias="exp" start-index="7" stop-index="24" />
+ <expression-projection alias="exp" start-index="7" stop-index="31" />
</projections>
<order-by>
- <column-item name="order_id">
+ <column-item name="order_id" start-index="60" stop-index="69" >
<owner name="o" start-index="60" stop-index="60" />
</column-item>
</order-by>
@@ -39,7 +41,7 @@
</table-factor>
</table-reference>
<projections start-index="7" stop-index="44">
- <expression-projection alias="creation_date" start-index="7" stop-index="27" />
+ <expression-projection alias="creation_date" start-index="7" stop-index="44" />
</projections>
<order-by>
<expression-item expression="DATE(i.creation_date)" order-direction="DESC" start-index="80" stop-index="100" />
@@ -86,7 +88,7 @@
<column-projection start-index="11" stop-index="19" name="item_id" alias="item_id">
<owner start-index="11" stop-index="11" name="o"/>
</column-projection>
- <expression-projection start-index="33" stop-index="110" alias="stateName" />
+ <expression-projection start-index="33" stop-index="124" alias="stateName" />
</projections>
<table-reference>
<table-factor>
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-group-by.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-group-by.xml
index 350e4e5..a974e7e 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-group-by.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-group-by.xml
@@ -263,7 +263,7 @@
</table-factor>
</table-reference>
<projections start-index="7" stop-index="84">
- <expression-projection alias="creation_date" start-index="7" stop-index="45" />
+ <expression-projection alias="creation_date" start-index="7" stop-index="62" />
<aggregation-projection type="COUNT" inner-expression="(*)" alias="c_number" start-index="65" stop-index="72" />
</projections>
<where start-index="106" stop-index="130" literal-stop-index="135">
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-pagination.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-pagination.xml
index 4e48dec..77bee90 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-pagination.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select-pagination.xml
@@ -1454,14 +1454,16 @@
</select>
<select sql-case-id="select_pagination_with_offset_fetch" parameters="20">
- <tables>
- <simple-table name="t_order" start-index="14" stop-index="20" />
- </tables>
+ <table-reference>
+ <table-factor>
+ <table name="t_order" start-index="14" stop-index="20"/>
+ </table-factor>
+ </table-reference>
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<order-by>
- <column-item name="order_id" />
+ <column-item name="order_id" start-index="31" stop-index="38" />
</order-by>
<row-count value="20" parameter-index="0" />
</select>
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select.xml
index 305f8e6..7459335 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select.xml
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/case/dml/select.xml
@@ -1736,7 +1736,7 @@
</table-factor>
</table-reference>
<projections start-index="7" stop-index="38">
- <expression-projection alias="func_status" start-index="7" stop-index="26" />
+ <expression-projection alias="func_status" start-index="7" stop-index="38" />
</projections>
<where start-index="53" stop-index="86" literal-stop-index="90">
<and-predicate>