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,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;
}