mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -23,7 +23,8 @@ import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
import com.alibaba.druid.util.FnvConstants;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -35,10 +36,10 @@ public class DB2ExprParser extends SQLExprParser {
|
||||
static {
|
||||
String[] strings = { "AVG", "COUNT", "MAX", "MIN", "STDDEV", "SUM", "ROW_NUMBER",
|
||||
"ROWNUMBER" };
|
||||
AGGREGATE_FUNCTIONS_CODES = FNVUtils.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FNVUtils.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
@@ -61,17 +62,16 @@ public class DB2ExprParser extends SQLExprParser {
|
||||
}
|
||||
|
||||
public SQLExpr primaryRest(SQLExpr expr) {
|
||||
if (lexer.identifierEquals(FNVUtils.VALUE)) {
|
||||
if (lexer.identifierEquals(FnvConstants.VALUE)) {
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
|
||||
String ident = identExpr.getName();
|
||||
if (ident.equalsIgnoreCase("NEXT")) {
|
||||
if (identExpr.hashCode64() == FnvConstants.NEXT) {
|
||||
lexer.nextToken();
|
||||
accept(Token.FOR);
|
||||
SQLName seqName = this.name();
|
||||
SQLSequenceExpr seqExpr = new SQLSequenceExpr(seqName, SQLSequenceExpr.Function.NextVal);
|
||||
return seqExpr;
|
||||
} else if (ident.equalsIgnoreCase("PREVIOUS")) {
|
||||
} else if (identExpr.hashCode64() == FnvConstants.PREVIOUS) {
|
||||
lexer.nextToken();
|
||||
accept(Token.FOR);
|
||||
SQLName seqName = this.name();
|
||||
@@ -79,21 +79,19 @@ public class DB2ExprParser extends SQLExprParser {
|
||||
return seqExpr;
|
||||
}
|
||||
}
|
||||
} else if (lexer.identifierEquals("DATE")) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.DATE)) {
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
|
||||
String ident = identExpr.getName();
|
||||
if (ident.equalsIgnoreCase("CURRENT")) {
|
||||
if (identExpr.hashCode64() == FnvConstants.CURRENT) {
|
||||
lexer.nextToken();
|
||||
|
||||
expr = new SQLIdentifierExpr("CURRENT DATE");
|
||||
}
|
||||
}
|
||||
} else if (lexer.identifierEquals("TIMESTAMP")) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.TIMESTAMP)) {
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
|
||||
String ident = identExpr.getName();
|
||||
if (ident.equalsIgnoreCase("CURRENT")) {
|
||||
if (identExpr.hashCode64() == FnvConstants.CURRENT) {
|
||||
lexer.nextToken();
|
||||
|
||||
expr = new SQLIdentifierExpr("CURRENT DATE");
|
||||
|
||||
@@ -17,16 +17,15 @@ package com.alibaba.druid.sql.dialect.mysql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
public class MySqlUserName extends MySqlExprImpl implements SQLName, Cloneable {
|
||||
|
||||
private String userName;
|
||||
private String host;
|
||||
|
||||
protected transient long userName_hash;
|
||||
|
||||
protected long hashCode64;
|
||||
private long userNameHashCod64;
|
||||
private long hashCode64;
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
@@ -35,8 +34,8 @@ public class MySqlUserName extends MySqlExprImpl implements SQLName, Cloneable {
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
|
||||
hashCode64 = 0;
|
||||
userName_hash = 0;
|
||||
this.hashCode64 = 0;
|
||||
this.userNameHashCod64 = 0;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
@@ -46,8 +45,8 @@ public class MySqlUserName extends MySqlExprImpl implements SQLName, Cloneable {
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
|
||||
hashCode64 = 0;
|
||||
userName_hash = 0;
|
||||
this.hashCode64 = 0;
|
||||
this.userNameHashCod64 = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,45 +65,36 @@ public class MySqlUserName extends MySqlExprImpl implements SQLName, Cloneable {
|
||||
|
||||
public MySqlUserName clone() {
|
||||
MySqlUserName x = new MySqlUserName();
|
||||
|
||||
x.userName = userName;
|
||||
x.host = host;
|
||||
x.host = host;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public long name_hash_lower() {
|
||||
if (userName_hash == 0
|
||||
public long nameHashCode64() {
|
||||
if (userNameHashCod64 == 0
|
||||
&& userName != null) {
|
||||
final int len = userName.length();
|
||||
|
||||
boolean quote = false;
|
||||
|
||||
String name = this.userName;
|
||||
if (len > 2) {
|
||||
char c0 = name.charAt(0);
|
||||
char c1 = name.charAt(len - 1);
|
||||
if (c0 == c1
|
||||
&& (c0 == '`' || c1 == '"')) {
|
||||
quote = true;
|
||||
}
|
||||
}
|
||||
if (quote) {
|
||||
userName_hash = FNVUtils.fnv_64_lower(name, 1, len -1);
|
||||
} else {
|
||||
userName_hash = FNVUtils.fnv_64_lower(name);
|
||||
}
|
||||
userNameHashCod64 = FnvHash.hashCode64(userName);
|
||||
}
|
||||
return userName_hash;
|
||||
return userNameHashCod64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long hashCode64() {
|
||||
if (hashCode64 == 0) {
|
||||
if (host != null) {
|
||||
hashCode64 = FNVUtils.fnv_64_lower(host, userName);
|
||||
long hash = FnvHash.hashCode64(host);
|
||||
hash ^= '@';
|
||||
hash *= 0x100000001b3L;
|
||||
hash = FnvHash.hashCode64(hash, userName);
|
||||
|
||||
hashCode64 = hash;
|
||||
} else {
|
||||
hashCode64 = name_hash_lower();
|
||||
hashCode64 = nameHashCode64();
|
||||
}
|
||||
}
|
||||
|
||||
return hashCode64;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,11 @@ import com.alibaba.druid.sql.ast.SQLPartition;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionValue;
|
||||
import com.alibaba.druid.sql.ast.SQLSubPartition;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLHexExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLUnaryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLUnaryOperator;
|
||||
@@ -51,9 +49,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlMatchAgainstExpr.Search
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName;
|
||||
import com.alibaba.druid.sql.ast.SQLLimit;
|
||||
import com.alibaba.druid.sql.parser.*;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
import com.alibaba.druid.util.FnvConstants;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -65,10 +63,10 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
static {
|
||||
String[] strings = { "AVG", "COUNT", "GROUP_CONCAT", "MAX", "MIN", "STDDEV", "SUM" };
|
||||
AGGREGATE_FUNCTIONS_CODES = FNVUtils.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FNVUtils.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
@@ -104,7 +102,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
public SQLExpr primary() {
|
||||
final Token tok = lexer.token();
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.OUTFILE)) {
|
||||
if (lexer.identifierEquals(FnvConstants.OUTFILE)) {
|
||||
lexer.nextToken();
|
||||
SQLExpr file = primary();
|
||||
SQLExpr expr = new MySqlOutFileExpr(file);
|
||||
@@ -177,7 +175,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
MySqlCharExpr mysqlCharExpr = new MySqlCharExpr(charValue);
|
||||
mysqlCharExpr.setCharset(identExpr.getName());
|
||||
if (lexer.identifierEquals(FNVUtils.COLLATE)) {
|
||||
if (lexer.identifierEquals(FnvConstants.COLLATE)) {
|
||||
lexer.nextToken();
|
||||
|
||||
String collate = lexer.stringVal();
|
||||
@@ -212,7 +210,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
return primaryRest(expr);
|
||||
}
|
||||
} else if ("COLLATE".equalsIgnoreCase(lexer.stringVal())) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.COLLATE)) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -234,7 +232,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
return primaryRest(expr);
|
||||
} else if (expr instanceof SQLVariantRefExpr) {
|
||||
if ("COLLATE".equalsIgnoreCase(lexer.stringVal())) {
|
||||
if (lexer.identifierEquals(FnvConstants.COLLATE)) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() != Token.IDENTIFIER
|
||||
@@ -343,7 +341,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
if (lexer.token() == Token.IN) {
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals(FNVUtils.NATURAL)) {
|
||||
if (lexer.identifierEquals(FnvConstants.NATURAL)) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("LANGUAGE");
|
||||
acceptIdentifier("MODE");
|
||||
@@ -355,7 +353,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
} else {
|
||||
matchAgainstExpr.setSearchModifier(SearchModifier.IN_NATURAL_LANGUAGE_MODE);
|
||||
}
|
||||
} else if (lexer.identifierEquals(FNVUtils.BOOLEAN)) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.BOOLEAN)) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("MODE");
|
||||
matchAgainstExpr.setSearchModifier(SearchModifier.IN_BOOLEAN_MODE);
|
||||
@@ -437,12 +435,12 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
SQLExpr expr = this.expr();
|
||||
column.setOnUpdate(expr);
|
||||
}
|
||||
if (lexer.identifierEquals(FNVUtils.CHARSET)) {
|
||||
if (lexer.identifierEquals(FnvConstants.CHARSET)) {
|
||||
lexer.nextToken();
|
||||
MySqlCharExpr charSetCollateExpr=new MySqlCharExpr();
|
||||
charSetCollateExpr.setCharset(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals(FNVUtils.COLLATE)) {
|
||||
if (lexer.identifierEquals(FnvConstants.COLLATE)) {
|
||||
lexer.nextToken();
|
||||
charSetCollateExpr.setCollate(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
@@ -450,13 +448,14 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
column.setCharsetExpr(charSetCollateExpr);
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
if (lexer.identifierEquals("AUTO_INCREMENT")) {
|
||||
if (lexer.identifierEquals(FnvConstants.AUTO_INCREMENT)) {
|
||||
lexer.nextToken();
|
||||
column.setAutoIncrement(true);
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("precision") && column.getDataType().getName().equalsIgnoreCase("double")) {
|
||||
if (lexer.identifierEquals(FnvConstants.PRECISION)
|
||||
&& column.getDataType().nameHashCode64() ==FnvConstants.DOUBLE) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
@@ -464,7 +463,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
throw new ParserException("syntax error " + lexer.info());
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("STORAGE")) {
|
||||
if (lexer.identifierEquals(FnvConstants.STORAGE)) {
|
||||
lexer.nextToken();
|
||||
SQLExpr expr = expr();
|
||||
column.setStorage(expr);
|
||||
@@ -478,12 +477,12 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("STORED")) {
|
||||
if (lexer.identifierEquals(FnvConstants.STORED)) {
|
||||
lexer.nextToken();
|
||||
column.setSorted(true);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("VIRTUAL")) {
|
||||
if (lexer.identifierEquals(FnvConstants.VIRTUAL)) {
|
||||
lexer.nextToken();
|
||||
column.setVirtual(true);
|
||||
}
|
||||
@@ -496,12 +495,12 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
protected SQLDataType parseDataTypeRest(SQLDataType dataType) {
|
||||
super.parseDataTypeRest(dataType);
|
||||
|
||||
if (lexer.identifierEquals("UNSIGNED")) {
|
||||
if (lexer.identifierEquals(FnvConstants.UNSIGNED)) {
|
||||
lexer.nextToken();
|
||||
dataType.getAttributes().put("UNSIGNED", true);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("ZEROFILL")) {
|
||||
if (lexer.identifierEquals(FnvConstants.ZEROFILL)) {
|
||||
lexer.nextToken();
|
||||
dataType.getAttributes().put("ZEROFILL", true);
|
||||
}
|
||||
@@ -515,14 +514,17 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
SQLExpr var = primary();
|
||||
|
||||
String ident = null;
|
||||
long identHash = 0;
|
||||
if (var instanceof SQLIdentifierExpr) {
|
||||
ident = ((SQLIdentifierExpr) var).getName();
|
||||
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) var;
|
||||
ident = identExpr.getName();
|
||||
identHash = identExpr.hashCode64();
|
||||
|
||||
if ("GLOBAL".equalsIgnoreCase(ident)) {
|
||||
if (identHash == FnvConstants.GLOBAL) {
|
||||
ident = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
var = new SQLVariantRefExpr(ident, true);
|
||||
} else if ("SESSION".equalsIgnoreCase(ident)) {
|
||||
} else if (identHash == FnvConstants.SESSION) {
|
||||
ident = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
var = new SQLVariantRefExpr(ident, false);
|
||||
@@ -531,7 +533,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
}
|
||||
}
|
||||
|
||||
if ("NAMES".equalsIgnoreCase(ident)) {
|
||||
if (identHash == FnvConstants.NAMES) {
|
||||
String charset = lexer.stringVal();
|
||||
|
||||
SQLExpr varExpr = null;
|
||||
@@ -550,7 +552,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
accept(Token.LITERAL_CHARS);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("COLLATE")) {
|
||||
if (lexer.identifierEquals(FnvConstants.COLLATE)) {
|
||||
MySqlCharExpr charsetExpr = new MySqlCharExpr(charset);
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -572,7 +574,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
item.setTarget(var);
|
||||
return item;
|
||||
} else if ("CHARACTER".equalsIgnoreCase(ident)) {
|
||||
} else if (identHash == FnvConstants.CHARACTER) {
|
||||
var = new SQLIdentifierExpr("CHARACTER SET");
|
||||
accept(Token.SET);
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -621,7 +623,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
MySqlPrimaryKey primaryKey = new MySqlPrimaryKey();
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.USING)) {
|
||||
if (lexer.identifierEquals(FnvConstants.USING)) {
|
||||
lexer.nextToken();
|
||||
primaryKey.setIndexType(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
@@ -665,7 +667,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
}
|
||||
|
||||
//5.5语法 USING BTREE 放在index 名字后
|
||||
if (lexer.identifierEquals(FNVUtils.USING)) {
|
||||
if (lexer.identifierEquals(FnvConstants.USING)) {
|
||||
lexer.nextToken();
|
||||
unique.setIndexType(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
@@ -690,7 +692,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
|
||||
if (lexer.identifierEquals("USING")) {
|
||||
if (lexer.identifierEquals(FnvConstants.USING)) {
|
||||
lexer.nextToken();
|
||||
unique.setIndexType(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
@@ -722,12 +724,12 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
this.names(fk.getReferencedColumns());
|
||||
accept(Token.RPAREN);
|
||||
|
||||
if (lexer.identifierEquals("MATCH")) {
|
||||
if (lexer.identifierEquals(FnvConstants.MATCH)) {
|
||||
if (lexer.identifierEquals("FULL")) {
|
||||
fk.setReferenceMatch(Match.FULL);
|
||||
} else if (lexer.identifierEquals("PARTIAL")) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.PARTIAL)) {
|
||||
fk.setReferenceMatch(Match.PARTIAL);
|
||||
} else if (lexer.identifierEquals("SIMPLE")) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.SIMPLE)) {
|
||||
fk.setReferenceMatch(Match.SIMPLE);
|
||||
}
|
||||
}
|
||||
@@ -755,19 +757,19 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
protected Option parseReferenceOption() {
|
||||
Option option;
|
||||
if (lexer.token() == Token.RESTRICT || lexer.identifierEquals("RESTRICT")) {
|
||||
if (lexer.token() == Token.RESTRICT || lexer.identifierEquals(FnvConstants.RESTRICT)) {
|
||||
option = Option.RESTRICT;
|
||||
lexer.nextToken();
|
||||
} else if (lexer.identifierEquals("CASCADE")) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.CASCADE)) {
|
||||
option = Option.CASCADE;
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.SET) {
|
||||
lexer.nextToken();
|
||||
accept(Token.NULL);
|
||||
option = Option.SET_NULL;
|
||||
} else if (lexer.identifierEquals("ON")) {
|
||||
} else if (lexer.token() == Token.ON || lexer.identifierEquals(FnvConstants.ON)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals("ACTION")) {
|
||||
if (lexer.identifierEquals(FnvConstants.ACTION)) {
|
||||
option = Option.NO_ACTION;
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
@@ -787,7 +789,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
SQLOrderBy orderBy = this.parseOrderBy();
|
||||
aggregateExpr.putAttribute("ORDER BY", orderBy);
|
||||
}
|
||||
if (lexer.identifierEquals("SEPARATOR")) {
|
||||
if (lexer.identifierEquals(FnvConstants.SEPARATOR)) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLExpr seperator = this.primary();
|
||||
@@ -828,7 +830,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
for (;;) {
|
||||
boolean storage = false;
|
||||
if (lexer.identifierEquals("DATA")) {
|
||||
if (lexer.identifierEquals(FnvConstants.DATA)) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("DIRECTORY");
|
||||
if (lexer.token() == Token.EQ) {
|
||||
@@ -849,22 +851,22 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
lexer.nextToken();
|
||||
}
|
||||
partitionDef.setIndexDirectory(this.expr());
|
||||
} else if (lexer.identifierEquals("MAX_ROWS")) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.MAX_ROWS)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr maxRows = this.primary();
|
||||
partitionDef.setMaxRows(maxRows);
|
||||
} else if (lexer.identifierEquals("MIN_ROWS")) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.MIN_ROWS)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr minRows = this.primary();
|
||||
partitionDef.setMaxRows(minRows);
|
||||
} else if (lexer.identifierEquals("ENGINE") || //
|
||||
(storage = (lexer.token() == Token.STORAGE || lexer.identifierEquals("STORAGE")))) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.ENGINE) || //
|
||||
(storage = (lexer.token() == Token.STORAGE || lexer.identifierEquals(FnvConstants.STORAGE)))) {
|
||||
if (storage) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLSelectParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -104,7 +104,7 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
if (token == (Token.DISTINCT)) {
|
||||
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.identifierEquals(FNVUtils.DISTINCTROW)) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.DISTINCTROW)) {
|
||||
queryBlock.setDistionOption(SQLSetQuantifier.DISTINCTROW);
|
||||
lexer.nextToken();
|
||||
} else if (token == (Token.ALL)) {
|
||||
@@ -112,42 +112,42 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.HIGH_PRIORITY)) {
|
||||
if (lexer.identifierEquals(FnvConstants.HIGH_PRIORITY)) {
|
||||
queryBlock.setHignPriority(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.STRAIGHT_JOIN)) {
|
||||
if (lexer.identifierEquals(FnvConstants.STRAIGHT_JOIN)) {
|
||||
queryBlock.setStraightJoin(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.SQL_SMALL_RESULT)) {
|
||||
if (lexer.identifierEquals(FnvConstants.SQL_SMALL_RESULT)) {
|
||||
queryBlock.setSmallResult(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.SQL_BIG_RESULT)) {
|
||||
if (lexer.identifierEquals(FnvConstants.SQL_BIG_RESULT)) {
|
||||
queryBlock.setBigResult(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.SQL_BUFFER_RESULT)) {
|
||||
if (lexer.identifierEquals(FnvConstants.SQL_BUFFER_RESULT)) {
|
||||
queryBlock.setBufferResult(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.SQL_CACHE)) {
|
||||
if (lexer.identifierEquals(FnvConstants.SQL_CACHE)) {
|
||||
queryBlock.setCache(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.SQL_NO_CACHE)) {
|
||||
if (lexer.identifierEquals(FnvConstants.SQL_NO_CACHE)) {
|
||||
queryBlock.setCache(false);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.SQL_CALC_FOUND_ROWS)) {
|
||||
if (lexer.identifierEquals(FnvConstants.SQL_CALC_FOUND_ROWS)) {
|
||||
queryBlock.setCalcFoundRows(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
@@ -184,10 +184,10 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
|
||||
queryBlock.setForUpdate(true);
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.NO_WAIT) || lexer.identifierEquals(FNVUtils.NOWAIT)) {
|
||||
if (lexer.identifierEquals(FnvConstants.NO_WAIT) || lexer.identifierEquals(FnvConstants.NOWAIT)) {
|
||||
lexer.nextToken();
|
||||
queryBlock.setNoWait(true);
|
||||
} else if (lexer.identifierEquals(FNVUtils.WAIT)) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.WAIT)) {
|
||||
lexer.nextToken();
|
||||
SQLExpr waitTime = this.exprParser.primary();
|
||||
queryBlock.setWaitTime(waitTime);
|
||||
@@ -259,32 +259,32 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.LOW_PRIORITY)) {
|
||||
if (lexer.identifierEquals(FnvConstants.LOW_PRIORITY)) {
|
||||
lexer.nextToken();
|
||||
update.setLowPriority(true);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.IGNORE)) {
|
||||
if (lexer.identifierEquals(FnvConstants.IGNORE)) {
|
||||
lexer.nextToken();
|
||||
update.setIgnore(true);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.COMMIT_ON_SUCCESS)) {
|
||||
if (lexer.identifierEquals(FnvConstants.COMMIT_ON_SUCCESS)) {
|
||||
lexer.nextToken();
|
||||
update.setCommitOnSuccess(true);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.ROLLBACK_ON_FAIL)) {
|
||||
if (lexer.identifierEquals(FnvConstants.ROLLBACK_ON_FAIL)) {
|
||||
lexer.nextToken();
|
||||
update.setRollBackOnFail(true);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.QUEUE_ON_PK)) {
|
||||
if (lexer.identifierEquals(FnvConstants.QUEUE_ON_PK)) {
|
||||
lexer.nextToken();
|
||||
update.setQueryOnPk(true);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.TARGET_AFFECT_ROW)) {
|
||||
if (lexer.identifierEquals(FnvConstants.TARGET_AFFECT_ROW)) {
|
||||
lexer.nextToken();
|
||||
SQLExpr targetAffectRow = this.exprParser.expr();
|
||||
update.setTargetAffectRow(targetAffectRow);
|
||||
@@ -422,7 +422,7 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
}
|
||||
|
||||
protected SQLTableSource parseTableSourceRest(SQLTableSource tableSource) {
|
||||
if (lexer.identifierEquals(FNVUtils.USING)) {
|
||||
if (lexer.identifierEquals(FnvConstants.USING)) {
|
||||
return tableSource;
|
||||
}
|
||||
|
||||
@@ -433,14 +433,14 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
tableSource.getHints().add(hint);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.IGNORE)) {
|
||||
if (lexer.identifierEquals(FnvConstants.IGNORE)) {
|
||||
lexer.nextToken();
|
||||
MySqlIgnoreIndexHint hint = new MySqlIgnoreIndexHint();
|
||||
parseIndexHint(hint);
|
||||
tableSource.getHints().add(hint);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.FORCE)) {
|
||||
if (lexer.identifierEquals(FnvConstants.FORCE)) {
|
||||
lexer.nextToken();
|
||||
MySqlForceIndexHint hint = new MySqlForceIndexHint();
|
||||
parseIndexHint(hint);
|
||||
|
||||
+11
-11
@@ -45,7 +45,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlSelectIntoStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLockTableStatement.LockType;
|
||||
import com.alibaba.druid.sql.parser.*;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvConstants;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -181,7 +181,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
throw new ParserException("syntax error. " + lexer.info());
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.USING)) {
|
||||
if (lexer.identifierEquals(FnvConstants.USING)) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLTableSource tableSource = createSQLSelectParser().parseTableSource();
|
||||
@@ -340,13 +340,13 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
private void parseCreateIndexUsing(SQLCreateIndexStatement stmt) {
|
||||
if (lexer.identifierEquals(FNVUtils.USING)) {
|
||||
if (lexer.identifierEquals(FnvConstants.USING)) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.BTREE)) {
|
||||
if (lexer.identifierEquals(FnvConstants.BTREE)) {
|
||||
stmt.setUsing("BTREE");
|
||||
lexer.nextToken();
|
||||
} else if (lexer.identifierEquals(FNVUtils.HASH)) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.HASH)) {
|
||||
stmt.setUsing("HASH");
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
@@ -962,7 +962,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
accept(Token.STAR);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.ERRORS)) {
|
||||
if (lexer.identifierEquals(FnvConstants.ERRORS)) {
|
||||
lexer.nextToken();
|
||||
|
||||
MySqlShowErrorsStatement stmt = new MySqlShowErrorsStatement();
|
||||
@@ -979,7 +979,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FNVUtils.ERRORS)) {
|
||||
if (lexer.identifierEquals(FnvConstants.ERRORS)) {
|
||||
lexer.nextToken();
|
||||
|
||||
MySqlShowErrorsStatement stmt = new MySqlShowErrorsStatement();
|
||||
@@ -3321,7 +3321,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
stmt.setDbType(dbType);
|
||||
|
||||
if (lexer.token() != Token.PROCEDURE) {
|
||||
if (lexer.identifierEquals("DEFINER")) {
|
||||
if (lexer.identifierEquals(FnvConstants.DEFINER)) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EQ);
|
||||
SQLName definer = this.exprParser.name();
|
||||
@@ -3347,19 +3347,19 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (lexer.identifierEquals("DETERMINISTIC")) {
|
||||
if (lexer.identifierEquals(FnvConstants.DETERMINISTIC)) {
|
||||
lexer.nextToken();
|
||||
stmt.setDeterministic(true);
|
||||
continue;
|
||||
}
|
||||
if (lexer.identifierEquals("CONTAINS")) {
|
||||
if (lexer.identifierEquals(FnvConstants.CONTAINS)) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("SQL");
|
||||
stmt.setContainsSql(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("SQL")) {
|
||||
if (lexer.identifierEquals(FnvConstants.SQL)) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("SECURITY");
|
||||
SQLName authid = this.exprParser.name();
|
||||
|
||||
+3
-4
@@ -49,7 +49,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement.UserSpecification;
|
||||
import com.alibaba.druid.sql.repository.SchemaRepository;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.stat.TableStat.Mode;
|
||||
@@ -485,7 +484,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
SQLName columnName = x.getColumnName();
|
||||
if (columnName != null) {
|
||||
addColumn(table, columnName.getSimpleName(), tableName.name_hash_lower(), columnName.name_hash_lower());
|
||||
addColumn(table, columnName.getSimpleName(), tableName.nameHashCode64(), columnName.nameHashCode64());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -995,7 +994,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
SQLName column = x.getColumnName();
|
||||
String columnName = column.toString();
|
||||
addColumn(tableName, columnName, table.name_hash_lower(), column.name_hash_lower());
|
||||
addColumn(tableName, columnName, table.nameHashCode64(), column.nameHashCode64());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1013,7 +1012,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
SQLName column = x.getNewColumnDefinition().getName();
|
||||
String columnName = column.toString();
|
||||
addColumn(tableName, columnName, table.name_hash_lower(), column.name_hash_lower());
|
||||
addColumn(tableName, columnName, table.nameHashCode64(), column.nameHashCode64());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
+3
-4
@@ -24,7 +24,6 @@ import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSourceImpl;
|
||||
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
|
||||
public class OdpsLateralViewTableSource extends SQLTableSourceImpl {
|
||||
|
||||
@@ -79,13 +78,13 @@ public class OdpsLateralViewTableSource extends SQLTableSourceImpl {
|
||||
}
|
||||
|
||||
public SQLTableSource findTableSource(long alias_hash) {
|
||||
long hash = this.alias_hash();
|
||||
long hash = this.aliasHashCode64();
|
||||
if (hash != 0 && hash == alias_hash) {
|
||||
return this;
|
||||
}
|
||||
|
||||
for (SQLName column : columns) {
|
||||
if (column.name_hash_lower() == alias_hash) {
|
||||
if (column.nameHashCode64() == alias_hash) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -99,7 +98,7 @@ public class OdpsLateralViewTableSource extends SQLTableSourceImpl {
|
||||
|
||||
public SQLTableSource findTableSourceWithColumn(long columnNameHash) {
|
||||
for (SQLName column : columns) {
|
||||
if (column.name_hash_lower() == columnNameHash) {
|
||||
if (column.nameHashCode64() == columnNameHash) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem;
|
||||
import com.alibaba.druid.sql.parser.*;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -46,10 +46,10 @@ public class OdpsExprParser extends SQLExprParser {
|
||||
"ROW_NUMBER",
|
||||
"WM_CONCAT"//
|
||||
};
|
||||
AGGREGATE_FUNCTIONS_CODES = FNVUtils.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FNVUtils.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
|
||||
@@ -20,14 +20,16 @@ import com.alibaba.druid.sql.ast.SQLExprImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
public class OracleDbLinkExpr extends SQLExprImpl implements SQLName, OracleExpr {
|
||||
|
||||
private SQLExpr expr;
|
||||
private String dbLink;
|
||||
|
||||
protected transient long dbLink_hash;
|
||||
private long dbLinkHashCode64;
|
||||
private long hashCode64;
|
||||
|
||||
|
||||
public OracleDbLinkExpr(){
|
||||
|
||||
@@ -121,34 +123,35 @@ public class OracleDbLinkExpr extends SQLExprImpl implements SQLName, OracleExpr
|
||||
return x;
|
||||
}
|
||||
|
||||
public long name_hash_lower() {
|
||||
if (dbLink_hash == 0
|
||||
public long nameHashCode64() {
|
||||
if (dbLinkHashCode64 == 0
|
||||
&& dbLink != null) {
|
||||
final int len = dbLink.length();
|
||||
|
||||
boolean quote = false;
|
||||
|
||||
String name = this.dbLink;
|
||||
if (len > 2) {
|
||||
char c0 = name.charAt(0);
|
||||
char c1 = name.charAt(len - 1);
|
||||
if (c0 == c1
|
||||
&& (c0 == '`' || c1 == '"')) {
|
||||
quote = true;
|
||||
}
|
||||
}
|
||||
if (quote) {
|
||||
dbLink_hash = FNVUtils.fnv_64_lower(name, 1, len -1);
|
||||
} else {
|
||||
dbLink_hash = FNVUtils.fnv_64_lower(name);
|
||||
}
|
||||
dbLinkHashCode64 = FnvHash.hashCode64(dbLink);
|
||||
}
|
||||
return dbLink_hash;
|
||||
return dbLinkHashCode64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long hashCode64() {
|
||||
// TODO hashCode64
|
||||
return 0;
|
||||
if (hashCode64 == 0) {
|
||||
long hash;
|
||||
if (expr instanceof SQLName) {
|
||||
hash = ((SQLName) expr).hashCode64();
|
||||
|
||||
hash ^= '.';
|
||||
hash *= FnvHash.PRIME;
|
||||
} else if (expr == null){
|
||||
hash = FnvHash.BASIC;
|
||||
} else {
|
||||
hash = FnvHash.fnv_64_lower(expr.toString());
|
||||
|
||||
hash ^= '.';
|
||||
hash *= FnvHash.PRIME;
|
||||
}
|
||||
hash = FnvHash.hashCode64(hash, dbLink);
|
||||
hashCode64 = hash;
|
||||
}
|
||||
|
||||
return hashCode64;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.alibaba.druid.sql.dialect.oracle.parser;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Savepoint;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
@@ -29,7 +28,6 @@ import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumericLiteralExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLSequenceExpr;
|
||||
@@ -53,7 +51,8 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OraclePrimaryKey;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleUnique;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleUsingIndexClause;
|
||||
import com.alibaba.druid.sql.parser.*;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
import com.alibaba.druid.util.FnvConstants;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class OracleExprParser extends SQLExprParser {
|
||||
@@ -112,10 +111,10 @@ public class OracleExprParser extends SQLExprParser {
|
||||
"VARIANCE", //
|
||||
"WM_CONCAT"
|
||||
};
|
||||
AGGREGATE_FUNCTIONS_CODES = FNVUtils.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FNVUtils.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
@@ -140,15 +139,14 @@ public class OracleExprParser extends SQLExprParser {
|
||||
this.dbType = JdbcConstants.ORACLE;
|
||||
}
|
||||
|
||||
protected boolean isCharType(String dataTypeName) {
|
||||
return "varchar2".equalsIgnoreCase(dataTypeName) //
|
||||
|| "nvarchar2".equalsIgnoreCase(dataTypeName) //
|
||||
|| "char".equalsIgnoreCase(dataTypeName) //
|
||||
|| "varchar".equalsIgnoreCase(dataTypeName) //
|
||||
|| "nchar".equalsIgnoreCase(dataTypeName) //
|
||||
|| "nvarchar".equalsIgnoreCase(dataTypeName) //
|
||||
//
|
||||
;
|
||||
protected boolean isCharType(long hash) {
|
||||
return hash == FnvConstants.CHAR
|
||||
|| hash == FnvConstants.NCHAR
|
||||
|| hash == FnvConstants.VARCHAR
|
||||
|| hash == FnvConstants.VARCHAR2
|
||||
|| hash == FnvConstants.NVARCHAR
|
||||
|| hash == FnvConstants.NVARCHAR2
|
||||
;
|
||||
}
|
||||
|
||||
public SQLDataType parseDataType(boolean restrict) {
|
||||
@@ -203,10 +201,10 @@ public class OracleExprParser extends SQLExprParser {
|
||||
if (lexer.token() == Token.EXCEPTION) {
|
||||
typeName = "EXCEPTION";
|
||||
lexer.nextToken();
|
||||
} else if (lexer.identifierEquals("LONG")) {
|
||||
} else if (lexer.identifierEquals(FnvConstants.LONG)) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.identifierEquals("RAW")) {
|
||||
if (lexer.identifierEquals(FnvConstants.RAW)) {
|
||||
lexer.nextToken();
|
||||
typeName = "LONG RAW";
|
||||
} else {
|
||||
|
||||
+3
-2
@@ -27,6 +27,7 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectQueryBlock;
|
||||
import com.alibaba.druid.util.FnvConstants;
|
||||
|
||||
public class OracleToMySqlOutputVisitor extends OracleOutputVisitor {
|
||||
|
||||
@@ -151,8 +152,8 @@ public class OracleToMySqlOutputVisitor extends OracleOutputVisitor {
|
||||
|
||||
static boolean isRowNumber(SQLExpr expr) {
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
String lownerName = ((SQLIdentifierExpr) expr).getLowerName();
|
||||
return "rownum".equals(lownerName);
|
||||
return ((SQLIdentifierExpr) expr)
|
||||
.hashCode64() == FnvConstants.ROWNUM;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -41,7 +41,7 @@ import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -54,10 +54,10 @@ public class PGExprParser extends SQLExprParser {
|
||||
|
||||
static {
|
||||
String[] strings = { "AVG", "COUNT", "MAX", "MIN", "STDDEV", "SUM", "ROW_NUMBER" };
|
||||
AGGREGATE_FUNCTIONS_CODES = FNVUtils.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FNVUtils.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
|
||||
+22
-29
@@ -21,7 +21,7 @@ import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
public class SQLServerObjectReferenceExpr extends SQLServerObjectImpl implements SQLServerExpr, SQLName {
|
||||
|
||||
@@ -29,7 +29,8 @@ public class SQLServerObjectReferenceExpr extends SQLServerObjectImpl implements
|
||||
private String database;
|
||||
private String schema;
|
||||
|
||||
protected long schema_hash;
|
||||
protected long schemaHashCode64;
|
||||
protected long hashCode64;
|
||||
|
||||
public SQLServerObjectReferenceExpr(){
|
||||
|
||||
@@ -116,41 +117,33 @@ public class SQLServerObjectReferenceExpr extends SQLServerObjectImpl implements
|
||||
|
||||
public SQLServerObjectReferenceExpr clone() {
|
||||
SQLServerObjectReferenceExpr x = new SQLServerObjectReferenceExpr();
|
||||
x.server = server;
|
||||
x.database = database;
|
||||
x.schema = schema;
|
||||
|
||||
x.server = server;
|
||||
x.database = database;
|
||||
x.schema = schema;
|
||||
|
||||
x.schemaHashCode64 = schemaHashCode64;
|
||||
x.hashCode64 = hashCode64;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public long name_hash_lower() {
|
||||
if (schema_hash == 0
|
||||
public long nameHashCode64() {
|
||||
if (schemaHashCode64 == 0
|
||||
&& schema != null) {
|
||||
final int len = schema.length();
|
||||
|
||||
boolean quote = false;
|
||||
|
||||
String name = this.schema;
|
||||
if (len > 2) {
|
||||
char c0 = name.charAt(0);
|
||||
char c1 = name.charAt(len - 1);
|
||||
if ((c0 == '`' && c1 == '`')
|
||||
|| (c0 == '"' && c1 == '"')
|
||||
|| (c0 == '[' && c1 == ']')) {
|
||||
quote = true;
|
||||
}
|
||||
}
|
||||
if (quote) {
|
||||
schema_hash = FNVUtils.fnv_64_lower(name, 1, len -1);
|
||||
} else {
|
||||
schema_hash = FNVUtils.fnv_64_lower(name);
|
||||
}
|
||||
schemaHashCode64 = FnvHash.hashCode64(schema);
|
||||
}
|
||||
return schema_hash;
|
||||
return schemaHashCode64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long hashCode64() {
|
||||
// TODO hashCode64
|
||||
return 0;
|
||||
if (hashCode64 == 0) {
|
||||
hashCode64 = new SQLPropertyExpr(
|
||||
new SQLPropertyExpr(server, database)
|
||||
, schema)
|
||||
.hashCode64();
|
||||
}
|
||||
return hashCode64;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -34,7 +34,7 @@ import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class SQLServerExprParser extends SQLExprParser {
|
||||
@@ -44,10 +44,10 @@ public class SQLServerExprParser extends SQLExprParser {
|
||||
|
||||
static {
|
||||
String[] strings = { "AVG", "COUNT", "MAX", "MIN", "ROW_NUMBER", "STDDEV", "SUM" };
|
||||
AGGREGATE_FUNCTIONS_CODES = FNVUtils.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FNVUtils.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user