improved sql parser.

This commit is contained in:
wenshao
2017-08-29 21:15:09 +08:00
parent 718500cf59
commit fd20785f6b
48 changed files with 894 additions and 847 deletions
@@ -21,6 +21,8 @@ public interface SQLDataType extends SQLObject {
String getName();
long nameHashCode64();
void setName(String name);
List<SQLExpr> getArguments();
@@ -17,24 +17,24 @@ package com.alibaba.druid.sql.ast;
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.FnvHash;
import java.util.ArrayList;
import java.util.List;
public class SQLDataTypeImpl extends SQLObjectImpl implements SQLDataType {
protected String name;
private String name;
private long nameHashCode64;
protected final List<SQLExpr> arguments = new ArrayList<SQLExpr>();
private Boolean withTimeZone;
private boolean withLocalTimeZone = false;
private Boolean withTimeZone;
private boolean withLocalTimeZone = false;
public SQLDataTypeImpl(){
}
public SQLDataTypeImpl(String name){
this.name = name;
}
@@ -62,8 +62,16 @@ public class SQLDataTypeImpl extends SQLObjectImpl implements SQLDataType {
return this.name;
}
public long nameHashCode64() {
if (nameHashCode64 == 0) {
nameHashCode64 = FnvHash.hashCode64(name);
}
return nameHashCode64;
}
public void setName(String name) {
this.name = name;
nameHashCode64 = 0L;
}
public List<SQLExpr> getArguments() {
@@ -16,11 +16,8 @@
package com.alibaba.druid.sql.ast;
public interface SQLName extends SQLExpr {
String getSimpleName();
String getSimpleName();
SQLName clone();
long name_hash_lower();
long hashCode64();
long nameHashCode64();
long hashCode64();
}
@@ -22,11 +22,16 @@ import java.util.List;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.*;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.FnvConstants;
import com.alibaba.druid.util.FnvHash;
public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLReplaceable {
private static final long serialVersionUID = 1L;
protected String methodName;
protected long methodNameHashCod64;
protected SQLAggregateOption option;
protected final List<SQLExpr> arguments = new ArrayList<SQLExpr>();
protected SQLKeep keep;
@@ -51,6 +56,13 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
this.methodName = methodName;
}
public long methodNameHashCod64() {
if (methodNameHashCod64 == 0) {
methodNameHashCod64 = FnvHash.hashCode64(methodName);
}
return methodNameHashCod64;
}
public SQLOrderBy getWithinGroup() {
return withinGroup;
}
@@ -204,8 +216,10 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
}
public SQLDataType computeDataType() {
if ("count".equals(methodName)
|| "row_number".equals(methodName)) {
long hash = methodNameHashCod64();
if (hash == FnvConstants.COUNT
|| hash == FnvConstants.ROW_NUMBER) {
return SQLIntegerExpr.DEFAULT_DATA_TYPE;
}
@@ -216,8 +230,8 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
}
}
if ("wm_conat".equals(methodName)
|| "group_concat".equals(methodName)) {
if (hash == FnvConstants.WM_CONAT
|| hash == FnvConstants.GROUP_CONCAT) {
return SQLCharExpr.DEFAULT_DATA_TYPE;
}
@@ -19,14 +19,12 @@ import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.*;
import com.alibaba.druid.sql.ast.statement.*;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvHash;
public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
protected String name;
private transient String lowerName;
protected transient long hashCode64;
protected String name;
private transient String lowerName;
private transient long hashCode64;
private transient SQLObject resolvedColumn;
private transient SQLObject resolvedOwnerObject;
@@ -65,7 +63,7 @@ public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
return lowerName;
}
public long name_hash_lower() {
public long nameHashCode64() {
return hashCode64();
}
@@ -73,7 +71,7 @@ public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
public long hashCode64() {
if (hashCode64 == 0
&& name != null) {
hashCode64 = FNVUtils.fnv_64_lower_normalized(name);
hashCode64 = FnvHash.hashCode64(name);
}
return hashCode64;
}
@@ -186,7 +184,7 @@ public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
if (queryBlock == null) {
return null;
}
SQLSelectItem selectItem = queryBlock.findSelectItem(name_hash_lower());
SQLSelectItem selectItem = queryBlock.findSelectItem(nameHashCode64());
if (selectItem != null) {
return selectItem.computeDataType();
}
@@ -18,23 +18,19 @@ package com.alibaba.druid.sql.ast.expr;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.*;
import com.alibaba.druid.sql.ast.statement.*;
import com.alibaba.druid.sql.parser.ParserException;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvHash;
public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
private SQLExpr owner;
private String name;
private SQLExpr owner;
private String name;
protected long name_hash_lower;
private transient long nameHashCod64;
private transient long hashCode64;
private transient SQLColumnDefinition resolvedColumn;
private transient SQLObject resolvedTableSource;
private transient long hash_ower;
public SQLPropertyExpr(String owner, String name){
this(new SQLIdentifierExpr(owner), name);
}
@@ -44,10 +40,10 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
this.name = name;
}
public SQLPropertyExpr(SQLExpr owner, String name, long name_hash_lower){
public SQLPropertyExpr(SQLExpr owner, String name, long nameHashCod64){
setOwner(owner);
this.name = name;
this.name_hash_lower = name_hash_lower;
this.nameHashCod64 = nameHashCod64;
}
public SQLPropertyExpr(){
@@ -75,7 +71,7 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
owner.setParent(this);
}
this.owner = owner;
this.hash_ower = 0;
this.hashCode64 = 0;
}
public void setOwner(String owner) {
@@ -88,8 +84,8 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
public void setName(String name) {
this.name = name;
this.hash_ower = 0;
this.name_hash_lower = 0;
this.hashCode64 = 0;
this.nameHashCod64 = 0;
}
public void output(StringBuffer buf) {
@@ -113,10 +109,26 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
}
public long hashCode64() {
if (hash_ower == 0) {
hash_ower = FNVUtils.fnv_64_lower(this);
if (hashCode64 == 0) {
long hash;
if (owner instanceof SQLName) {
hash = ((SQLName) owner).hashCode64();
hash ^= '.';
hash *= FnvHash.PRIME;
} else if (owner == null){
hash = FnvHash.BASIC;
} else {
hash = FnvHash.fnv_64_lower(owner.toString());
hash ^= '.';
hash *= FnvHash.PRIME;
}
hash = FnvHash.hashCode64(hash, name);
hashCode64 = hash;
}
return hash_ower;
return hashCode64;
}
@Override
@@ -149,12 +161,14 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
}
public SQLPropertyExpr clone() {
SQLPropertyExpr x = new SQLPropertyExpr();
x.name = this.name;
SQLExpr owner_x = null;
if (owner != null) {
x.setOwner(owner.clone());
owner_x = owner.clone();
}
SQLPropertyExpr x = new SQLPropertyExpr(owner_x, name, nameHashCod64);
x.hashCode64 = hashCode64;
x.resolvedColumn = resolvedColumn;
x.resolvedTableSource = resolvedTableSource;
@@ -169,31 +183,12 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
return false;
}
public long name_hash_lower() {
if (name_hash_lower == 0
public long nameHashCode64() {
if (nameHashCod64 == 0
&& name != null) {
final int len = name.length();
boolean quote = false;
String name = this.name;
if (len > 2) {
char c0 = name.charAt(0);
char c1 = name.charAt(len - 1);
if ((c0 == '`' && c1 == '`')
|| (c0 == '"' && c1 == '"')
|| (c0 == '\'' && c1 == '\'')
|| (c0 == '[' && c1 == ']')) {
quote = true;
}
}
if (quote) {
name_hash_lower = FNVUtils.fnv_64_lower(name, 1, len -1);
} else {
name_hash_lower = FNVUtils.fnv_64_lower(name);
}
nameHashCod64 = FnvHash.hashCode64(name);
}
return name_hash_lower;
return nameHashCod64;
}
public String normalizedName() {
@@ -258,7 +253,7 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
if (queryBlock == null) {
return null;
}
SQLSelectItem selectItem = queryBlock.findSelectItem(name_hash_lower());
SQLSelectItem selectItem = queryBlock.findSelectItem(nameHashCode64());
if (selectItem != null) {
return selectItem.computeDataType();
}
@@ -117,7 +117,7 @@ public class SQLBlockStatement extends SQLStatementImpl {
public SQLParameter findParameter(long hash) {
for (SQLParameter param : this.parameters) {
if (param.getName().name_hash_lower() == hash) {
if (param.getName().nameHashCode64() == hash) {
return param;
}
}
@@ -107,7 +107,7 @@ public class SQLCharacterDataType extends SQLDataTypeImpl {
public SQLCharacterDataType clone() {
SQLCharacterDataType x = new SQLCharacterDataType(name);
SQLCharacterDataType x = new SQLCharacterDataType(getName());
super.cloneTo(x);
@@ -169,7 +169,7 @@ public class SQLCreateProcedureStatement extends SQLStatementImpl implements SQL
public SQLParameter findParameter(long hash) {
for (SQLParameter param : this.parameters) {
if (param.getName().name_hash_lower() == hash) {
if (param.getName().nameHashCode64() == hash) {
return param;
}
}
@@ -15,7 +15,6 @@
*/
package com.alibaba.druid.sql.ast.statement;
import java.io.IOException;
import java.util.*;
import com.alibaba.druid.sql.SQLUtils;
@@ -24,14 +23,12 @@ import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvHash;
import com.alibaba.druid.util.ListDG;
import com.alibaba.druid.util.lang.Consumer;
import oracle.sql.SQLUtil;
public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLStatement, SQLCreateStatement {
@@ -239,7 +236,7 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
return null;
}
long hash = FNVUtils.fnv_64_lower_normalized(columName);
long hash = FnvHash.hashCode64(columName);
return findColumn(hash);
}
@@ -248,7 +245,7 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
if (element instanceof SQLColumnDefinition) {
SQLColumnDefinition column = (SQLColumnDefinition) element;
SQLName columnName = column.getName();
if (columnName != null && columnName.name_hash_lower() == columName_hash) {
if (columnName != null && columnName.nameHashCode64() == columName_hash) {
return column;
}
}
@@ -23,11 +23,10 @@ import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
import com.alibaba.druid.sql.repository.SchemaObject;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvHash;
public class SQLExprTableSource extends SQLTableSourceImpl {
@@ -218,13 +217,13 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
}
public boolean containsAlias(long aliasHash) {
if (this.alias_hash() == aliasHash) {
if (this.aliasHashCode64() == aliasHash) {
return true;
}
if (expr instanceof SQLName) {
long exprNameHash = ((SQLName) expr).name_hash_lower();
return exprNameHash == alias_hash;
long exprNameHash = ((SQLName) expr).nameHashCode64();
return exprNameHash == aliasHashCod64;
}
return false;
@@ -235,7 +234,7 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
return null;
}
long hash = FNVUtils.fnv_64_lower_normalized(columnName);
long hash = FnvHash.hashCode64(columnName);
return findColumn(hash);
}
@@ -257,7 +256,7 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
return null;
}
long hash = FNVUtils.fnv_64_lower_normalized(columnName);
long hash = FnvHash.hashCode64(columnName);
return findTableSourceWithColumn(hash);
}
@@ -287,12 +286,12 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
return null;
}
if (alias_hash() == alias_hash) {
if (aliasHashCode64() == alias_hash) {
return this;
}
if (expr instanceof SQLName) {
long exprNameHash = ((SQLName) expr).name_hash_lower();
long exprNameHash = ((SQLName) expr).nameHashCode64();
if (exprNameHash == alias_hash) {
return this;
}
@@ -20,15 +20,12 @@ import java.util.List;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.ast.SQLReplaceable;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvHash;
public class SQLJoinTableSource extends SQLTableSourceImpl implements SQLReplaceable {
@@ -417,7 +414,7 @@ public class SQLJoinTableSource extends SQLTableSourceImpl implements SQLReplace
}
public SQLColumnDefinition findColumn(String columnName) {
long hash = FNVUtils.fnv_64_lower_normalized(columnName);
long hash = FnvHash.hashCode64(columnName);
return findColumn(hash);
}
@@ -438,7 +435,7 @@ public class SQLJoinTableSource extends SQLTableSourceImpl implements SQLReplace
@Override
public SQLTableSource findTableSourceWithColumn(String columnName) {
long hash = FNVUtils.fnv_64_lower_normalized(columnName);
long hash = FnvHash.hashCode64(columnName);
return findTableSourceWithColumn(hash);
}
@@ -533,7 +530,7 @@ public class SQLJoinTableSource extends SQLTableSourceImpl implements SQLReplace
return null;
}
if (alias_hash() == alias_hash) {
if (aliasHashCode64() == alias_hash) {
return this;
}
@@ -21,7 +21,7 @@ import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvHash;
public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
@@ -30,7 +30,7 @@ public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
protected boolean connectByRoot = false;
protected transient long alias_hash;
protected transient long aliasHashCode64;
public SQLSelectItem(){
@@ -174,15 +174,15 @@ public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
return false;
}
long hash = FNVUtils.fnv_64_lower_normalized(alias);
long hash = FnvHash.hashCode64(alias);
return match(hash);
}
public long alias_hash() {
if (this.alias_hash == 0) {
this.alias_hash = FNVUtils.fnv_64_lower_normalized(alias);
if (this.aliasHashCode64 == 0) {
this.aliasHashCode64 = FnvHash.hashCode64(alias);
}
return alias_hash;
return aliasHashCode64;
}
public boolean match(long alias_hash) {
@@ -202,7 +202,7 @@ public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
}
if (expr instanceof SQLIdentifierExpr) {
return ((SQLIdentifierExpr) expr).name_hash_lower() == alias_hash;
return ((SQLIdentifierExpr) expr).nameHashCode64() == alias_hash;
}
if (expr instanceof SQLPropertyExpr) {
@@ -216,7 +216,7 @@ public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
return false;
}
return ((SQLPropertyExpr) expr).name_hash_lower() == alias_hash;
return ((SQLPropertyExpr) expr).nameHashCode64() == alias_hash;
}
return false;
@@ -21,9 +21,8 @@ import java.util.List;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.*;
import com.alibaba.druid.sql.ast.expr.*;
import com.alibaba.druid.sql.repository.SchemaObject;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvHash;
public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery, SQLReplaceable {
private boolean bracket = false;
@@ -487,7 +486,7 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
return null;
}
long hash = FNVUtils.fnv_64_lower_normalized(ident);
long hash = FnvHash.hashCode64(ident);
return findSelectItem(hash);
}
@@ -528,7 +527,7 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
return null;
}
long hash = FNVUtils.fnv_64_lower_normalized(columnName);
long hash = FnvHash.hashCode64(columnName);
return from.findColumn(hash);
}
@@ -24,6 +24,7 @@ import com.alibaba.druid.sql.ast.SQLObject;
public interface SQLTableSource extends SQLObject {
String getAlias();
long aliasHashCode64();
void setAlias(String alias);
@@ -22,17 +22,13 @@ import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLHint;
import com.alibaba.druid.sql.ast.SQLObjectImpl;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvHash;
public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTableSource {
protected String alias;
protected List<SQLHint> hints;
protected SQLExpr flashback;
protected long alias_hash;
protected long aliasHashCod64;
public SQLTableSourceImpl(){
@@ -48,7 +44,7 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
public void setAlias(String alias) {
this.alias = alias;
this.alias_hash = 0L;
this.aliasHashCod64 = 0L;
}
public int getHintsSize() {
@@ -97,12 +93,12 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
return false;
}
public long alias_hash() {
if (alias_hash == 0
public long aliasHashCode64() {
if (aliasHashCod64 == 0
&& alias != null) {
alias_hash = FNVUtils.fnv_64_lower_normalized(alias);
aliasHashCod64 = FnvHash.hashCode64(alias);
}
return alias_hash;
return aliasHashCod64;
}
public SQLColumnDefinition findColumn(String columnName) {
@@ -110,7 +106,7 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
return null;
}
long hash = FNVUtils.fnv_64_lower_normalized(alias);
long hash = FnvHash.hashCode64(alias);
return findColumn(hash);
}
@@ -123,7 +119,7 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
return null;
}
long hash = FNVUtils.fnv_64_lower_normalized(alias);
long hash = FnvHash.hashCode64(alias);
return findTableSourceWithColumn(hash);
}
@@ -132,12 +128,12 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
}
public SQLTableSource findTableSource(String alias) {
long hash = FNVUtils.fnv_64_lower_normalized(alias);
long hash = FnvHash.hashCode64(alias);
return findTableSource(hash);
}
public SQLTableSource findTableSource(long alias_hash) {
long hash = this.alias_hash();
long hash = this.aliasHashCode64();
if (hash != 0 && hash == alias_hash) {
return this;
}
@@ -21,7 +21,6 @@ import java.util.List;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLObjectImpl;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLWithSubqueryClause extends SQLObjectImpl {
@@ -129,7 +128,7 @@ public class SQLWithSubqueryClause extends SQLObjectImpl {
public SQLTableSource findTableSourceWithColumn(long columnNameHash) {
for (SQLName column : columns) {
if (column.name_hash_lower() == columnNameHash) {
if (column.nameHashCode64() == columnNameHash) {
return this;
}
}
@@ -143,7 +142,7 @@ public class SQLWithSubqueryClause extends SQLObjectImpl {
}
for (Entry entry : entries) {
if (entry.alias_hash() == alias_hash) {
if (entry.aliasHashCode64() == alias_hash) {
return entry;
}
}
@@ -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);
@@ -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();
@@ -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;
}
@@ -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 {
@@ -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;
}
@@ -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;
}
}
@@ -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;
}
@@ -40,7 +40,7 @@ import java.util.Arrays;
import java.util.List;
import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvHash;
import com.alibaba.druid.util.JdbcConstants;
import com.alibaba.druid.util.StringUtils;
@@ -1529,7 +1529,7 @@ public class Lexer {
if (stringVal == null) {
stringVal = subString(mark, bufPos);
}
this.hash_lower = FNVUtils.fnv_64_lower(stringVal);
this.hash_lower = FnvHash.fnv_64_lower(stringVal);
}
return this.hash_lower == hash_lower;
}
@@ -1539,7 +1539,7 @@ public class Lexer {
if (stringVal == null) {
stringVal = subString(mark, bufPos);
}
this.hash_lower = FNVUtils.fnv_64_lower(stringVal);
this.hash_lower = FnvHash.fnv_64_lower(stringVal);
}
return hash_lower;
}
@@ -44,7 +44,8 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem;
import com.alibaba.druid.sql.ast.statement.SQLUnique;
import com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem;
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 SQLExprParser extends SQLParser {
@@ -55,10 +56,10 @@ public class SQLExprParser extends SQLParser {
static {
String[] strings = { "AVG", "COUNT", "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;
}
@@ -236,7 +237,7 @@ public class SQLExprParser extends SQLParser {
SQLExpr rightExp = bitXor();
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.DIV, rightExp, getDbType());
expr = multiplicativeRest(expr);
} else if (lexer.identifierEquals(FNVUtils.MOD)) {
} else if (lexer.identifierEquals(FnvConstants.MOD)) {
lexer.nextToken();
SQLExpr rightExp = primary();
@@ -786,8 +787,8 @@ public class SQLExprParser extends SQLParser {
Token token = lexer.token;
if (token == Token.OF) {
if (expr instanceof SQLIdentifierExpr) {
String name = ((SQLIdentifierExpr) expr).getName();
if ("CURRENT".equalsIgnoreCase(name)) {
long hashCode64 = ((SQLIdentifierExpr) expr).hashCode64();
if (hashCode64 == FnvConstants.CURRENT) {
lexer.nextToken();
SQLName cursorName = this.name();
return new SQLCurrentOfCursorExpr(cursorName);
@@ -796,18 +797,17 @@ public class SQLExprParser extends SQLParser {
} else if (token == Token.FOR) {
if (expr instanceof SQLIdentifierExpr) {
SQLIdentifierExpr idenExpr = (SQLIdentifierExpr) expr;
String name = idenExpr.getName();
if ("NEXTVAL".equalsIgnoreCase(name)) {
if (idenExpr.hashCode64() == FnvConstants.NEXTVAL) {
lexer.nextToken();
SQLName seqName = this.name();
SQLSequenceExpr seqExpr = new SQLSequenceExpr(seqName, SQLSequenceExpr.Function.NextVal);
return seqExpr;
} else if ("CURRVAL".equalsIgnoreCase(name)) {
} else if (idenExpr.hashCode64() == FnvConstants.CURRVAL) {
lexer.nextToken();
SQLName seqName = this.name();
SQLSequenceExpr seqExpr = new SQLSequenceExpr(seqName, SQLSequenceExpr.Function.CurrVal);
return seqExpr;
} else if ("PREVVAL".equalsIgnoreCase(name)) {
} else if (idenExpr.hashCode64() == FnvConstants.PREVVAL) {
lexer.nextToken();
SQLName seqName = this.name();
SQLSequenceExpr seqExpr = new SQLSequenceExpr(seqName, SQLSequenceExpr.Function.PrevVal);
@@ -826,7 +826,7 @@ public class SQLExprParser extends SQLParser {
expr = dotRest(expr);
return primaryRest(expr);
} else if (lexer.identifierEquals(FNVUtils.SETS) //
} else if (lexer.identifierEquals(FnvConstants.SETS) //
&& expr.getClass() == SQLIdentifierExpr.class //
&& "GROUPING".equalsIgnoreCase(((SQLIdentifierExpr) expr).getName())) {
SQLGroupingSetExpr groupingSets = new SQLGroupingSetExpr();
@@ -906,26 +906,26 @@ public class SQLExprParser extends SQLParser {
if (expr instanceof SQLIdentifierExpr) {
SQLIdentifierExpr identifierExpr = (SQLIdentifierExpr) expr;
methodName = identifierExpr.getName();
hash_lower = identifierExpr.name_hash_lower();
hash_lower = identifierExpr.nameHashCode64();
if (hash_lower == FNVUtils.TRIM) {
if (lexer.identifierEquals(FNVUtils.LEADING)) {
if (hash_lower == FnvConstants.TRIM) {
if (lexer.identifierEquals(FnvConstants.LEADING)) {
trimOption = lexer.stringVal();
lexer.nextToken();
} else if (lexer.identifierEquals(FNVUtils.BOTH)) {
} else if (lexer.identifierEquals(FnvConstants.BOTH)) {
trimOption = lexer.stringVal();
lexer.nextToken();
} else if (lexer.identifierEquals(FNVUtils.TRAILING)) {
} else if (lexer.identifierEquals(FnvConstants.TRAILING)) {
trimOption = lexer.stringVal();
lexer.nextToken();
}
} else if (hash_lower == FNVUtils.MATCH
} else if (hash_lower == FnvConstants.MATCH
&& JdbcConstants.MYSQL.equals(dbType)) {
return parseMatch();
} else if (hash_lower == FNVUtils.EXTRACT
} else if (hash_lower == FnvConstants.EXTRACT
&& JdbcConstants.MYSQL.equals(dbType)) {
return parseExtract();
} else if (hash_lower == FNVUtils.POSITION
} else if (hash_lower == FnvConstants.POSITION
&& JdbcConstants.MYSQL.equals(dbType)) {
return parsePosition();
}
@@ -933,7 +933,7 @@ public class SQLExprParser extends SQLParser {
} else if (expr instanceof SQLPropertyExpr) {
methodName = expr.toString();
aggMethodName = SQLUtils.normalize(methodName);
hash_lower = FNVUtils.fnv_64_lower(aggMethodName);
hash_lower = FnvHash.fnv_64_lower(aggMethodName);
aggMethodName = getAggreateFunction(hash_lower);
owner = ((SQLPropertyExpr) expr).getOwner();
@@ -978,7 +978,7 @@ public class SQLExprParser extends SQLParser {
}
}
if (lexer.token == Token.USING || lexer.identifierEquals(FNVUtils.USING)) {
if (lexer.token == Token.USING || lexer.identifierEquals(FnvConstants.USING)) {
lexer.nextToken();
SQLExpr using = this.primary();
methodInvokeExpr.setUsing(using);
@@ -1229,7 +1229,7 @@ public class SQLExprParser extends SQLParser {
}
public boolean isAggreateFunction(String word) {
long hash_lower = FNVUtils.fnv_64_lower(word);
long hash_lower = FnvHash.fnv_64_lower(word);
return isAggreateFunction(hash_lower);
}
@@ -1253,7 +1253,7 @@ public class SQLExprParser extends SQLParser {
} else if (lexer.token == Token.DISTINCT) {
aggregateExpr = new SQLAggregateExpr(methodName, SQLAggregateOption.DISTINCT);
lexer.nextToken();
} else if (lexer.identifierEquals(FNVUtils.DEDUPLICATION)) { // just for nut
} else if (lexer.identifierEquals(FnvConstants.DEDUPLICATION)) { // just for nut
aggregateExpr = new SQLAggregateExpr(methodName, SQLAggregateOption.DEDUPLICATION);
lexer.nextToken();
} else {
@@ -1301,9 +1301,10 @@ public class SQLExprParser extends SQLParser {
}
SQLOver.WindowingType windowingType = null;
if (lexer.identifierEquals("ROWS")) {
if (lexer.identifierEquals(FnvConstants.ROWS)) {
windowingType = SQLOver.WindowingType.ROWS;
} else if (lexer.identifierEquals("RANGE")) {
} else if (lexer.identifierEquals(FnvConstants.RANGE)) {
windowingType = SQLOver.WindowingType.RANGE;
}
@@ -1316,10 +1317,10 @@ public class SQLExprParser extends SQLParser {
SQLIntegerExpr rowsBegin = (SQLIntegerExpr) this.primary();
over.setWindowingBetweenBegin(rowsBegin);
if (lexer.identifierEquals("PRECEDING")) {
if (lexer.identifierEquals(FnvConstants.PRECEDING)) {
over.setWindowingBetweenBeginPreceding(true);
lexer.nextToken();
} else if (lexer.identifierEquals("FOLLOWING")) {
} else if (lexer.identifierEquals(FnvConstants.FOLLOWING)) {
over.setWindowingBetweenBeginFollowing(true);
lexer.nextToken();
}
@@ -1329,25 +1330,25 @@ public class SQLExprParser extends SQLParser {
SQLIntegerExpr betweenEnd = (SQLIntegerExpr) this.primary();
over.setWindowingBetweenEnd(betweenEnd);
if (lexer.identifierEquals("PRECEDING")) {
if (lexer.identifierEquals(FnvConstants.PRECEDING)) {
over.setWindowingBetweenEndPreceding(true);
lexer.nextToken();
} else if (lexer.identifierEquals("FOLLOWING")) {
} else if (lexer.identifierEquals(FnvConstants.FOLLOWING)) {
over.setWindowingBetweenEndFollowing(true);
lexer.nextToken();
}
} else {
if (lexer.identifierEquals("CURRENT")) {
if (lexer.identifierEquals(FnvConstants.CURRENT)) {
lexer.nextToken();
acceptIdentifier("ROW");
over.setWindowing(new SQLIdentifierExpr("CURRENT ROW"));
} else if (lexer.identifierEquals("UNBOUNDED")) {
} else if (lexer.identifierEquals(FnvConstants.UNBOUNDED)) {
lexer.nextToken();
over.setWindowing(new SQLIdentifierExpr("UNBOUNDED"));
if (lexer.identifierEquals("PRECEDING")) {
if (lexer.identifierEquals(FnvConstants.PRECEDING)) {
over.setWindowingPreceding(true);
lexer.nextToken();
} else if (lexer.identifierEquals("FOLLOWING")) {
@@ -1358,10 +1359,10 @@ public class SQLExprParser extends SQLParser {
SQLIntegerExpr rowsExpr = (SQLIntegerExpr) this.primary();
over.setWindowing(rowsExpr);
if (lexer.identifierEquals("PRECEDING")) {
if (lexer.identifierEquals(FnvConstants.PRECEDING)) {
over.setWindowingPreceding(true);
lexer.nextToken();
} else if (lexer.identifierEquals("FOLLOWING")) {
} else if (lexer.identifierEquals(FnvConstants.FOLLOWING)) {
over.setWindowingFollowing(true);
lexer.nextToken();
}
@@ -1383,7 +1384,7 @@ public class SQLExprParser extends SQLParser {
lexer.nextToken();
if (lexer.identifierEquals("SIBLINGS")) {
if (lexer.identifierEquals(FnvConstants.SIBLINGS)) {
lexer.nextToken();
orderBy.setSibings(true);
}
@@ -1423,12 +1424,12 @@ public class SQLExprParser extends SQLParser {
item.setType(SQLOrderingSpecification.DESC);
}
if (lexer.identifierEquals("NULLS")) {
if (lexer.identifierEquals(FnvConstants.NULLS)) {
lexer.nextToken();
if (lexer.identifierEquals("FIRST")) {
if (lexer.identifierEquals(FnvConstants.FIRST)) {
lexer.nextToken();
item.setNullsOrderType(SQLSelectOrderByItem.NullsOrderType.NullsFirst);
} else if (lexer.identifierEquals("LAST")) {
} else if (lexer.identifierEquals(FnvConstants.LAST)) {
lexer.nextToken();
item.setNullsOrderType(SQLSelectOrderByItem.NullsOrderType.NullsLast);
} else {
@@ -1842,7 +1843,7 @@ public class SQLExprParser extends SQLParser {
rightExp = primary();
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Escape, rightExp, getDbType());
}
} else if (lexer.identifierEquals(FNVUtils.RLIKE)) {
} else if (lexer.identifierEquals(FnvConstants.RLIKE)) {
lexer.nextToken();
rightExp = equality();
@@ -1900,7 +1901,7 @@ public class SQLExprParser extends SQLParser {
expr = new SQLBinaryOpExpr(expr, op, rightExp, dbType);
} else if (token == Token.IN) {
expr = inRest(expr);
} else if (lexer.identifierEquals(FNVUtils.REGEXP)) {
} else if (lexer.identifierEquals(FnvConstants.REGEXP)) {
lexer.nextToken();
rightExp = equality();
@@ -1909,7 +1910,7 @@ public class SQLExprParser extends SQLParser {
return new SQLBinaryOpExpr(expr, SQLBinaryOperator.RegExp, rightExp, JdbcConstants.MYSQL);
} else if (JdbcConstants.POSTGRESQL.equals(lexer.dbType)) {
if (lexer.identifierEquals("SIMILAR")) {
if (lexer.identifierEquals(FnvConstants.SIMILAR)) {
lexer.nextToken();
accept(Token.TO);
@@ -2010,7 +2011,7 @@ public class SQLExprParser extends SQLParser {
expr = new SQLBetweenExpr(expr, true, beginExpr, endExpr);
return expr;
} else if (lexer.identifierEquals("RLIKE")) {
} else if (lexer.identifierEquals(FnvConstants.RLIKE)) {
lexer.nextToken();
SQLExpr rightExp = primary();
@@ -2024,7 +2025,7 @@ public class SQLExprParser extends SQLParser {
rightExp = relationalRest(rightExp);
return new SQLBinaryOpExpr(expr, SQLBinaryOperator.NotILike, rightExp, getDbType());
} else if (lexer.identifierEquals(FNVUtils.REGEXP)) {
} else if (lexer.identifierEquals(FnvConstants.REGEXP)) {
lexer.nextToken();
SQLExpr rightExp = primary();
@@ -2102,13 +2103,14 @@ public class SQLExprParser extends SQLParser {
accept(Token.RPAREN);
}
if (lexer.identifierEquals("PRECISION") && dataType.getName().equalsIgnoreCase("DOUBLE")) {
if (lexer.identifierEquals(FnvConstants.PRECISION)
&& dataType.nameHashCode64() == FnvConstants.DOUBLE) {
lexer.nextToken();
dataType.setName("DOUBLE PRECISION");
}
if ("timestamp".equalsIgnoreCase(dataType.getName())) {
if (lexer.identifierEquals("WITHOUT")) {
if (FnvConstants.TIMESTAMP == dataType.nameHashCode64()) {
if (lexer.identifierEquals(FnvConstants.WITHOUT)) {
lexer.nextToken();
acceptIdentifier("TIME");
acceptIdentifier("ZONE");
@@ -2125,13 +2127,21 @@ public class SQLExprParser extends SQLParser {
}
protected boolean isCharType(String dataTypeName) {
return "char".equalsIgnoreCase(dataTypeName) //
|| "varchar".equalsIgnoreCase(dataTypeName) || "nchar".equalsIgnoreCase(dataTypeName)
|| "nvarchar".equalsIgnoreCase(dataTypeName) || "tinytext".equalsIgnoreCase(dataTypeName)
|| "text".equalsIgnoreCase(dataTypeName) || "mediumtext".equalsIgnoreCase(dataTypeName)
|| "longtext".equalsIgnoreCase(dataTypeName)
//
;
long hash = FnvHash.hashCode64(dataTypeName);
return isCharType(hash);
}
protected boolean isCharType(long hash) {
return hash == FnvConstants.CHAR
|| hash == FnvConstants.VARCHAR
|| hash == FnvConstants.NCHAR
|| hash == FnvConstants.NVARCHAR
|| hash == FnvConstants.TINYTEXT
|| hash == FnvConstants.TEXT
|| hash == FnvConstants.MEDIUMTEXT
|| hash == FnvConstants.LONGTEXT
;
}
protected SQLDataType parseCharTypeRest(SQLCharacterDataType charType) {
@@ -2140,7 +2150,7 @@ public class SQLExprParser extends SQLParser {
lexer.nextToken();
}
if (lexer.identifierEquals("CHARACTER")) {
if (lexer.identifierEquals(FnvConstants.CHARACTER)) {
lexer.nextToken();
accept(Token.SET);
@@ -2157,17 +2167,16 @@ public class SQLExprParser extends SQLParser {
lexer.nextToken();
}
if (lexer.token == Token.IDENTIFIER) {
if (lexer.stringVal().equalsIgnoreCase("COLLATE")) {
lexer.nextToken();
if (lexer.identifierEquals(FnvConstants.COLLATE)) {
lexer.nextToken();
if (lexer.token != Token.IDENTIFIER) {
throw new ParserException();
}
charType.setCollate(lexer.stringVal());
lexer.nextToken();
if (lexer.token != Token.IDENTIFIER) {
throw new ParserException();
}
charType.setCollate(lexer.stringVal());
lexer.nextToken();
}
return charType;
}
@@ -2339,16 +2348,16 @@ public class SQLExprParser extends SQLParser {
} else if (lexer.token == Token.ENABLE) {
lexer.nextToken();
check.setEnable(true);
} else if (lexer.identifierEquals("VALIDATE")) {
} else if (lexer.identifierEquals(FnvConstants.VALIDATE)) {
lexer.nextToken();
check.setValidate(Boolean.TRUE);
} else if (lexer.identifierEquals("NOVALIDATE")) {
} else if (lexer.identifierEquals(FnvConstants.NOVALIDATE)) {
lexer.nextToken();
check.setValidate(Boolean.FALSE);
} else if (lexer.identifierEquals("RELY")) {
} else if (lexer.identifierEquals(FnvConstants.RELY)) {
lexer.nextToken();
check.setRely(Boolean.TRUE);
} else if (lexer.identifierEquals("NORELY")) {
} else if (lexer.identifierEquals(FnvConstants.NORELY)) {
lexer.nextToken();
check.setRely(Boolean.FALSE);
}
@@ -2381,16 +2390,16 @@ public class SQLExprParser extends SQLParser {
} else if (lexer.token == Token.ENABLE) {
lexer.nextToken();
unique.setEnable(true);
} else if (lexer.identifierEquals("VALIDATE")) {
} else if (lexer.identifierEquals(FnvConstants.VALIDATE)) {
lexer.nextToken();
unique.setValidate(Boolean.TRUE);
} else if (lexer.identifierEquals("NOVALIDATE")) {
} else if (lexer.identifierEquals(FnvConstants.NOVALIDATE)) {
lexer.nextToken();
unique.setValidate(Boolean.FALSE);
} else if (lexer.identifierEquals("RELY")) {
} else if (lexer.identifierEquals(FnvConstants.RELY)) {
lexer.nextToken();
unique.setRely(Boolean.TRUE);
} else if (lexer.identifierEquals("NORELY")) {
} else if (lexer.identifierEquals(FnvConstants.NORELY)) {
lexer.nextToken();
unique.setRely(Boolean.FALSE);
}
@@ -2409,7 +2418,7 @@ public class SQLExprParser extends SQLParser {
item.setTarget(var);
if (lexer.token == Token.COLONEQ) {
lexer.nextToken();
} else if (lexer.token == Token.TRUE || lexer.identifierEquals("TRUE")) {
} else if (lexer.token == Token.TRUE || lexer.identifierEquals(FnvConstants.TRUE)) {
lexer.nextToken();
item.setValue(new SQLBooleanExpr(true));
return item;
@@ -2523,7 +2532,7 @@ public class SQLExprParser extends SQLParser {
if (lexer.token == Token.ON) {
lexer.nextToken();
accept(Token.DELETE);
if (lexer.identifierEquals("CASCADE")) {
if (lexer.identifierEquals(FnvConstants.CASCADE)) {
lexer.nextToken();
fk.setOnDeleteCascade(true);
} else {
@@ -2549,11 +2558,11 @@ public class SQLExprParser extends SQLParser {
long hash_lower = lexer.hash_lower();
lexer.nextTokenComma();
if (hash_lower == FNVUtils.CONNECT_BY_ROOT) {
if (hash_lower == FnvConstants.CONNECT_BY_ROOT) {
connectByRoot = true;
expr = new SQLIdentifierExpr(lexer.stringVal());
lexer.nextToken();
} else if (FNVUtils.DATE == hash_lower
} else if (FnvConstants.DATE == hash_lower
&& lexer.token == Token.LITERAL_CHARS
&& (JdbcConstants.ORACLE.equals(getDbType())
|| JdbcConstants.POSTGRESQL.equals(getDbType()))) {
@@ -2586,7 +2595,7 @@ public class SQLExprParser extends SQLParser {
return new SQLSelectItem(expr, as, connectByRoot);
}
if (token == Token.IDENTIFIER && hash_lower != FNVUtils.CURRENT) {
if (token == Token.IDENTIFIER && hash_lower != FnvConstants.CURRENT) {
String as = lexer.stringVal();
lexer.nextTokenComma();
return new SQLSelectItem(expr, as, connectByRoot);
@@ -2630,7 +2639,7 @@ public class SQLExprParser extends SQLParser {
SQLGroupingSetExpr expr = new SQLGroupingSetExpr();
if (lexer.identifierEquals("SET")) {
if (lexer.token == Token.SET || lexer.identifierEquals(FnvConstants.SET)) {
lexer.nextToken();
} else {
return new SQLIdentifierExpr(tmp);
@@ -2660,13 +2669,13 @@ public class SQLExprParser extends SQLParser {
accept(Token.LPAREN);
this.exprList(values.getItems(), values);
accept(Token.RPAREN);
} else if (lexer.identifierEquals("LESS")) {
} else if (lexer.identifierEquals(FnvConstants.LESS)) {
lexer.nextToken();
acceptIdentifier("THAN");
values = new SQLPartitionValue(SQLPartitionValue.Operator.LessThan);
if (lexer.identifierEquals("MAXVALUE")) {
if (lexer.identifierEquals(FnvConstants.MAXVALUE)) {
SQLIdentifierExpr maxValue = new SQLIdentifierExpr(lexer.stringVal());
lexer.nextToken();
maxValue.setParent(values);
@@ -2705,7 +2714,7 @@ public class SQLExprParser extends SQLParser {
limit.setOffset(temp);
lexer.nextToken();
limit.setRowCount(this.expr());
} else if (lexer.identifierEquals("OFFSET")) {
} else if (lexer.identifierEquals(FnvConstants.OFFSET)) {
limit.setRowCount(temp);
lexer.nextToken();
limit.setOffset(this.expr());
@@ -18,11 +18,9 @@ package com.alibaba.druid.sql.parser;
import java.util.List;
import com.alibaba.druid.sql.ast.*;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.statement.*;
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectQueryBlock;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvConstants;
import com.alibaba.druid.util.JdbcConstants;
public class SQLSelectParser extends SQLParser {
@@ -178,13 +176,13 @@ public class SQLSelectParser extends SQLParser {
}
if (JdbcConstants.INFORMIX.equals(dbType)) {
if (lexer.identifierEquals("SKIP")) {
if (lexer.identifierEquals(FnvConstants.SKIP)) {
lexer.nextToken();
SQLExpr offset = this.exprParser.primary();
queryBlock.setOffset(offset);
}
if (lexer.identifierEquals("FIRST")) {
if (lexer.identifierEquals(FnvConstants.FIRST)) {
lexer.nextToken();
SQLExpr first = this.exprParser.primary();
queryBlock.setFirst(first);
@@ -221,7 +219,7 @@ public class SQLSelectParser extends SQLParser {
SQLWithSubqueryClause withQueryClause = new SQLWithSubqueryClause();
if (lexer.token == Token.RECURSIVE || lexer.identifierEquals("RECURSIVE")) {
if (lexer.token == Token.RECURSIVE || lexer.identifierEquals(FnvConstants.RECURSIVE)) {
lexer.nextToken();
withQueryClause.setRecursive(true);
}
@@ -264,7 +262,7 @@ public class SQLSelectParser extends SQLParser {
SQLWithSubqueryClause withQueryClause = new SQLWithSubqueryClause();
if (lexer.token == Token.RECURSIVE || lexer.identifierEquals("RECURSIVE")) {
if (lexer.token == Token.RECURSIVE || lexer.identifierEquals(FnvConstants.RECURSIVE)) {
lexer.nextToken();
withQueryClause.setRecursive(true);
}
@@ -339,12 +337,12 @@ public class SQLSelectParser extends SQLParser {
accept(Token.BY);
SQLSelectGroupByClause groupBy = new SQLSelectGroupByClause();
if (lexer.identifierEquals("ROLLUP")) {
if (lexer.identifierEquals(FnvConstants.ROLLUP)) {
lexer.nextToken();
accept(Token.LPAREN);
groupBy.setWithRollUp(true);
}
if (lexer.identifierEquals("CUBE")) {
if (lexer.identifierEquals(FnvConstants.CUBE)) {
lexer.nextToken();
accept(Token.LPAREN);
groupBy.setWithCube(true);
@@ -376,7 +374,7 @@ public class SQLSelectParser extends SQLParser {
if (lexer.token == Token.WITH) {
lexer.nextToken();
if (lexer.identifierEquals("CUBE")) {
if (lexer.identifierEquals(FnvConstants.CUBE)) {
lexer.nextToken();
groupBy.setWithCube(true);
} else {
@@ -526,8 +524,8 @@ public class SQLSelectParser extends SQLParser {
protected SQLTableSource parseTableSourceRest(SQLTableSource tableSource) {
if ((tableSource.getAlias() == null) || (tableSource.getAlias().length() == 0)) {
if (lexer.token != Token.LEFT && lexer.token != Token.RIGHT && lexer.token != Token.FULL
&& (!lexer.identifierEquals(FNVUtils.STRAIGHT_JOIN))
&& (!lexer.identifierEquals(FNVUtils.CROSS))
&& (!lexer.identifierEquals(FnvConstants.STRAIGHT_JOIN))
&& (!lexer.identifierEquals(FnvConstants.CROSS))
&& lexer.token != Token.OUTER) {
String alias = tableAlias();
if (alias != null) {
@@ -539,19 +537,18 @@ public class SQLSelectParser extends SQLParser {
SQLJoinTableSource.JoinType joinType = null;
boolean natural = false;
if (JdbcConstants.MYSQL.equals(dbType) && lexer.identifierEquals(FNVUtils.NATURAL)) {
boolean natural = lexer.identifierEquals(FnvConstants.NATURAL) && JdbcConstants.MYSQL.equals(dbType);
if (natural) {
lexer.nextToken();
natural = true;
}
if (lexer.token == Token.LEFT) {
lexer.nextToken();
if (lexer.identifierEquals(FNVUtils.SEMI)) {
if (lexer.identifierEquals(FnvConstants.SEMI)) {
lexer.nextToken();
joinType = SQLJoinTableSource.JoinType.LEFT_SEMI_JOIN;
} else if (lexer.identifierEquals(FNVUtils.ANTI)) {
} else if (lexer.identifierEquals(FnvConstants.ANTI)) {
lexer.nextToken();
joinType = SQLJoinTableSource.JoinType.LEFT_ANTI_JOIN;
} else if (lexer.token == Token.OUTER) {
@@ -587,21 +584,21 @@ public class SQLSelectParser extends SQLParser {
} else if (lexer.token == Token.COMMA) {
lexer.nextToken();
joinType = SQLJoinTableSource.JoinType.COMMA;
} else if (lexer.identifierEquals(FNVUtils.STRAIGHT_JOIN)) {
} else if (lexer.identifierEquals(FnvConstants.STRAIGHT_JOIN)) {
lexer.nextToken();
joinType = SQLJoinTableSource.JoinType.STRAIGHT_JOIN;
} else if (lexer.identifierEquals(FNVUtils.CROSS)) {
} else if (lexer.identifierEquals(FnvConstants.CROSS)) {
lexer.nextToken();
if (lexer.token == Token.JOIN) {
lexer.nextToken();
joinType = SQLJoinTableSource.JoinType.CROSS_JOIN;
} else if (lexer.identifierEquals(FNVUtils.APPLY)) {
} else if (lexer.identifierEquals(FnvConstants.APPLY)) {
lexer.nextToken();
joinType = SQLJoinTableSource.JoinType.CROSS_APPLY;
}
} else if (lexer.token == Token.OUTER) {
lexer.nextToken();
if (lexer.identifierEquals(FNVUtils.APPLY)) {
if (lexer.identifierEquals(FnvConstants.APPLY)) {
lexer.nextToken();
joinType = SQLJoinTableSource.JoinType.OUTER_APPLY;
}
@@ -625,7 +622,7 @@ public class SQLSelectParser extends SQLParser {
}
if (lexer.token == Token.USING
||lexer.identifierEquals(FNVUtils.USING))
||lexer.identifierEquals(FnvConstants.USING))
{
Lexer.SavePoint savePoint = lexer.mark();
lexer.nextToken();
@@ -667,7 +664,7 @@ public class SQLSelectParser extends SQLParser {
join.setRight(rightTableSource);
if (!natural) {
if (JdbcConstants.MYSQL.equals(dbType) && "NATURAL".equalsIgnoreCase(tableSource.getAlias())) {
if (tableSource.aliasHashCode64() == FnvConstants.NATURAL && JdbcConstants.MYSQL.equals(dbType)) {
tableSource.setAlias(null);
natural = true;
}
@@ -678,7 +675,7 @@ public class SQLSelectParser extends SQLParser {
lexer.nextToken();
join.setCondition(expr());
} else if (lexer.token == Token.USING
|| lexer.identifierEquals(FNVUtils.USING)) {
|| lexer.identifierEquals(FnvConstants.USING)) {
Lexer.SavePoint savePoint = lexer.mark();
lexer.nextToken();
if (lexer.token == Token.LPAREN) {
@@ -720,11 +717,11 @@ public class SQLSelectParser extends SQLParser {
return;
}
if (lexer.identifierEquals("OFFSET") || lexer.token == Token.OFFSET) {
if (lexer.identifierEquals(FnvConstants.OFFSET) || lexer.token == Token.OFFSET) {
lexer.nextToken();
SQLExpr offset = this.exprParser.primary();
queryBlock.setOffset(offset);
if (lexer.identifierEquals("ROW") || lexer.identifierEquals("ROWS")) {
if (lexer.identifierEquals(FnvConstants.ROW) || lexer.identifierEquals(FnvConstants.ROWS)) {
lexer.nextToken();
}
}
@@ -732,14 +729,14 @@ public class SQLSelectParser extends SQLParser {
if (lexer.token == Token.FETCH) {
lexer.nextToken();
if (lexer.token == Token.FIRST
|| lexer.identifierEquals("NEXT")) {
|| lexer.identifierEquals(FnvConstants.NEXT)) {
lexer.nextToken();
} else {
acceptIdentifier("FIRST");
}
SQLExpr first = this.exprParser.primary();
queryBlock.setFirst(first);
if (lexer.identifierEquals("ROW") || lexer.identifierEquals("ROWS")) {
if (lexer.identifierEquals(FnvConstants.ROW) || lexer.identifierEquals(FnvConstants.ROWS)) {
lexer.nextToken();
}
@@ -752,16 +749,16 @@ public class SQLSelectParser extends SQLParser {
}
protected void parseHierachical(SQLSelectQueryBlock queryBlock) {
if (lexer.token == Token.CONNECT || lexer.identifierEquals(FNVUtils.CONNECT)) {
if (lexer.token == Token.CONNECT || lexer.identifierEquals(FnvConstants.CONNECT)) {
lexer.nextToken();
accept(Token.BY);
if (lexer.token == Token.PRIOR || lexer.identifierEquals(FNVUtils.PRIOR)) {
if (lexer.token == Token.PRIOR || lexer.identifierEquals(FnvConstants.PRIOR)) {
lexer.nextToken();
queryBlock.setPrior(true);
}
if (lexer.identifierEquals(FNVUtils.NOCYCLE)) {
if (lexer.identifierEquals(FnvConstants.NOCYCLE)) {
queryBlock.setNoCycle(true);
lexer.nextToken();
@@ -773,27 +770,27 @@ public class SQLSelectParser extends SQLParser {
queryBlock.setConnectBy(this.exprParser.expr());
}
if (lexer.token == Token.START || lexer.identifierEquals(FNVUtils.START)) {
if (lexer.token == Token.START || lexer.identifierEquals(FnvConstants.START)) {
lexer.nextToken();
accept(Token.WITH);
queryBlock.setStartWith(this.exprParser.expr());
}
if (lexer.token == Token.CONNECT || lexer.identifierEquals(FNVUtils.CONNECT)) {
if (lexer.token == Token.CONNECT || lexer.identifierEquals(FnvConstants.CONNECT)) {
lexer.nextToken();
accept(Token.BY);
if (lexer.token == Token.PRIOR || lexer.identifierEquals(FNVUtils.PRIOR)) {
if (lexer.token == Token.PRIOR || lexer.identifierEquals(FnvConstants.PRIOR)) {
lexer.nextToken();
queryBlock.setPrior(true);
}
if (lexer.identifierEquals(FNVUtils.NOCYCLE)) {
if (lexer.identifierEquals(FnvConstants.NOCYCLE)) {
queryBlock.setNoCycle(true);
lexer.nextToken();
if (lexer.token == Token.PRIOR || lexer.identifierEquals(FNVUtils.PRIOR)) {
if (lexer.token == Token.PRIOR || lexer.identifierEquals(FnvConstants.PRIOR)) {
lexer.nextToken();
queryBlock.setPrior(true);
}
@@ -20,7 +20,7 @@ import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
import com.alibaba.druid.sql.ast.statement.SQLUniqueConstraint;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvHash;
/**
* Created by wenshao on 08/06/2017.
@@ -51,7 +51,7 @@ public class SchemaObjectImpl implements SchemaObject {
}
public SQLColumnDefinition findColumn(String columName) {
long hash = FNVUtils.fnv_64_lower_normalized(columName);
long hash = FnvHash.hashCode64(columName);
return findColumn(hash);
}
@@ -16,14 +16,11 @@
package com.alibaba.druid.sql.repository;
import com.alibaba.druid.sql.ast.SQLDeclareItem;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@@ -105,7 +102,7 @@ public interface SchemaResolveVisitor extends SQLASTVisitor {
if (declares == null) {
declares = new HashMap<Long, SQLDeclareItem>();
}
declares.put(x.getName().name_hash_lower(), x);
declares.put(x.getName().nameHashCode64(), x);
}
protected SQLDeclareItem findDeclare(long nameHash) {
@@ -22,7 +22,7 @@ import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerUpdateStatement;
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitorAdapter;
import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter;
import com.alibaba.druid.util.FNVUtils;
import com.alibaba.druid.util.FnvConstants;
import com.alibaba.druid.util.PGUtils;
import java.util.ArrayList;
@@ -815,7 +815,7 @@ class SchemaResolveVisitorFactory {
}
public boolean visit(SQLIdentifierExpr x) {
if (PGUtils.isPseudoColumn(x.name_hash_lower())) {
if (PGUtils.isPseudoColumn(x.nameHashCode64())) {
return false;
}
@@ -1255,7 +1255,7 @@ class SchemaResolveVisitorFactory {
SQLIdentifierExpr identifierExpr = (SQLIdentifierExpr) orderByItemExpr;
identifierExpr.setResolvedTableSource(table);
SQLColumnDefinition column = x.findColumn(identifierExpr.name_hash_lower());
SQLColumnDefinition column = x.findColumn(identifierExpr.nameHashCode64());
if (column != null) {
identifierExpr.setResolvedColumn(column);
}
@@ -1414,10 +1414,10 @@ class SchemaResolveVisitorFactory {
}
String ident = x.getName();
long hash = x.name_hash_lower();
long hash = x.nameHashCode64();
SQLTableSource tableSource = null;
if ((hash == FNVUtils.LEVEL || hash == FNVUtils.CONNECT_BY_ISCYCLE)
if ((hash == FnvConstants.LEVEL || hash == FnvConstants.CONNECT_BY_ISCYCLE)
&& ctx.object instanceof SQLSelectQueryBlock) {
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) ctx.object;
if (queryBlock.getStartWith() != null
@@ -1527,7 +1527,7 @@ class SchemaResolveVisitorFactory {
SQLExpr expr = ((SQLExprTableSource) tableSource).getExpr();
if (expr instanceof SQLIdentifierExpr) {
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
long identHash = identExpr.name_hash_lower();
long identHash = identExpr.nameHashCode64();
tableSource = unwrapAlias(ctx, tableSource, identHash);
}
@@ -1562,7 +1562,7 @@ class SchemaResolveVisitorFactory {
SQLExpr ownerObj = x.getOwner();
if (ownerObj instanceof SQLIdentifierExpr) {
SQLIdentifierExpr owner = (SQLIdentifierExpr) ownerObj;
owner_hash = owner.name_hash_lower();
owner_hash = owner.nameHashCode64();
} else if (ownerObj instanceof SQLPropertyExpr) {
owner_hash = ((SQLPropertyExpr) ownerObj).hashCode64();
}
@@ -1625,7 +1625,7 @@ class SchemaResolveVisitorFactory {
if (tableSource != null) {
x.setResolvedTableSource(tableSource);
SQLColumnDefinition column = tableSource.findColumn(x.name_hash_lower());
SQLColumnDefinition column = tableSource.findColumn(x.nameHashCode64());
if (column != null) {
x.setResolvedColumn(column);
}
@@ -1717,7 +1717,7 @@ class SchemaResolveVisitorFactory {
}
SQLTableSource tableSource = x.findTableSource(propertyExpr.getOwnernName());
if (tableSource != null) {
column = tableSource.findColumn(propertyExpr.name_hash_lower());
column = tableSource.findColumn(propertyExpr.nameHashCode64());
if (column != null) {
propertyExpr.setResolvedColumn(column);
}
@@ -1726,7 +1726,7 @@ class SchemaResolveVisitorFactory {
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
visitor.visit(identExpr);
long name_hash = identExpr.name_hash_lower();
long name_hash = identExpr.nameHashCode64();
SQLColumnDefinition column = identExpr.getResolvedColumn();
if (column != null) {
@@ -1786,7 +1786,7 @@ class SchemaResolveVisitorFactory {
if (orderByItemExpr instanceof SQLIdentifierExpr) {
SQLIdentifierExpr orderByItemIdentExpr = (SQLIdentifierExpr) orderByItemExpr;
long hash = orderByItemIdentExpr.name_hash_lower();
long hash = orderByItemIdentExpr.nameHashCode64();
SQLSelectItem selectItem = x.findSelectItem(hash);
if (selectItem != null) {
@@ -1901,7 +1901,7 @@ class SchemaResolveVisitorFactory {
if (orderByItemExpr instanceof SQLIdentifierExpr) {
SQLIdentifierExpr orderByItemIdentExpr = (SQLIdentifierExpr) orderByItemExpr;
long hash = orderByItemIdentExpr.name_hash_lower();
long hash = orderByItemIdentExpr.nameHashCode64();
SQLSelectItem selectItem = null;
if (queryBlock != null) {
@@ -1971,7 +1971,7 @@ class SchemaResolveVisitorFactory {
if (identifierExpr != null) {
checkParameter(visitor, identifierExpr);
SQLTableSource tableSource = unwrapAlias(visitor.getContext(), null, identifierExpr.name_hash_lower());
SQLTableSource tableSource = unwrapAlias(visitor.getContext(), null, identifierExpr.nameHashCode64());
if (tableSource != null) {
identifierExpr.setResolvedTableSource(tableSource);
}
@@ -36,7 +36,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleDbLinkExpr;
import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleExpr;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitorAdapter;
import com.alibaba.druid.sql.ast.statement.SQLDeclareStatement;
import com.alibaba.druid.sql.parser.SQLParserUtils;
import com.alibaba.druid.sql.repository.SchemaObject;
import com.alibaba.druid.sql.repository.SchemaRepository;
import com.alibaba.druid.stat.TableStat;
@@ -44,7 +43,8 @@ import com.alibaba.druid.stat.TableStat.Column;
import com.alibaba.druid.stat.TableStat.Condition;
import com.alibaba.druid.stat.TableStat.Mode;
import com.alibaba.druid.stat.TableStat.Relationship;
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 com.alibaba.druid.util.StringUtils;
@@ -268,7 +268,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
}
} else if (tableSource instanceof SQLWithSubqueryClause.Entry
|| tableSource instanceof SQLSubqueryTableSource) {
SQLTableSource xx = tableSource.findTableSourceWithColumn(x.name_hash_lower());
SQLTableSource xx = tableSource.findTableSourceWithColumn(x.nameHashCode64());
if (xx != null) {
}
@@ -930,7 +930,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
return false;
}
column = addColumn(table.getName(), ident, table.name_hash_lower(), x.name_hash_lower());
column = addColumn(table.getName(), ident, table.nameHashCode64(), x.nameHashCode64());
if (column != null && isParentGroupBy(x)) {
this.groupByColumns.add(column);
@@ -939,7 +939,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
} else if (expr instanceof SQLPropertyExpr) {
SQLPropertyExpr table = (SQLPropertyExpr) expr;
String tableName = table.toString();
column = addColumn(tableName, ident, 0, x.name_hash_lower());
column = addColumn(tableName, ident, 0, x.nameHashCode64());
if (column != null && isParentGroupBy(x)) {
this.groupByColumns.add(column);
@@ -969,7 +969,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
tableName = table.toString();
}
column = addColumn(tableName, ident, 0, x.name_hash_lower());
column = addColumn(tableName, ident, 0, x.nameHashCode64());
}
}
} else if (tableSource instanceof SQLWithSubqueryClause.Entry
@@ -1188,12 +1188,12 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
return false;
}
long hash = x.name_hash_lower();
long hash = x.nameHashCode64();
if (isPseudoColumn(hash)) {
return false;
}
if ((hash == FNVUtils.LEVEL || hash == FNVUtils.CONNECT_BY_ISCYCLE)
if ((hash == FnvConstants.LEVEL || hash == FnvConstants.CONNECT_BY_ISCYCLE)
&& x.getResolvedColumn() == null
&& tableSource == null) {
return false;
@@ -1206,7 +1206,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
SQLExpr expr = ((SQLExprTableSource) tableSource).getExpr();
if (expr instanceof SQLIdentifierExpr) {
SQLIdentifierExpr table = (SQLIdentifierExpr) expr;
column = addColumn(table.getName(), ident, table.name_hash_lower(), hash);
column = addColumn(table.getName(), ident, table.nameHashCode64(), hash);
if (column != null && isParentGroupBy(x)) {
this.groupByColumns.add(column);
@@ -1244,7 +1244,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
tableName = table.toString();
}
column = addColumn(tableName, ident, 0, x.name_hash_lower());
column = addColumn(tableName, ident, 0, x.nameHashCode64());
}
}
} else if (tableSource instanceof SQLWithSubqueryClause.Entry
@@ -1421,9 +1421,9 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
int p = tableName.indexOf('.');
if (p != -1) {
SQLExpr owner = SQLUtils.toSQLExpr(tableName, dbType);
hashCode = FNVUtils.fnv_64_lower(new SQLPropertyExpr(owner, columnName));
hashCode = new SQLPropertyExpr(owner, columnName).hashCode64();
} else {
hashCode = FNVUtils.fnv_64_lower(tableName, columnName);
hashCode = FnvHash.fnv_64_lower(tableName, columnName);
}
return columns.containsKey(hashCode);
}