From 5145fbdfd3ff380975a34fd8583b721beba226ad Mon Sep 17 00:00:00 2001 From: loxp Date: Sun, 2 Dec 2018 14:10:49 +0800 Subject: [PATCH 01/13] refactor AntlrParsingEngine --- .../core/parsing/SQLParsingEngine.java | 6 ++-- .../parsing/antlr/AntlrParsingEngine.java | 28 +++++++++---------- .../antlr/AntlrIntegrateParsingTest.java | 4 +-- .../ddl/IntegrateDDLParsingCompatTest.java | 4 +-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLParsingEngine.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLParsingEngine.java index 62b497ec50b9f..b2f0f9f241ef3 100755 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLParsingEngine.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLParsingEngine.java @@ -67,7 +67,7 @@ public SQLStatement parse(final boolean useCache) { SQLStatement result; if (PostgreSQLKeyword.SHOW == lexerEngine.getCurrentToken().getType()) { - result = AntlrParsingEngine.parse(dbType, sql, shardingRule, shardingTableMetaData); + result = new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData).parse(); return result; } @@ -75,12 +75,12 @@ public SQLStatement parse(final boolean useCache) { Token currentToken = lexerEngine.getCurrentToken(); if (firstToken != currentToken) { if (DDLStatement.isDDL(firstToken.getType(), currentToken.getType())) { - result = AntlrParsingEngine.parse(dbType, sql, shardingRule, shardingTableMetaData); + result = new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData).parse(); } else { result = sqlParser.parse(); } } else if (TCLStatement.isTCL(firstToken.getType())) { - result = AntlrParsingEngine.parse(dbType, sql, shardingRule, shardingTableMetaData); + result = new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData).parse(); } else { result = sqlParser.parse(); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/AntlrParsingEngine.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/AntlrParsingEngine.java index 166d0ef23f366..14fb45441d2ab 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/AntlrParsingEngine.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/AntlrParsingEngine.java @@ -24,10 +24,10 @@ import io.shardingsphere.core.parsing.antlr.extractor.statement.SQLStatementExtractorFactory; import io.shardingsphere.core.parsing.antlr.extractor.statement.SQLStatementType; import io.shardingsphere.core.parsing.parser.exception.SQLParsingUnsupportedException; +import io.shardingsphere.core.parsing.parser.sql.SQLParser; import io.shardingsphere.core.parsing.parser.sql.SQLStatement; import io.shardingsphere.core.rule.ShardingRule; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import lombok.AllArgsConstructor; import org.antlr.v4.runtime.ParserRuleContext; /** @@ -35,19 +35,19 @@ * * @author duhongjun */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class AntlrParsingEngine { +@AllArgsConstructor +public final class AntlrParsingEngine implements SQLParser { - /** - * Parse SQL. - * - * @param dbType database type - * @param sql SQL - * @param shardingRule sharding rule - * @param shardingTableMetaData sharding table meta data - * @return SQL statement - */ - public static SQLStatement parse(final DatabaseType dbType, final String sql, final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) { + private DatabaseType dbType; + + private String sql; + + private ShardingRule shardingRule; + + private ShardingTableMetaData shardingTableMetaData; + + @Override + public SQLStatement parse() { ParserRuleContext rootContext = SQLASTParserFactory.newInstance(dbType, sql).execute(); if (null == rootContext) { throw new SQLParsingUnsupportedException(String.format("Unsupported SQL of `%s`", sql)); diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/antlr/AntlrIntegrateParsingTest.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/antlr/AntlrIntegrateParsingTest.java index 57f0451e0f0ec..b660f61833c2b 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/antlr/AntlrIntegrateParsingTest.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/antlr/AntlrIntegrateParsingTest.java @@ -109,8 +109,8 @@ public void assertSupportedSQL() { if (DatabaseType.H2 == databaseType) { execDatabaseType = DatabaseType.MySQL; } - new SQLStatementAssert(AntlrParsingEngine.parse( - execDatabaseType, sql, getShardingRule(), getShardingTableMetaData()), sqlCaseId, sqlCaseType, sqlCasesLoader, parserResultSetLoader).assertSQLStatement(); + new SQLStatementAssert(new AntlrParsingEngine( + execDatabaseType, sql, getShardingRule(), getShardingTableMetaData()).parse(), sqlCaseId, sqlCaseType, sqlCasesLoader, parserResultSetLoader).assertSQLStatement(); } } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/antlr/ddl/IntegrateDDLParsingCompatTest.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/antlr/ddl/IntegrateDDLParsingCompatTest.java index 6c0af423746ed..f98569a51b641 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/antlr/ddl/IntegrateDDLParsingCompatTest.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/antlr/ddl/IntegrateDDLParsingCompatTest.java @@ -104,8 +104,8 @@ public void assertSupportedSQL() { if (DatabaseType.H2 == databaseType) { execDatabaseType = DatabaseType.MySQL; } - new SQLStatementAssert(AntlrParsingEngine.parse( - execDatabaseType, sql, getShardingRule(), getShardingTableMetaData()), sqlCaseId, sqlCaseType, sqlCasesLoader, parserResultSetLoader).assertSQLStatement(); + new SQLStatementAssert(new AntlrParsingEngine( + execDatabaseType, sql, getShardingRule(), getShardingTableMetaData()).parse(), sqlCaseId, sqlCaseType, sqlCasesLoader, parserResultSetLoader).assertSQLStatement(); } /** From acb0634a3fc9232814214211b21600bf0612cc5c Mon Sep 17 00:00:00 2001 From: loxp Date: Sun, 2 Dec 2018 14:43:34 +0800 Subject: [PATCH 02/13] refactor SQL parsing logic, put all parser choosing logic into SQLParserFactory --- .../core/parsing/SQLParsingEngine.java | 23 +------- .../parsing/parser/sql/SQLParserFactory.java | 56 +++++-------------- 2 files changed, 14 insertions(+), 65 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLParsingEngine.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLParsingEngine.java index b2f0f9f241ef3..2082af258e0bf 100755 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLParsingEngine.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLParsingEngine.java @@ -62,28 +62,7 @@ public SQLStatement parse(final boolean useCache) { return cachedSQLStatement.get(); } LexerEngine lexerEngine = LexerEngineFactory.newInstance(dbType, sql); - lexerEngine.nextToken(); - Token firstToken = lexerEngine.getCurrentToken(); - SQLStatement result; - - if (PostgreSQLKeyword.SHOW == lexerEngine.getCurrentToken().getType()) { - result = new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData).parse(); - return result; - } - - SQLParser sqlParser = SQLParserFactory.newInstance(dbType, lexerEngine.getCurrentToken().getType(), shardingRule, lexerEngine, shardingTableMetaData); - Token currentToken = lexerEngine.getCurrentToken(); - if (firstToken != currentToken) { - if (DDLStatement.isDDL(firstToken.getType(), currentToken.getType())) { - result = new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData).parse(); - } else { - result = sqlParser.parse(); - } - } else if (TCLStatement.isTCL(firstToken.getType())) { - result = new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData).parse(); - } else { - result = sqlParser.parse(); - } + SQLStatement result = SQLParserFactory.newInstance(dbType, shardingRule, lexerEngine, shardingTableMetaData, sql).parse(); if (useCache) { ParsingResultCache.getInstance().put(sql, result); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java index 283c3140084f6..37474422b7a53 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java @@ -19,8 +19,10 @@ import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.metadata.table.ShardingTableMetaData; +import io.shardingsphere.core.parsing.antlr.AntlrParsingEngine; import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.lexer.dialect.mysql.MySQLKeyword; +import io.shardingsphere.core.parsing.lexer.dialect.postgresql.PostgreSQLKeyword; import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword; import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.lexer.token.TokenType; @@ -69,14 +71,18 @@ public final class SQLParserFactory { * Create SQL parser. * * @param dbType database type - * @param tokenType token type * @param shardingRule databases and tables sharding rule * @param lexerEngine lexical analysis engine * @param shardingTableMetaData sharding metadata + * @param sql sql to parse * @return SQL parser */ public static SQLParser newInstance( - final DatabaseType dbType, final TokenType tokenType, final ShardingRule shardingRule, final LexerEngine lexerEngine, final ShardingTableMetaData shardingTableMetaData) { + final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine, final ShardingTableMetaData shardingTableMetaData, final String sql) { + + lexerEngine.nextToken(); + TokenType tokenType = lexerEngine.getCurrentToken().getType(); + if (DQLStatement.isDQL(tokenType)) { return getDQLParser(dbType, shardingRule, lexerEngine, shardingTableMetaData); } @@ -84,15 +90,18 @@ public static SQLParser newInstance( return getDMLParser(dbType, tokenType, shardingRule, lexerEngine, shardingTableMetaData); } if (TCLStatement.isTCL(tokenType)) { - return getTCLParser(dbType, shardingRule, lexerEngine); + return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData); } if (DALStatement.isDAL(tokenType)) { + if (PostgreSQLKeyword.SHOW == tokenType) { + new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData); + } return getDALParser(dbType, (Keyword) tokenType, shardingRule, lexerEngine); } lexerEngine.nextToken(); TokenType secondaryTokenType = lexerEngine.getCurrentToken().getType(); if (DDLStatement.isDDL(tokenType, secondaryTokenType)) { - return getDDLParser(dbType, tokenType, shardingRule, lexerEngine); + return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData); } if (DCLStatement.isDCL(tokenType, secondaryTokenType)) { return getDCLParser(dbType, tokenType, shardingRule, lexerEngine); @@ -118,45 +127,6 @@ private static SQLParser getDMLParser( } } - private static SQLParser getDDLParser(final DatabaseType dbType, final TokenType tokenType, final ShardingRule shardingRule, final LexerEngine lexerEngine) { - lexerEngine.skipUntil(DefaultKeyword.INDEX, DefaultKeyword.TABLE); - if (lexerEngine.isEnd()) { - throw new SQLParsingUnsupportedException(tokenType); - } - return DefaultKeyword.TABLE == lexerEngine.getCurrentToken().getType() ? getTableDDLParser(dbType, tokenType, shardingRule, lexerEngine) - : getIndexDDLParser(dbType, tokenType, shardingRule, lexerEngine); - } - - private static SQLParser getTableDDLParser(final DatabaseType dbType, final TokenType tokenType, final ShardingRule shardingRule, final LexerEngine lexerEngine) { - switch ((DefaultKeyword) tokenType) { - case CREATE: - return CreateTableParserFactory.newInstance(dbType, shardingRule, lexerEngine); - case ALTER: - return AlterTableParserFactory.newInstance(dbType, shardingRule, lexerEngine); - case DROP: - return DropTableParserFactory.newInstance(dbType, shardingRule, lexerEngine); - case TRUNCATE: - return TruncateTableParserFactory.newInstance(dbType, shardingRule, lexerEngine); - default: - throw new SQLParsingUnsupportedException(tokenType); - } - } - - private static SQLParser getIndexDDLParser(final DatabaseType dbType, final TokenType tokenType, final ShardingRule shardingRule, final LexerEngine lexerEngine) { - switch ((DefaultKeyword) tokenType) { - case CREATE: - return CreateIndexParserFactory.newInstance(dbType, shardingRule, lexerEngine); - case DROP: - return DropIndexParserFactory.newInstance(dbType, shardingRule, lexerEngine); - default: - throw new SQLParsingUnsupportedException(tokenType); - } - } - - private static SQLParser getTCLParser(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) { - return TCLParserFactory.newInstance(dbType, shardingRule, lexerEngine); - } - private static SQLParser getDALParser(final DatabaseType dbType, final Keyword tokenType, final ShardingRule shardingRule, final LexerEngine lexerEngine) { if (DefaultKeyword.USE == tokenType) { return UseParserFactory.newInstance(dbType, shardingRule, lexerEngine); From e342a8b456237252650bc82e1e6e5ace83bca998 Mon Sep 17 00:00:00 2001 From: loxp Date: Sun, 2 Dec 2018 14:46:14 +0800 Subject: [PATCH 03/13] update DAL statement judgement --- .../dialect/postgresql/PostgreSQLKeyword.java | 3 ++- .../parsing/lexer/token/DefaultKeyword.java | 3 ++- .../parsing/parser/sql/dal/DALStatement.java | 20 +++++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/postgresql/PostgreSQLKeyword.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/postgresql/PostgreSQLKeyword.java index 149da2a3718a0..c3c8beea9e1de 100755 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/postgresql/PostgreSQLKeyword.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/postgresql/PostgreSQLKeyword.java @@ -65,5 +65,6 @@ public enum PostgreSQLKeyword implements Keyword { INITIALLY, DEFERRED, IMMEDIATE, - EXTRACT + EXTRACT, + CONSTRAINTS } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/token/DefaultKeyword.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/token/DefaultKeyword.java index 47efd7a34b8a6..5836922517527 100755 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/token/DefaultKeyword.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/token/DefaultKeyword.java @@ -156,7 +156,8 @@ public enum DefaultKeyword implements Keyword { COMMIT, ROLLBACK, SAVEPOINT, - BEGIN, + BEGIN, + TRANSACTION, /* Other Command diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dal/DALStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dal/DALStatement.java index 2b49082904a09..691332dd5b5c5 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dal/DALStatement.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dal/DALStatement.java @@ -37,7 +37,12 @@ @ToString(callSuper = true) public class DALStatement extends AbstractSQLStatement { - private static final Collection STATEMENT_PREFIX = Arrays.asList(DefaultKeyword.USE, DefaultKeyword.DESC, MySQLKeyword.DESCRIBE, MySQLKeyword.SHOW, PostgreSQLKeyword.SHOW); + private static final Collection SINGLE_TOKEN_STATEMENT_PREFIX = Arrays.asList(DefaultKeyword.USE, DefaultKeyword.DESC, MySQLKeyword.DESCRIBE, MySQLKeyword.SHOW, + PostgreSQLKeyword.SHOW, PostgreSQLKeyword.RESET); + + private static final Collection DUAL_TOKEN_PRIMARY_STATEMENT_PREFIX = Arrays.asList(DefaultKeyword.SET); + + private static final Collection DUAL_TOKEN_NOT_SECONDARY_STATEMENT_PREFIX = Arrays.asList(DefaultKeyword.ROLE, DefaultKeyword.TRANSACTION, PostgreSQLKeyword.CONSTRAINTS); public DALStatement() { super(SQLType.DAL); @@ -50,6 +55,17 @@ public DALStatement() { * @return is DAL or not */ public static boolean isDAL(final TokenType tokenType) { - return STATEMENT_PREFIX.contains(tokenType); + return SINGLE_TOKEN_STATEMENT_PREFIX.contains(tokenType); + } + + /** + * Is DAL statement. + * + * @param primaryTokenType primary token type + * @param secondaryTokenType secondary token type + * @return is DAL or not + */ + public static boolean isDAL(final TokenType primaryTokenType, final TokenType secondaryTokenType) { + return DUAL_TOKEN_PRIMARY_STATEMENT_PREFIX.contains(primaryTokenType) && !DUAL_TOKEN_NOT_SECONDARY_STATEMENT_PREFIX.contains(secondaryTokenType); } } From 88c3a40a9fda6e0aadaeb33f5abbc1993eced55e Mon Sep 17 00:00:00 2001 From: loxp Date: Sun, 2 Dec 2018 14:48:57 +0800 Subject: [PATCH 04/13] add dual token DAL judgement --- .../core/parsing/parser/sql/SQLParserFactory.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java index 37474422b7a53..2ccc515d6334b 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java @@ -100,6 +100,9 @@ public static SQLParser newInstance( } lexerEngine.nextToken(); TokenType secondaryTokenType = lexerEngine.getCurrentToken().getType(); + if (DALStatement.isDAL(tokenType, secondaryTokenType)) { + new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData); + } if (DDLStatement.isDDL(tokenType, secondaryTokenType)) { return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData); } From cdeef2838bc681009f56b7392fdbdf99ef5d4554 Mon Sep 17 00:00:00 2001 From: loxp Date: Sun, 2 Dec 2018 14:54:27 +0800 Subject: [PATCH 05/13] add ANTLR PostgreSQL DAL grammar --- .../antlr4/imports/PostgreSQLDALStatement.g4 | 26 ++++++++++++++++--- .../antlr/autogen/PostgreSQLStatement.g4 | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/sharding-core/src/main/antlr4/imports/PostgreSQLDALStatement.g4 b/sharding-core/src/main/antlr4/imports/PostgreSQLDALStatement.g4 index 04c2d42f04c51..fd58687da6048 100644 --- a/sharding-core/src/main/antlr4/imports/PostgreSQLDALStatement.g4 +++ b/sharding-core/src/main/antlr4/imports/PostgreSQLDALStatement.g4 @@ -3,10 +3,28 @@ grammar PostgreSQLDALStatement; import PostgreSQLKeyword, Keyword, BaseRule, DataType, Symbol; show - : SHOW showParam + : SHOW (ALL | ID) + ; + +setParam + : SET scope? setClause + ; + +scope + : SESSION | LOCAL ; -showParam - : ALL - | ID +setClause + : TIME ZONE timeZoneType + | ID (TO | EQ_) (STRING | DEFAULT) ; + +timeZoneType + : NUMBER + | LOCAL + | DEFAULT + ; + +resetParam + : RESET (ALL | ID) + ; \ No newline at end of file diff --git a/sharding-core/src/main/antlr4/io/shardingsphere/core/parsing/antlr/autogen/PostgreSQLStatement.g4 b/sharding-core/src/main/antlr4/io/shardingsphere/core/parsing/antlr/autogen/PostgreSQLStatement.g4 index 97587dfe2f6fd..320a4dc3379f3 100644 --- a/sharding-core/src/main/antlr4/io/shardingsphere/core/parsing/antlr/autogen/PostgreSQLStatement.g4 +++ b/sharding-core/src/main/antlr4/io/shardingsphere/core/parsing/antlr/autogen/PostgreSQLStatement.g4 @@ -35,4 +35,6 @@ execute | alterRoleResetConfig | dropRole | show + | setParam + | resetParam ; From 24b4e32e2d98556a3e14ead763bb233dd0c6b1dd Mon Sep 17 00:00:00 2001 From: loxp Date: Sun, 2 Dec 2018 14:58:18 +0800 Subject: [PATCH 06/13] add PostgreSQL DAL parsing components --- .../extractor/statement/SQLStatementType.java | 4 ++ .../PostgreSQLResetParamExtractor.java | 35 ++++++++++++++++++ .../PostgreSQLSetParamExtractor.java | 37 +++++++++++++++++++ .../PostgreSQLStatementExtractorRegistry.java | 4 ++ .../statement/ResetParamStatement.java | 6 +++ .../statement/SetParamStatement.java | 6 +++ 6 files changed, 92 insertions(+) create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLResetParamExtractor.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLSetParamExtractor.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ResetParamStatement.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/SetParamStatement.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/SQLStatementType.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/SQLStatementType.java index be9a36ab56efc..99c6ec17b9691 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/SQLStatementType.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/SQLStatementType.java @@ -53,6 +53,10 @@ public enum SQLStatementType { SET_VARIABLE("SetVariable"), + SET_PARAM("SetParam"), // PostgreSQL SET statement + + RESET_PARAM("ResetParam"), + SHOW("Show"); private final String name; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLResetParamExtractor.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLResetParamExtractor.java new file mode 100644 index 0000000000000..d6783090ffee1 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLResetParamExtractor.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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. + *

+ */ + +package io.shardingsphere.core.parsing.antlr.extractor.statement.engine.dal.dialect.postgresql; + +import io.shardingsphere.core.parsing.antlr.extractor.statement.engine.dal.DALStatementExtractor; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.statement.ResetParamStatement; +import io.shardingsphere.core.parsing.parser.sql.SQLStatement; + +/** + * PostgreSQL reset param statement extractor. + * + * @author loxp + */ +public class PostgreSQLResetParamExtractor extends DALStatementExtractor { + + @Override + protected SQLStatement createStatement() { + return new ResetParamStatement(); + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLSetParamExtractor.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLSetParamExtractor.java new file mode 100644 index 0000000000000..dfeae1e6fad2d --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLSetParamExtractor.java @@ -0,0 +1,37 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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. + *

+ */ + +package io.shardingsphere.core.parsing.antlr.extractor.statement.engine.dal.dialect.postgresql; + +import io.shardingsphere.core.parsing.antlr.extractor.statement.engine.dal.DALStatementExtractor; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.statement.SetParamStatement; +import io.shardingsphere.core.parsing.parser.sql.SQLStatement; +import lombok.NoArgsConstructor; + +/** + * PostgreSQL set param statement extractor. + * + * @author loxp + */ +@NoArgsConstructor +public class PostgreSQLSetParamExtractor extends DALStatementExtractor { + + @Override + protected SQLStatement createStatement() { + return new SetParamStatement(); + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/registry/dialect/PostgreSQLStatementExtractorRegistry.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/registry/dialect/PostgreSQLStatementExtractorRegistry.java index 14b26872f5a69..7cff70833aac9 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/registry/dialect/PostgreSQLStatementExtractorRegistry.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/registry/dialect/PostgreSQLStatementExtractorRegistry.java @@ -19,6 +19,8 @@ import io.shardingsphere.core.parsing.antlr.extractor.statement.SQLStatementExtractor; import io.shardingsphere.core.parsing.antlr.extractor.statement.SQLStatementType; +import io.shardingsphere.core.parsing.antlr.extractor.statement.engine.dal.dialect.postgresql.PostgreSQLResetParamExtractor; +import io.shardingsphere.core.parsing.antlr.extractor.statement.engine.dal.dialect.postgresql.PostgreSQLSetParamExtractor; import io.shardingsphere.core.parsing.antlr.extractor.statement.engine.dal.dialect.postgresql.PostgreSQLShowExtractor; import io.shardingsphere.core.parsing.antlr.extractor.statement.engine.ddl.CreateIndexExtractor; import io.shardingsphere.core.parsing.antlr.extractor.statement.engine.ddl.CreateTableExtractor; @@ -65,6 +67,8 @@ private static void registerTCL() { private static void registerDAL() { EXTRACTORS.put(SQLStatementType.SHOW, new PostgreSQLShowExtractor()); + EXTRACTORS.put(SQLStatementType.SET_PARAM, new PostgreSQLSetParamExtractor()); + EXTRACTORS.put(SQLStatementType.RESET_PARAM, new PostgreSQLResetParamExtractor()); } @Override diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ResetParamStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ResetParamStatement.java new file mode 100644 index 0000000000000..ec50b2c3f6fcf --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ResetParamStatement.java @@ -0,0 +1,6 @@ +package io.shardingsphere.core.parsing.parser.dialect.postgresql.statement; + +import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement; + +public class ResetParamStatement extends DALStatement { +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/SetParamStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/SetParamStatement.java new file mode 100644 index 0000000000000..5d3382e28e71d --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/SetParamStatement.java @@ -0,0 +1,6 @@ +package io.shardingsphere.core.parsing.parser.dialect.postgresql.statement; + +import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement; + +public class SetParamStatement extends DALStatement { +} From d7a7b66b8c0897047373258f4da4b557ad4b7813 Mon Sep 17 00:00:00 2001 From: loxp Date: Sun, 2 Dec 2018 15:00:02 +0800 Subject: [PATCH 07/13] modify route function, add PostgreSQL DAL statements --- .../core/routing/router/sharding/ParsingSQLRouter.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java index 331e713057573..5709d149d30ea 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java @@ -30,6 +30,8 @@ import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowTableStatusStatement; import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement; import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.UseStatement; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.statement.ResetParamStatement; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.statement.SetParamStatement; import io.shardingsphere.core.parsing.parser.sql.SQLStatement; import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement; import io.shardingsphere.core.parsing.parser.sql.dcl.DCLStatement; @@ -137,7 +139,9 @@ private RoutingResult route(final SQLStatement sqlStatement, final ShardingCondi routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule); } else if (sqlStatement instanceof DDLStatement || (sqlStatement instanceof DCLStatement && ((DCLStatement) sqlStatement).isGrantForSingleTable())) { routingEngine = new TableBroadcastRoutingEngine(shardingRule, sqlStatement); - } else if (sqlStatement instanceof ShowDatabasesStatement || ((sqlStatement instanceof ShowTablesStatement || sqlStatement instanceof ShowTableStatusStatement) && tableNames.isEmpty())) { + } else if (sqlStatement instanceof ShowDatabasesStatement + || ((sqlStatement instanceof ShowTablesStatement || sqlStatement instanceof ShowTableStatusStatement) && tableNames.isEmpty()) || sqlStatement instanceof SetParamStatement + || sqlStatement instanceof ResetParamStatement) { routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule); } else if (sqlStatement instanceof DCLStatement) { routingEngine = new InstanceBroadcastRoutingEngine(shardingRule, shardingDataSourceMetaData); From 9b0c2c8f3c7f9cd61ef1d0a6366dfb488c3fb2ad Mon Sep 17 00:00:00 2001 From: loxp Date: Sun, 2 Dec 2018 15:02:51 +0800 Subject: [PATCH 08/13] add copyright and documentation --- .../postgresql/ShowParamExtractor.java | 22 +++++++++++++++++++ .../engine/dal/DALStatementExtractor.java | 22 +++++++++++++++++++ .../postgresql/PostgreSQLShowExtractor.java | 22 +++++++++++++++++++ .../filler/engnie/ShowParamSegmentFiller.java | 22 +++++++++++++++++++ .../antlr/sql/segment/ShowParamSegment.java | 22 +++++++++++++++++++ 5 files changed, 110 insertions(+) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/segment/engine/dialect/postgresql/ShowParamExtractor.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/segment/engine/dialect/postgresql/ShowParamExtractor.java index 79b70e58c2f5c..5c48f60ab82a2 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/segment/engine/dialect/postgresql/ShowParamExtractor.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/segment/engine/dialect/postgresql/ShowParamExtractor.java @@ -1,3 +1,20 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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. + *

+ */ + package io.shardingsphere.core.parsing.antlr.extractor.segment.engine.dialect.postgresql; import com.google.common.base.Optional; @@ -8,6 +25,11 @@ import io.shardingsphere.core.parsing.antlr.sql.segment.ShowParamSegment; import org.antlr.v4.runtime.ParserRuleContext; +/** + * PostgreSQL show param extractor. + * + * @author loxp + */ public class ShowParamExtractor implements OptionalSQLSegmentExtractor { @Override diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/DALStatementExtractor.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/DALStatementExtractor.java index f1732caa750d6..12057199742d8 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/DALStatementExtractor.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/DALStatementExtractor.java @@ -1,9 +1,31 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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. + *

+ */ + package io.shardingsphere.core.parsing.antlr.extractor.statement.engine.dal; import io.shardingsphere.core.parsing.antlr.extractor.statement.engine.AbstractSQLStatementExtractor; import io.shardingsphere.core.parsing.parser.sql.SQLStatement; import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement; +/** + * DAL statement extractor. + * + * @author loxp + */ public abstract class DALStatementExtractor extends AbstractSQLStatementExtractor { @Override diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLShowExtractor.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLShowExtractor.java index 06403de536822..00ae3cbf9bd73 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLShowExtractor.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/extractor/statement/engine/dal/dialect/postgresql/PostgreSQLShowExtractor.java @@ -1,3 +1,20 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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. + *

+ */ + package io.shardingsphere.core.parsing.antlr.extractor.statement.engine.dal.dialect.postgresql; import io.shardingsphere.core.parsing.antlr.extractor.segment.engine.dialect.postgresql.ShowParamExtractor; @@ -5,6 +22,11 @@ import io.shardingsphere.core.parsing.parser.dialect.postgresql.statement.ShowStatement; import io.shardingsphere.core.parsing.parser.sql.SQLStatement; +/** + * PostgreSQL show statement extractor. + * + * @author loxp + */ public final class PostgreSQLShowExtractor extends DALStatementExtractor { public PostgreSQLShowExtractor() { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/filler/engnie/ShowParamSegmentFiller.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/filler/engnie/ShowParamSegmentFiller.java index a13076d73256f..670a4235dd687 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/filler/engnie/ShowParamSegmentFiller.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/filler/engnie/ShowParamSegmentFiller.java @@ -1,3 +1,20 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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. + *

+ */ + package io.shardingsphere.core.parsing.antlr.filler.engnie; import io.shardingsphere.core.metadata.table.ShardingTableMetaData; @@ -7,6 +24,11 @@ import io.shardingsphere.core.parsing.parser.dialect.postgresql.statement.ShowStatement; import io.shardingsphere.core.parsing.parser.sql.SQLStatement; +/** + * Show param segment filler. + * + * @author loxp + */ public class ShowParamSegmentFiller implements SQLSegmentFiller { @Override public void fill(SQLSegment sqlSegment, SQLStatement sqlStatement, ShardingTableMetaData shardingTableMetaData) { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/sql/segment/ShowParamSegment.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/sql/segment/ShowParamSegment.java index 6a560e6207b2b..03f3dc69728c6 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/sql/segment/ShowParamSegment.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/antlr/sql/segment/ShowParamSegment.java @@ -1,9 +1,31 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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. + *

+ */ + package io.shardingsphere.core.parsing.antlr.sql.segment; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +/** + * Show param segment. + * + * @author loxp + */ @RequiredArgsConstructor @Getter @Setter From a8daf2290452c9518279a4d94ef4ce1979953782 Mon Sep 17 00:00:00 2001 From: loxp Date: Sun, 2 Dec 2018 15:02:58 +0800 Subject: [PATCH 09/13] add unit test --- .../antlr_supported_sql/postgre/dal/reset.xml | 5 +++++ .../antlr_supported_sql/postgre/dal/set.xml | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 sharding-sql-test/src/main/resources/antlr_supported_sql/postgre/dal/reset.xml create mode 100644 sharding-sql-test/src/main/resources/antlr_supported_sql/postgre/dal/set.xml diff --git a/sharding-sql-test/src/main/resources/antlr_supported_sql/postgre/dal/reset.xml b/sharding-sql-test/src/main/resources/antlr_supported_sql/postgre/dal/reset.xml new file mode 100644 index 0000000000000..1be84015116c6 --- /dev/null +++ b/sharding-sql-test/src/main/resources/antlr_supported_sql/postgre/dal/reset.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/sharding-sql-test/src/main/resources/antlr_supported_sql/postgre/dal/set.xml b/sharding-sql-test/src/main/resources/antlr_supported_sql/postgre/dal/set.xml new file mode 100644 index 0000000000000..82045c891e4d8 --- /dev/null +++ b/sharding-sql-test/src/main/resources/antlr_supported_sql/postgre/dal/set.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + From 637d1f468d6083d7bd17f0a0077a4a3eb4350c57 Mon Sep 17 00:00:00 2001 From: loxp Date: Sun, 2 Dec 2018 15:46:54 +0800 Subject: [PATCH 10/13] modify statement checking order in SQLParserFactory --- .../core/parsing/parser/sql/SQLParserFactory.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java index 2ccc515d6334b..2bb028185695f 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLParserFactory.java @@ -89,9 +89,6 @@ public static SQLParser newInstance( if (DMLStatement.isDML(tokenType)) { return getDMLParser(dbType, tokenType, shardingRule, lexerEngine, shardingTableMetaData); } - if (TCLStatement.isTCL(tokenType)) { - return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData); - } if (DALStatement.isDAL(tokenType)) { if (PostgreSQLKeyword.SHOW == tokenType) { new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData); @@ -103,6 +100,9 @@ public static SQLParser newInstance( if (DALStatement.isDAL(tokenType, secondaryTokenType)) { new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData); } + if (TCLStatement.isTCL(tokenType)) { + return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData); + } if (DDLStatement.isDDL(tokenType, secondaryTokenType)) { return new AntlrParsingEngine(dbType, sql, shardingRule, shardingTableMetaData); } From e193e79acb4239a72454fe4608579689dd311eb1 Mon Sep 17 00:00:00 2001 From: loxp Date: Sun, 2 Dec 2018 16:13:38 +0800 Subject: [PATCH 11/13] fix file format --- .../core/routing/router/sharding/ParsingSQLRouter.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java index 5709d149d30ea..ebb37d085f471 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/routing/router/sharding/ParsingSQLRouter.java @@ -139,9 +139,8 @@ private RoutingResult route(final SQLStatement sqlStatement, final ShardingCondi routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule); } else if (sqlStatement instanceof DDLStatement || (sqlStatement instanceof DCLStatement && ((DCLStatement) sqlStatement).isGrantForSingleTable())) { routingEngine = new TableBroadcastRoutingEngine(shardingRule, sqlStatement); - } else if (sqlStatement instanceof ShowDatabasesStatement - || ((sqlStatement instanceof ShowTablesStatement || sqlStatement instanceof ShowTableStatusStatement) && tableNames.isEmpty()) || sqlStatement instanceof SetParamStatement - || sqlStatement instanceof ResetParamStatement) { + } else if (sqlStatement instanceof ShowDatabasesStatement || ((sqlStatement instanceof ShowTablesStatement || sqlStatement instanceof ShowTableStatusStatement) && tableNames.isEmpty()) + || sqlStatement instanceof SetParamStatement || sqlStatement instanceof ResetParamStatement) { routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule); } else if (sqlStatement instanceof DCLStatement) { routingEngine = new InstanceBroadcastRoutingEngine(shardingRule, shardingDataSourceMetaData); From 4571fc694d4a68177caa96f6c5457b316c7e1cc0 Mon Sep 17 00:00:00 2001 From: loxp Date: Mon, 3 Dec 2018 09:15:12 +0800 Subject: [PATCH 12/13] modify antlr grammar file format --- .../src/main/antlr4/imports/PostgreSQLDALStatement.g4 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sharding-core/src/main/antlr4/imports/PostgreSQLDALStatement.g4 b/sharding-core/src/main/antlr4/imports/PostgreSQLDALStatement.g4 index fd58687da6048..2b5e2d5dacd87 100644 --- a/sharding-core/src/main/antlr4/imports/PostgreSQLDALStatement.g4 +++ b/sharding-core/src/main/antlr4/imports/PostgreSQLDALStatement.g4 @@ -20,9 +20,7 @@ setClause ; timeZoneType - : NUMBER - | LOCAL - | DEFAULT + : NUMBER | LOCAL | DEFAULT ; resetParam From 5813fcd89666624ef43a3fef9d9c6cff02deaa59 Mon Sep 17 00:00:00 2001 From: loxp Date: Mon, 3 Dec 2018 09:48:38 +0800 Subject: [PATCH 13/13] fix file format --- .../statement/ResetParamStatement.java | 22 +++++++++++++++++++ .../statement/SetParamStatement.java | 22 +++++++++++++++++++ .../postgresql/statement/ShowStatement.java | 22 +++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ResetParamStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ResetParamStatement.java index ec50b2c3f6fcf..cb802b94e6c82 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ResetParamStatement.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ResetParamStatement.java @@ -1,6 +1,28 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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. + *

+ */ + package io.shardingsphere.core.parsing.parser.dialect.postgresql.statement; import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement; +/** + * Reset param statement. + * + * @author loxp + */ public class ResetParamStatement extends DALStatement { } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/SetParamStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/SetParamStatement.java index 5d3382e28e71d..732d06737beb6 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/SetParamStatement.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/SetParamStatement.java @@ -1,6 +1,28 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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. + *

+ */ + package io.shardingsphere.core.parsing.parser.dialect.postgresql.statement; import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement; +/** + * Set param statement. + * + * @author loxp + */ public class SetParamStatement extends DALStatement { } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ShowStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ShowStatement.java index dbdfe5096c30f..d0cba24fe9e9d 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ShowStatement.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/statement/ShowStatement.java @@ -1,9 +1,31 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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. + *

+ */ + package io.shardingsphere.core.parsing.parser.dialect.postgresql.statement; import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement; import lombok.Getter; import lombok.Setter; +/** + * Show statement. + * + * @author loxp + */ @Getter @Setter public final class ShowStatement extends DALStatement {