This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 86ab9443f98 Consider SQLServer Subquery Segment Index (#17300)
86ab9443f98 is described below
commit 86ab9443f98887cae84a04d6afa8463ea2b69f81
Author: Thanoshan MV <[email protected]>
AuthorDate: Wed May 4 11:19:48 2022 +0530
Consider SQLServer Subquery Segment Index (#17300)
---
.../statement/impl/SQLServerStatementSQLVisitor.java | 13 +++++++------
.../src/main/resources/case/dml/delete.xml | 4 ++--
.../src/main/resources/case/dml/insert.xml | 4 ++--
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
index 7f4cb5a7c76..7a23cc1bbea 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerStatementSQLVisitor.java
@@ -926,12 +926,13 @@ public abstract class SQLServerStatementSQLVisitor
extends SQLServerStatementBas
public ASTNode visitWithClause(final WithClauseContext ctx) {
List<CteClauseContext> cteClauses = ctx.cteClause();
Collection<CommonTableExpressionSegment> commonTableExpressions = new
LinkedList<>();
- for (CteClauseContext cte : cteClauses) {
- SubquerySegment subquery = new
SubquerySegment(cte.subquery().start.getStartIndex(),
cte.subquery().stop.getStopIndex(), (SQLServerSelectStatement)
visit(cte.subquery()));
- IdentifierValue identifier = (IdentifierValue)
visit(cte.identifier());
- CommonTableExpressionSegment commonTableExpression = new
CommonTableExpressionSegment(cte.start.getStartIndex(),
cte.stop.getStopIndex(), identifier, subquery);
- if (null != cte.columnNames()) {
- ColumnNamesContext columnNames = cte.columnNames();
+ for (CteClauseContext each : cteClauses) {
+ SubquerySegment subquery = new
SubquerySegment(each.subquery().aggregationClause().start.getStartIndex(),
+ each.subquery().aggregationClause().stop.getStopIndex(),
(SQLServerSelectStatement) visit(each.subquery()));
+ IdentifierValue identifier = (IdentifierValue)
visit(each.identifier());
+ CommonTableExpressionSegment commonTableExpression = new
CommonTableExpressionSegment(each.start.getStartIndex(),
each.stop.getStopIndex(), identifier, subquery);
+ if (null != each.columnNames()) {
+ ColumnNamesContext columnNames = each.columnNames();
CollectionValue<ColumnSegment> columns =
(CollectionValue<ColumnSegment>) visit(columnNames);
commonTableExpression.getColumns().addAll(columns.getValue());
}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/delete.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/delete.xml
index 84f7e9e0914..ee168450cf2 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/delete.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/delete.xml
@@ -364,7 +364,7 @@
<column name="order_id" start-index="10" stop-index="17"/>
<column name="user_id" start-index="20" stop-index="26"/>
</columns>
- <subquery-expression start-index="32" stop-index="70">
+ <subquery-expression start-index="33" stop-index="69">
<select>
<from>
<simple-table name="t_order" start-index="63"
stop-index="69" />
@@ -400,7 +400,7 @@
<delete sql-case-id="delete_without_columns_with_with_clause">
<with start-index="0" stop-index="50">
<common-table-expression name="cte" start-index="5"
stop-index="50">
- <subquery-expression start-index="12" stop-index="50">
+ <subquery-expression start-index="13" stop-index="49">
<select>
<from>
<simple-table name="t_order" start-index="43"
stop-index="49" />
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/insert.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/insert.xml
index 35d48cd1f06..63546ba9bdf 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/insert.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dml/insert.xml
@@ -1489,7 +1489,7 @@
<column name="order_id" start-index="10" stop-index="17"/>
<column name="user_id" start-index="20" stop-index="26"/>
</columns>
- <subquery-expression start-index="32" stop-index="70">
+ <subquery-expression start-index="33" stop-index="69">
<select>
<from>
<simple-table name="t_order" start-index="63"
stop-index="69" />
@@ -1521,7 +1521,7 @@
<insert sql-case-id="insert_without_columns_with_with_clause">
<with start-index="0" stop-index="50">
<common-table-expression name="cte" start-index="5"
stop-index="50">
- <subquery-expression start-index="12" stop-index="50">
+ <subquery-expression start-index="13" stop-index="49">
<select>
<from>
<simple-table name="t_order" start-index="43"
stop-index="49" />