You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by lu...@apache.org on 2020/10/14 06:29:01 UTC
[shardingsphere] branch master updated: Add SQLServer parser select
aggregation clause, support except & intersect. (#7778)
This is an automated email from the ASF dual-hosted git repository.
lujingshang 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 38f2a47 Add SQLServer parser select aggregation clause, support except & intersect. (#7778)
38f2a47 is described below
commit 38f2a47c1ac3efb505af9f7fadf9f89a3d35904d
Author: Zonglei Dong <do...@apache.org>
AuthorDate: Wed Oct 14 14:27:56 2020 +0800
Add SQLServer parser select aggregation clause, support except & intersect. (#7778)
* add SQLServer except & intersect keywords.
* add SQLServer select aggregation clause, support except & intersect.
* merge SQLServer unionClause to aggregationClause.
---
.../src/main/antlr4/imports/sqlserver/DMLStatement.g4 | 8 ++++----
.../src/main/antlr4/imports/sqlserver/Keyword.g4 | 9 +++++++++
.../sql/parser/sqlserver/visitor/impl/SQLServerDMLVisitor.java | 10 +++++-----
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
index b129b1b..129a79d 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
@@ -73,11 +73,11 @@ multipleTableNames
;
select
- : unionClause
+ : aggregationClause
;
-unionClause
- : selectClause (UNION (ALL | DISTINCT)? selectClause)*
+aggregationClause
+ : selectClause ((UNION (ALL)? | EXCEPT | INTERSECT) selectClause)*
;
selectClause
@@ -154,7 +154,7 @@ havingClause
;
subquery
- : LP_ unionClause RP_
+ : LP_ aggregationClause RP_
;
withClause_
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4
index 2ab38de..6ab5f84 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4
@@ -579,3 +579,12 @@ PERCENT
TIES
: T I E S
;
+
+EXCEPT
+ : E X C E P T
+ ;
+
+INTERSECT
+ : I N T E R S E C T
+ ;
+
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/impl/SQLServerDMLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/impl/SQLServerDMLVisitor.java
index ffd9656..6d12144 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/impl/SQLServerDMLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/impl/SQLServerDMLVisitor.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.sql.parser.sqlserver.visitor.impl;
import org.apache.shardingsphere.sql.parser.api.ASTNode;
import org.apache.shardingsphere.sql.parser.api.visitor.statement.DMLVisitor;
+import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AggregationClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AliasContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AssignmentContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AssignmentValueContext;
@@ -58,7 +59,6 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.Tab
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableReferenceContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableReferencesContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TopContext;
-import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.UnionClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.UpdateContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.WhereClauseContext;
import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.WithClause_Context;
@@ -337,14 +337,14 @@ public final class SQLServerDMLVisitor extends SQLServerVisitor implements DMLVi
@Override
public ASTNode visitSelect(final SelectContext ctx) {
// TODO :Unsupported for withClause.
- SQLServerSelectStatement result = (SQLServerSelectStatement) visit(ctx.unionClause());
+ SQLServerSelectStatement result = (SQLServerSelectStatement) visit(ctx.aggregationClause());
result.setParameterCount(getCurrentParameterIndex());
return result;
}
@Override
- public ASTNode visitUnionClause(final UnionClauseContext ctx) {
- // TODO :Unsupported for union SQL.
+ public ASTNode visitAggregationClause(final AggregationClauseContext ctx) {
+ // TODO :Unsupported for union | except | intersect SQL.
return visit(ctx.selectClause(0));
}
@@ -621,6 +621,6 @@ public final class SQLServerDMLVisitor extends SQLServerVisitor implements DMLVi
@Override
public ASTNode visitSubquery(final SubqueryContext ctx) {
- return visit(ctx.unionClause());
+ return visit(ctx.aggregationClause());
}
}