From c3e6e390cb4e564d1056ec6c67a136afe7ae51dd Mon Sep 17 00:00:00 2001 From: haocao Date: Wed, 17 Jan 2018 15:45:58 +0800 Subject: [PATCH] For issue #540. --- .../expression/AliasExpressionParser.java | 9 +++--- .../MySQLAliasExpressionParser.java | 17 ++++++++++- .../OracleAliasExpressionParser.java | 30 ++++++++++++++++++- .../PostgreSQLAliasExpressionParser.java | 8 ++++- .../SQLServerAliasExpressionParser.java | 17 ++++++++++- 5 files changed, 73 insertions(+), 8 deletions(-) diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/clause/expression/AliasExpressionParser.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/clause/expression/AliasExpressionParser.java index e1c7f0a88e081..83a763bdf03e5 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/clause/expression/AliasExpressionParser.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/clause/expression/AliasExpressionParser.java @@ -49,10 +49,11 @@ private Optional parseAlias() { private TokenType[] getDefaultAvailableKeywordsForSelectItemAlias() { return new TokenType[] { - Literals.IDENTIFIER, Literals.CHARS, DefaultKeyword.TABLESPACE, DefaultKeyword.FUNCTION, DefaultKeyword.SEQUENCE, DefaultKeyword.OF, DefaultKeyword.DO, - DefaultKeyword.NO, DefaultKeyword.TEMPORARY, DefaultKeyword.TEMP, DefaultKeyword.COMMENT, DefaultKeyword.AFTER, DefaultKeyword.INSTEAD, DefaultKeyword.ROW, - DefaultKeyword.STATEMENT, DefaultKeyword.EXECUTE, DefaultKeyword.BITMAP, DefaultKeyword.NOSORT, DefaultKeyword.REVERSE, DefaultKeyword.COMPILE, - DefaultKeyword.PASSWORD, DefaultKeyword.USER, DefaultKeyword.END, DefaultKeyword.CASE, DefaultKeyword.KEY, DefaultKeyword.INTERVAL, DefaultKeyword.CONSTRAINT, }; + Literals.IDENTIFIER, Literals.CHARS, DefaultKeyword.BITMAP, DefaultKeyword.NOSORT, DefaultKeyword.REVERSE, DefaultKeyword.COMPILE, DefaultKeyword.NEW, DefaultKeyword.ADVISE, + DefaultKeyword.AVG, DefaultKeyword.MAX, DefaultKeyword.MIN, DefaultKeyword.SUM, DefaultKeyword.COUNT, DefaultKeyword.ROUND, DefaultKeyword.TRUNC, DefaultKeyword.LENGTH, + DefaultKeyword.CHAR_LENGTH, DefaultKeyword.SUBSTR, DefaultKeyword.INSTR, DefaultKeyword.INITCAP, DefaultKeyword.UPPER, DefaultKeyword.LOWER, DefaultKeyword.LTRIM, DefaultKeyword.RTRIM, + DefaultKeyword.TRANSLATE, DefaultKeyword.LPAD, DefaultKeyword.RPAD, DefaultKeyword.DECODE, DefaultKeyword.NVL, + }; } protected TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias() { diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/mysql/clause/expression/MySQLAliasExpressionParser.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/mysql/clause/expression/MySQLAliasExpressionParser.java index 3677e9256a2e2..979e3d65549bb 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/mysql/clause/expression/MySQLAliasExpressionParser.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/mysql/clause/expression/MySQLAliasExpressionParser.java @@ -1,6 +1,7 @@ package io.shardingjdbc.core.parsing.parser.dialect.mysql.clause.expression; import io.shardingjdbc.core.parsing.lexer.LexerEngine; +import io.shardingjdbc.core.parsing.lexer.dialect.mysql.MySQLKeyword; import io.shardingjdbc.core.parsing.lexer.token.DefaultKeyword; import io.shardingjdbc.core.parsing.lexer.token.TokenType; import io.shardingjdbc.core.parsing.parser.clause.expression.AliasExpressionParser; @@ -18,7 +19,21 @@ public MySQLAliasExpressionParser(final LexerEngine lexerEngine) { @Override protected TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias() { - return new TokenType[0]; + return new TokenType[] { + DefaultKeyword.VIEW, DefaultKeyword.TABLESPACE, DefaultKeyword.FUNCTION, DefaultKeyword.SEQUENCE, DefaultKeyword.OF, DefaultKeyword.DO, DefaultKeyword.NO, DefaultKeyword.WITHOUT, + DefaultKeyword.TEMPORARY, DefaultKeyword.TEMP, DefaultKeyword.COMMENT, DefaultKeyword.AFTER, DefaultKeyword.INSTEAD, DefaultKeyword.ROW, DefaultKeyword.STATEMENT, + DefaultKeyword.EXECUTE, DefaultKeyword.MODIFY, DefaultKeyword.ENABLE, DefaultKeyword.DISABLE, DefaultKeyword.VALIDATE, DefaultKeyword.USER, DefaultKeyword.IDENTIFIED, + DefaultKeyword.TRUNCATE, DefaultKeyword.END, DefaultKeyword.FULL, DefaultKeyword.CLOSE, DefaultKeyword.CAST, DefaultKeyword.ESCAPE, DefaultKeyword.SOME, DefaultKeyword.UNTIL, + DefaultKeyword.OPEN, DefaultKeyword.OVER, DefaultKeyword.PASSWORD, DefaultKeyword.LOCAL, DefaultKeyword.GLOBAL, DefaultKeyword.STORAGE, DefaultKeyword.DATA, + DefaultKeyword.COALESCE, DefaultKeyword.VARCHAR2, DefaultKeyword.DATE, DefaultKeyword.TIME, DefaultKeyword.BOOLEAN, DefaultKeyword.ANY, DefaultKeyword.GREATEST, + DefaultKeyword.LEAST, DefaultKeyword.POSITION, DefaultKeyword.SUBSTRING, DefaultKeyword.TRIM, + MySQLKeyword.OFFSET, MySQLKeyword.VALUE, MySQLKeyword.BEGIN, MySQLKeyword.QUICK, MySQLKeyword.CACHE, MySQLKeyword.SQL_CACHE, MySQLKeyword.SQL_NO_CACHE, MySQLKeyword.SQL_BUFFER_RESULT, + MySQLKeyword.FIRST, MySQLKeyword.ALGORITHM, MySQLKeyword.DISCARD, MySQLKeyword.IMPORT, MySQLKeyword.VALIDATION, MySQLKeyword.REORGANIZE, MySQLKeyword.EXCHANGE, MySQLKeyword.REBUILD, + MySQLKeyword.REPAIR, MySQLKeyword.REMOVE, MySQLKeyword.UPGRADE, MySQLKeyword.KEY_BLOCK_SIZE, MySQLKeyword.AUTO_INCREMENT, MySQLKeyword.AVG_ROW_LENGTH, MySQLKeyword.CHECKSUM, + MySQLKeyword.COMPRESSION, MySQLKeyword.CONNECTION, MySQLKeyword.DIRECTORY, MySQLKeyword.DELAY_KEY_WRITE, MySQLKeyword.ENCRYPTION, MySQLKeyword.ENGINE, MySQLKeyword.INSERT_METHOD, + MySQLKeyword.MAX_ROWS, MySQLKeyword.MIN_ROWS, MySQLKeyword.PACK_KEYS, MySQLKeyword.ROW_FORMAT, MySQLKeyword.DYNAMIC, MySQLKeyword.FIXED, MySQLKeyword.COMPRESSED, MySQLKeyword.REDUNDANT, + MySQLKeyword.COMPACT, MySQLKeyword.STATS_AUTO_RECALC, MySQLKeyword.STATS_PERSISTENT, MySQLKeyword.STATS_SAMPLE_PAGES, MySQLKeyword.DISK, MySQLKeyword.MEMORY, MySQLKeyword.ROLLUP, + }; } @Override diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/oracle/clause/expression/OracleAliasExpressionParser.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/oracle/clause/expression/OracleAliasExpressionParser.java index f383babf34fea..5cf44198752bb 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/oracle/clause/expression/OracleAliasExpressionParser.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/oracle/clause/expression/OracleAliasExpressionParser.java @@ -1,6 +1,8 @@ package io.shardingjdbc.core.parsing.parser.dialect.oracle.clause.expression; import io.shardingjdbc.core.parsing.lexer.LexerEngine; +import io.shardingjdbc.core.parsing.lexer.dialect.oracle.OracleKeyword; +import io.shardingjdbc.core.parsing.lexer.token.DefaultKeyword; import io.shardingjdbc.core.parsing.lexer.token.TokenType; import io.shardingjdbc.core.parsing.parser.clause.expression.AliasExpressionParser; @@ -17,7 +19,33 @@ public OracleAliasExpressionParser(final LexerEngine lexerEngine) { @Override protected TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias() { - return new TokenType[0]; + return new TokenType[]{ + DefaultKeyword.SCHEMA, DefaultKeyword.DATABASE, DefaultKeyword.PROCEDURE, DefaultKeyword.TABLESPACE, DefaultKeyword.FUNCTION, DefaultKeyword.SEQUENCE, DefaultKeyword.CURSOR, + DefaultKeyword.IF, DefaultKeyword.WHILE, DefaultKeyword.DO, DefaultKeyword.NO, DefaultKeyword.WITHOUT, DefaultKeyword.TRUE, DefaultKeyword.FALSE, DefaultKeyword.TEMPORARY, + DefaultKeyword.TEMP, DefaultKeyword.REPLACE, DefaultKeyword.BEFORE, DefaultKeyword.AFTER, DefaultKeyword.INSTEAD, DefaultKeyword.EACH, DefaultKeyword.STATEMENT, + DefaultKeyword.EXECUTE, DefaultKeyword.FULLTEXT, DefaultKeyword.ENABLE, DefaultKeyword.DISABLE, DefaultKeyword.TRUNCATE, DefaultKeyword.CASCADE, DefaultKeyword.AS, + DefaultKeyword.CASE, DefaultKeyword.WHEN, DefaultKeyword.END, DefaultKeyword.LEFT, DefaultKeyword.RIGHT, DefaultKeyword.FULL, DefaultKeyword.INNER, DefaultKeyword.OUTER, + DefaultKeyword.CROSS, DefaultKeyword.JOIN, DefaultKeyword.USE, DefaultKeyword.USING, DefaultKeyword.NATURAL, DefaultKeyword.DECLARE, DefaultKeyword.FETCH, DefaultKeyword.CLOSE, + DefaultKeyword.CAST, DefaultKeyword.ESCAPE, DefaultKeyword.SOME, DefaultKeyword.LEAVE, DefaultKeyword.ITERATE, DefaultKeyword.REPEAT, DefaultKeyword.UNTIL, DefaultKeyword.OPEN, + DefaultKeyword.OUT, DefaultKeyword.INOUT, DefaultKeyword.OVER, DefaultKeyword.LOOP, DefaultKeyword.EXPLAIN, DefaultKeyword.PASSWORD, DefaultKeyword.LOCAL, DefaultKeyword.GLOBAL, + DefaultKeyword.STORAGE, DefaultKeyword.DATA, DefaultKeyword.COALESCE, DefaultKeyword.CHARACTER, DefaultKeyword.VARYING, DefaultKeyword.INT, DefaultKeyword.DEC, DefaultKeyword.NUMERIC, + DefaultKeyword.REAL, DefaultKeyword.DOUBLE, DefaultKeyword.PRECISION, DefaultKeyword.TIME, DefaultKeyword.INTERVAL, DefaultKeyword.BOOLEAN, DefaultKeyword.BLOB, DefaultKeyword.XOR, + DefaultKeyword.GREATEST, DefaultKeyword.LEAST, DefaultKeyword.POSITION, DefaultKeyword.SUBSTRING, DefaultKeyword.TRIM, DefaultKeyword.BOTH, DefaultKeyword.LEADING, + DefaultKeyword.TRAILING, DefaultKeyword.CONVERT, DefaultKeyword.CONSTRAINT, DefaultKeyword.PRIMARY, DefaultKeyword.FOREIGN, DefaultKeyword.KEY, DefaultKeyword.REFERENCES, + OracleKeyword.LOCKED, OracleKeyword.COMMIT, OracleKeyword.CREATION, OracleKeyword.UPDATED, OracleKeyword.UPSERT, OracleKeyword.CONNECT_BY_ROOT, + OracleKeyword.STORE, OracleKeyword.MERGE, OracleKeyword.PURGE, OracleKeyword.GOTO, OracleKeyword.ONLY, OracleKeyword.AUTOMATIC, OracleKeyword.MAIN, + OracleKeyword.PCTINCREASE, OracleKeyword.CHUNK, OracleKeyword.LIMIT, OracleKeyword.GROUPING, OracleKeyword.ROLLUP, OracleKeyword.CUBE, + OracleKeyword.UNLIMITED, OracleKeyword.SIBLINGS, OracleKeyword.INCLUDE, OracleKeyword.EXCLUDE, OracleKeyword.PIVOT, OracleKeyword.UNPIVOT, + OracleKeyword.EXCEPTION, OracleKeyword.EXCEPTIONS, OracleKeyword.ERRORS, OracleKeyword.DEFERRED, OracleKeyword.NAV, OracleKeyword.VERSIONS, + OracleKeyword.WAIT, OracleKeyword.SAMPLE, OracleKeyword.CONTINUE, OracleKeyword.TIMESTAMP, OracleKeyword.SEGMENT, OracleKeyword.PARTITION, + OracleKeyword.SUBPARTITION, OracleKeyword.RETURN, OracleKeyword.RETURNING, OracleKeyword.REJECT, OracleKeyword.MAXTRANS, OracleKeyword.MINEXTENTS, + OracleKeyword.BEGIN, OracleKeyword.SAVEPOINT, OracleKeyword.MATCHED, OracleKeyword.LOB, OracleKeyword.DIMENSION, OracleKeyword.FORCE, OracleKeyword.FIRST, + OracleKeyword.NEXT, OracleKeyword.LAST, OracleKeyword.EXTRACT, OracleKeyword.RULES, OracleKeyword.INITIALLY, OracleKeyword.KEEP, OracleKeyword.KEEP_DUPLICATES, + OracleKeyword.REFERENCE, OracleKeyword.SEED, OracleKeyword.IGNORE, OracleKeyword.MEASURES, OracleKeyword.LOGGING, OracleKeyword.MAXSIZE, OracleKeyword.FLASH_CACHE, + OracleKeyword.CELL_FLASH_CACHE, OracleKeyword.SKIP, OracleKeyword.NONE, OracleKeyword.NULLS, OracleKeyword.SINGLE, OracleKeyword.SCN, OracleKeyword.INITRANS, + OracleKeyword.BLOCK, OracleKeyword.SEQUENTIAL, OracleKeyword.BINARY, OracleKeyword.INSENSITIVE, OracleKeyword.SCROLL, OracleKeyword.XML, OracleKeyword.MINVALUE, + OracleKeyword.MAXVALUE, OracleKeyword.CACHE, OracleKeyword.NOCACHE, OracleKeyword.CYCLE, OracleKeyword.NOCYCLE, + }; } @Override diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/postgresql/clause/expression/PostgreSQLAliasExpressionParser.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/postgresql/clause/expression/PostgreSQLAliasExpressionParser.java index 41fb09f0b8cc0..ab94e5073ed90 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/postgresql/clause/expression/PostgreSQLAliasExpressionParser.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/postgresql/clause/expression/PostgreSQLAliasExpressionParser.java @@ -1,6 +1,8 @@ package io.shardingjdbc.core.parsing.parser.dialect.postgresql.clause.expression; import io.shardingjdbc.core.parsing.lexer.LexerEngine; +import io.shardingjdbc.core.parsing.lexer.dialect.postgresql.PostgreSQLKeyword; +import io.shardingjdbc.core.parsing.lexer.token.DefaultKeyword; import io.shardingjdbc.core.parsing.lexer.token.TokenType; import io.shardingjdbc.core.parsing.parser.clause.expression.AliasExpressionParser; @@ -17,7 +19,11 @@ public PostgreSQLAliasExpressionParser(final LexerEngine lexerEngine) { @Override protected TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias() { - return new TokenType[0]; + return new TokenType[] { + DefaultKeyword.WHILE, DefaultKeyword.FULLTEXT, DefaultKeyword.MODIFY, DefaultKeyword.IDENTIFIED, DefaultKeyword.USE, DefaultKeyword.LEAVE, DefaultKeyword.ITERATE, + DefaultKeyword.REPEAT, DefaultKeyword.OPEN, DefaultKeyword.LOOP, DefaultKeyword.VARCHAR2, DefaultKeyword.DATE, DefaultKeyword.BLOB, DefaultKeyword.XOR, DefaultKeyword.CONVERT, + PostgreSQLKeyword.PLAIN, PostgreSQLKeyword.EXTENDED, PostgreSQLKeyword.MAIN, + }; } @Override diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/sqlserver/clause/expression/SQLServerAliasExpressionParser.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/sqlserver/clause/expression/SQLServerAliasExpressionParser.java index 55363c1f1a811..c62b3f94a53cc 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/sqlserver/clause/expression/SQLServerAliasExpressionParser.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/sqlserver/clause/expression/SQLServerAliasExpressionParser.java @@ -1,6 +1,8 @@ package io.shardingjdbc.core.parsing.parser.dialect.sqlserver.clause.expression; import io.shardingjdbc.core.parsing.lexer.LexerEngine; +import io.shardingjdbc.core.parsing.lexer.dialect.sqlserver.SQLServerKeyword; +import io.shardingjdbc.core.parsing.lexer.token.DefaultKeyword; import io.shardingjdbc.core.parsing.lexer.token.TokenType; import io.shardingjdbc.core.parsing.parser.clause.expression.AliasExpressionParser; @@ -17,7 +19,20 @@ public SQLServerAliasExpressionParser(final LexerEngine lexerEngine) { @Override protected TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias() { - return new TokenType[0]; + return new TokenType[] { + DefaultKeyword.TABLESPACE, DefaultKeyword.SEQUENCE, DefaultKeyword.DO, DefaultKeyword.NO, DefaultKeyword.WITHOUT, DefaultKeyword.TRUE, DefaultKeyword.FALSE, DefaultKeyword.TEMPORARY, + DefaultKeyword.TEMP, DefaultKeyword.COMMENT, DefaultKeyword.REPLACE, DefaultKeyword.BEFORE, DefaultKeyword.AFTER, DefaultKeyword.INSTEAD, DefaultKeyword.EACH, DefaultKeyword.ROW, + DefaultKeyword.STATEMENT, DefaultKeyword.FULLTEXT, DefaultKeyword.MODIFY, DefaultKeyword.RENAME, DefaultKeyword.ENABLE, DefaultKeyword.DISABLE, DefaultKeyword.VALIDATE, + DefaultKeyword.IDENTIFIED, DefaultKeyword.USING, DefaultKeyword.NATURAL, DefaultKeyword.CAST, DefaultKeyword.LOCK, DefaultKeyword.LEAVE, DefaultKeyword.ITERATE, DefaultKeyword.REPEAT, + DefaultKeyword.UNTIL, DefaultKeyword.OUT, DefaultKeyword.INOUT, DefaultKeyword.LOOP, DefaultKeyword.EXPLAIN, DefaultKeyword.PASSWORD, DefaultKeyword.LOCAL, DefaultKeyword.GLOBAL, + DefaultKeyword.STORAGE, DefaultKeyword.DATA, DefaultKeyword.CHAR, DefaultKeyword.CHARACTER, DefaultKeyword.VARCHAR, DefaultKeyword.VARCHAR2, DefaultKeyword.INTEGER, DefaultKeyword.INT, + DefaultKeyword.SMALLINT, DefaultKeyword.DECIMAL, DefaultKeyword.DEC, DefaultKeyword.NUMERIC, DefaultKeyword.FLOAT, DefaultKeyword.REAL, DefaultKeyword.PRECISION, DefaultKeyword.DATE, + DefaultKeyword.TIME, DefaultKeyword.INTERVAL, DefaultKeyword.BOOLEAN, DefaultKeyword.BLOB, DefaultKeyword.XOR, DefaultKeyword.GREATEST, DefaultKeyword.LEAST, DefaultKeyword.POSITION, + DefaultKeyword.SUBSTRING, DefaultKeyword.TRIM, DefaultKeyword.BOTH, DefaultKeyword.LEADING, DefaultKeyword.TRAILING, + SQLServerKeyword.TIES, SQLServerKeyword.ROW_NUMBER, SQLServerKeyword.PARTITION, SQLServerKeyword.ONLY, SQLServerKeyword.OUTPUT, SQLServerKeyword.AUTO, SQLServerKeyword.TYPE, + SQLServerKeyword.ELEMENTS, SQLServerKeyword.XML, SQLServerKeyword.XSINIL, SQLServerKeyword.XMLSCHEMA, SQLServerKeyword.TYP, SQLServerKeyword.APPLY, SQLServerKeyword.REDUCE, + SQLServerKeyword.REPLICATE, SQLServerKeyword.EXTRACT, SQLServerKeyword.REDISTRIBUTE, + }; } @Override