mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user