From a5a95b423e37d39092d253c24d6e07add7fbe908 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sat, 30 Mar 2019 15:09:28 +0800 Subject: [PATCH] for #2084, merge BaseRule and SQLServerBase --- .../main/antlr4/imports/sqlserver/BaseRule.g4 | 135 ++++++++++++++- .../antlr4/imports/sqlserver/SQLServerBase.g4 | 159 ------------------ .../sqlserver/SQLServerDCLStatement.g4 | 2 +- .../sqlserver/SQLServerDDLStatement.g4 | 2 +- .../sqlserver/SQLServerTCLStatement.g4 | 2 +- .../parse/antlr/autogen/SQLServerStatement.g4 | 2 +- 6 files changed, 135 insertions(+), 167 deletions(-) delete mode 100644 sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerBase.g4 diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 index fcd6de27feeec..0e2e7facd6fea 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 @@ -52,7 +52,7 @@ primaryKey ; columnNames - : LP_ columnName (COMMA_ columnName)* RP_ + : LP_ columnNameWithSort (COMMA_ columnNameWithSort)* RP_ ; exprs @@ -165,7 +165,7 @@ caseExpress ; privateExprOfDb - : matchNone + : windowedFunction | atTimeZoneExpr | castExpr | convertExpr ; variable @@ -207,9 +207,9 @@ collateClause ; orderByClause - : ORDER BY orderByItem (COMMA_ orderByItem)* + : ORDER BY orderByExpr (COMMA_ orderByExpr)* ; - + orderByItem : (columnName | number | expr) (ASC | DESC)? ; @@ -218,6 +218,133 @@ asterisk : ASTERISK_ ; +dataType + : dataTypeName_ (dataTypeLength | LP_ MAX RP_ | LP_ (CONTENT | DOCUMENT)? ignoredIdentifier_ RP_)? + ; + +dataTypeName_ + : IDENTIFIER_ + ; + +atTimeZoneExpr + : IDENTIFIER_ (WITH TIME ZONE)? STRING_ + ; + +castExpr + : CAST LP_ expr AS dataType (LP_ NUMBER_ RP_)? RP_ + ; + +convertExpr + : CONVERT (dataType (LP_ NUMBER_ RP_)? COMMA_ expr (COMMA_ NUMBER_)?) + ; + +windowedFunction + : functionCall overClause + ; + +overClause + : OVER LP_ partitionByClause? orderByClause? rowRangeClause? RP_ + ; + +partitionByClause + : PARTITION BY expr (COMMA_ expr)* + ; + +orderByExpr + : expr (COLLATE collationName)? (ASC | DESC)? + ; + +rowRangeClause + : (ROWS | RANGE) windowFrameExtent + ; + +windowFrameExtent + : windowFramePreceding | windowFrameBetween + ; + +windowFrameBetween + : BETWEEN windowFrameBound AND windowFrameBound + ; + +windowFrameBound + : windowFramePreceding | windowFrameFollowing + ; + +windowFramePreceding + : UNBOUNDED PRECEDING | NUMBER_ PRECEDING | CURRENT ROW + ; + +windowFrameFollowing + : UNBOUNDED FOLLOWING | NUMBER_ FOLLOWING | CURRENT ROW + ; + +columnNameWithSort + : columnName (ASC | DESC)? + ; + +indexOption + : FILLFACTOR EQ_ NUMBER_ + | eqOnOffOption + | (COMPRESSION_DELAY | MAX_DURATION) eqTime + | MAXDOP EQ_ NUMBER_ + | compressionOption onPartitionClause? + ; + +compressionOption + : DATA_COMPRESSION EQ_ (NONE | ROW | PAGE | COLUMNSTORE | COLUMNSTORE_ARCHIVE) + ; + +eqTime + : EQ_ NUMBER_ (MINUTES)? + ; + +eqOnOffOption + : eqKey eqOnOff + ; + +eqKey + : PAD_INDEX + | SORT_IN_TEMPDB + | IGNORE_DUP_KEY + | STATISTICS_NORECOMPUTE + | STATISTICS_INCREMENTAL + | DROP_EXISTING + | ONLINE + | RESUMABLE + | ALLOW_ROW_LOCKS + | ALLOW_PAGE_LOCKS + | COMPRESSION_DELAY + | SORT_IN_TEMPDB + ; + +eqOnOff + : EQ_ (ON | OFF) + ; + +onPartitionClause + : ON PARTITIONS LP_ partitionExpressions RP_ + ; + +partitionExpressions + : partitionExpression (COMMA_ partitionExpression)* + ; + +partitionExpression + : NUMBER_ | numberRange + ; + +numberRange + : NUMBER_ TO NUMBER_ + ; + +lowPriorityLockWait + : WAIT_AT_LOW_PRIORITY LP_ MAX_DURATION EQ_ NUMBER_ (MINUTES)? COMMA_ ABORT_AFTER_WAIT EQ_ (NONE | SELF | BLOCKERS) RP_ + ; + +onLowPriorLockWait + : ON (LP_ lowPriorityLockWait RP_)? + ; + ignoredIdentifier_ : IDENTIFIER_ ; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerBase.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerBase.g4 deleted file mode 100644 index 0d406fa1606e5..0000000000000 --- a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerBase.g4 +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -grammar SQLServerBase; - -import Symbol, Keyword, Literals, BaseRule; - -dataType - : dataTypeName_ (dataTypeLength | LP_ MAX RP_ | LP_ (CONTENT | DOCUMENT)? ignoredIdentifier_ RP_)? - ; - -dataTypeName_ - : IDENTIFIER_ - ; - -privateExprOfDb - : windowedFunction | atTimeZoneExpr | castExpr | convertExpr - ; - -atTimeZoneExpr - : IDENTIFIER_ (WITH TIME ZONE)? STRING_ - ; - -castExpr - : CAST LP_ expr AS dataType (LP_ NUMBER_ RP_)? RP_ - ; - -convertExpr - : CONVERT (dataType (LP_ NUMBER_ RP_)? COMMA_ expr (COMMA_ NUMBER_)?) - ; - -windowedFunction - : functionCall overClause - ; - -overClause - : OVER LP_ partitionByClause? orderByClause? rowRangeClause? RP_ - ; - -partitionByClause - : PARTITION BY expr (COMMA_ expr)* - ; - -orderByClause - : ORDER BY orderByExpr (COMMA_ orderByExpr)* - ; - -orderByExpr - : expr (COLLATE collationName)? (ASC | DESC)? - ; - -rowRangeClause - : (ROWS | RANGE) windowFrameExtent - ; - -windowFrameExtent - : windowFramePreceding | windowFrameBetween - ; - -windowFrameBetween - : BETWEEN windowFrameBound AND windowFrameBound - ; - -windowFrameBound - : windowFramePreceding | windowFrameFollowing - ; - -windowFramePreceding - : UNBOUNDED PRECEDING | NUMBER_ PRECEDING | CURRENT ROW - ; - -windowFrameFollowing - : UNBOUNDED FOLLOWING | NUMBER_ FOLLOWING | CURRENT ROW - ; - -columnNames - : LP_ columnNameWithSort (COMMA_ columnNameWithSort)* RP_ - ; - -columnNameWithSort - : columnName (ASC | DESC)? - ; - -indexOption - : FILLFACTOR EQ_ NUMBER_ - | eqOnOffOption - | (COMPRESSION_DELAY | MAX_DURATION) eqTime - | MAXDOP EQ_ NUMBER_ - | compressionOption onPartitionClause? - ; - -compressionOption - : DATA_COMPRESSION EQ_ (NONE | ROW | PAGE | COLUMNSTORE | COLUMNSTORE_ARCHIVE) - ; - -eqTime - : EQ_ NUMBER_ (MINUTES)? - ; - -eqOnOffOption - : eqKey eqOnOff - ; - -eqKey - : PAD_INDEX - | SORT_IN_TEMPDB - | IGNORE_DUP_KEY - | STATISTICS_NORECOMPUTE - | STATISTICS_INCREMENTAL - | DROP_EXISTING - | ONLINE - | RESUMABLE - | ALLOW_ROW_LOCKS - | ALLOW_PAGE_LOCKS - | COMPRESSION_DELAY - | SORT_IN_TEMPDB - ; - -eqOnOff - : EQ_ (ON | OFF) - ; - -onPartitionClause - : ON PARTITIONS LP_ partitionExpressions RP_ - ; - -partitionExpressions - : partitionExpression (COMMA_ partitionExpression)* - ; - -partitionExpression - : NUMBER_ | numberRange - ; - -numberRange - : NUMBER_ TO NUMBER_ - ; - -lowPriorityLockWait - : WAIT_AT_LOW_PRIORITY LP_ MAX_DURATION EQ_ NUMBER_ (MINUTES)? COMMA_ ABORT_AFTER_WAIT EQ_ (NONE | SELF | BLOCKERS) RP_ - ; - -onLowPriorLockWait - : ON (LP_ lowPriorityLockWait RP_)? - ; diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerDCLStatement.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerDCLStatement.g4 index 784872faca7db..c013a646fc887 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerDCLStatement.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerDCLStatement.g4 @@ -17,7 +17,7 @@ grammar SQLServerDCLStatement; -import Symbol, Keyword, Literals, SQLServerBase, BaseRule; +import Symbol, Keyword, Literals, BaseRule; grant : GRANT (classPrivilegesClause_ | classTypePrivilegesClause_) diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerDDLStatement.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerDDLStatement.g4 index 7b621cea54f06..e39eb69f777cc 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerDDLStatement.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerDDLStatement.g4 @@ -17,7 +17,7 @@ grammar SQLServerDDLStatement; -import Symbol, Keyword, Literals, SQLServerBase, BaseRule; +import Symbol, Keyword, Literals, BaseRule; createIndex : CREATE UNIQUE? (CLUSTERED | NONCLUSTERED)? INDEX indexName ON tableName columnNames diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerTCLStatement.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerTCLStatement.g4 index d8b0f9ce501dc..4f0530cba73e6 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerTCLStatement.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerTCLStatement.g4 @@ -17,7 +17,7 @@ grammar SQLServerTCLStatement; -import Symbol, Keyword, Literals, SQLServerBase; +import Symbol, Keyword, Literals; setTransaction : SET TRANSACTION diff --git a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/org/apache/shardingsphere/core/parse/antlr/autogen/SQLServerStatement.g4 b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/org/apache/shardingsphere/core/parse/antlr/autogen/SQLServerStatement.g4 index 0ce154b9c5d8c..23949aa28a9f4 100644 --- a/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/org/apache/shardingsphere/core/parse/antlr/autogen/SQLServerStatement.g4 +++ b/sharding-core/sharding-core-parse/sharding-core-parse-sqlserver/src/main/antlr4/org/apache/shardingsphere/core/parse/antlr/autogen/SQLServerStatement.g4 @@ -17,7 +17,7 @@ grammar SQLServerStatement; -import Keyword, Symbol, SQLServerBase, SQLServerDDLStatement, SQLServerTCLStatement, SQLServerDCLStatement; +import Keyword, Symbol, SQLServerDDLStatement, SQLServerTCLStatement, SQLServerDCLStatement; execute : (createIndex