From a9767bd07b3f1403a67106a642a1a80ac45cf538 Mon Sep 17 00:00:00 2001 From: "Juan Pan(Trista)" Date: Fri, 13 Mar 2020 21:34:44 +0800 Subject: [PATCH] Support query with between subquery (#4752) --- .../sql/supported/dml/select-sub-query.xml | 4 + .../resources/sql/supported/dml/select.xml | 2 - .../parser/mysql/visitor/MySQLVisitor.java | 3 + .../parser/oracle/visitor/OracleVisitor.java | 3 + .../postgresql/visitor/PostgreSQLVisitor.java | 3 + .../parser/sql92/visitor/SQL92Visitor.java | 3 + .../sqlserver/visitor/SQLServerVisitor.java | 3 + .../resources/sql/dml/select-sub-query.xml | 118 ++++++++++++++++++ .../src/test/resources/sql/dml/select.xml | 71 ----------- 9 files changed, 137 insertions(+), 73 deletions(-) diff --git a/sharding-sql-test/src/main/resources/sql/supported/dml/select-sub-query.xml b/sharding-sql-test/src/main/resources/sql/supported/dml/select-sub-query.xml index 0dd96f29e0..ea3175b15a 100644 --- a/sharding-sql-test/src/main/resources/sql/supported/dml/select-sub-query.xml +++ b/sharding-sql-test/src/main/resources/sql/supported/dml/select-sub-query.xml @@ -21,4 +21,8 @@ + + + + diff --git a/sharding-sql-test/src/main/resources/sql/supported/dml/select.xml b/sharding-sql-test/src/main/resources/sql/supported/dml/select.xml index 28bdc99771..ae28d4b1d0 100644 --- a/sharding-sql-test/src/main/resources/sql/supported/dml/select.xml +++ b/sharding-sql-test/src/main/resources/sql/supported/dml/select.xml @@ -46,8 +46,6 @@ - - diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java index b42c7db19a..04f5c46a01 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/MySQLVisitor.java @@ -386,6 +386,9 @@ public abstract class MySQLVisitor extends MySQLStatementBaseVisitor { if (astNode instanceof ParameterMarkerValue) { return new ParameterMarkerExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((ParameterMarkerValue) astNode).getValue()); } + if (astNode instanceof SubquerySegment) { + return new SubqueryExpressionSegment((SubquerySegment) astNode); + } if (astNode instanceof OtherLiteralValue) { return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), context.getText()); } diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/OracleVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/OracleVisitor.java index f677122f9b..ab6f4a3618 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/OracleVisitor.java +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/OracleVisitor.java @@ -368,6 +368,9 @@ public abstract class OracleVisitor extends OracleStatementBaseVisitor if (astNode instanceof ParameterMarkerValue) { return new ParameterMarkerExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((ParameterMarkerValue) astNode).getValue()); } + if (astNode instanceof SubquerySegment) { + return new SubqueryExpressionSegment((SubquerySegment) astNode); + } if (astNode instanceof OtherLiteralValue) { return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), context.getText()); } 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 7ad2304a01..1696ce53a7 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 @@ -370,6 +370,9 @@ public abstract class PostgreSQLVisitor extends PostgreSQLStatementBaseVisitor { if (astNode instanceof ParameterMarkerValue) { return new ParameterMarkerExpressionSegment(context.start.getStartIndex(), context.stop.getStopIndex(), ((ParameterMarkerValue) astNode).getValue()); } + if (astNode instanceof SubquerySegment) { + return new SubqueryExpressionSegment((SubquerySegment) astNode); + } if (astNode instanceof OtherLiteralValue) { return new CommonExpressionSegment(context.getStart().getStartIndex(), context.getStop().getStopIndex(), context.getText()); } 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 9975e0ba21..b5376a38bb 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 @@ -368,6 +368,9 @@ public abstract class SQLServerVisitor extends SQLServerStatementBaseVisitor --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select.xml b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select.xml index 1107fa3e04..eb938c5c6f 100644 --- a/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select.xml +++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sql/dml/select.xml @@ -1282,77 +1282,6 @@ -
- - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
-- GitLab