improved sql parser.

This commit is contained in:
wenshao
2017-08-31 11:20:04 +08:00
parent ce2daf6b9a
commit 947059f715
36 changed files with 1291 additions and 670 deletions
@@ -22,7 +22,7 @@ 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.Constants;
import com.alibaba.druid.util.FnvHash;
public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLReplaceable {
@@ -220,8 +220,8 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
public SQLDataType computeDataType() {
long hash = methodNameHashCod64();
if (hash == FnvConstants.COUNT
|| hash == FnvConstants.ROW_NUMBER) {
if (hash == FnvHash.Constants.COUNT
|| hash == FnvHash.Constants.ROW_NUMBER) {
return SQLIntegerExpr.DEFAULT_DATA_TYPE;
}
@@ -232,8 +232,8 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
}
}
if (hash == FnvConstants.WM_CONAT
|| hash == FnvConstants.GROUP_CONCAT) {
if (hash == FnvHash.Constants.WM_CONAT
|| hash == FnvHash.Constants.GROUP_CONCAT) {
return SQLCharExpr.DEFAULT_DATA_TYPE;
}
@@ -109,6 +109,14 @@ public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
return x;
}
public SQLIdentifierExpr simplify() {
String normalized = SQLUtils.normalize(name);
if (normalized != name) {
return new SQLIdentifierExpr(name, hashCode64);
}
return this;
}
public String normalizedName() {
return SQLUtils.normalize(name);
}
@@ -18,6 +18,7 @@ package com.alibaba.druid.sql.ast.expr;
import com.alibaba.druid.sql.ast.SQLDataType;
import com.alibaba.druid.sql.ast.SQLDataTypeImpl;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.Utils;
import java.io.IOException;
import java.math.BigDecimal;
@@ -80,13 +81,12 @@ public class SQLNumberExpr extends SQLNumericLiteralExpr implements SQLValuableE
@Override
public int hashCode() {
if (chars != null && number == null) {
this.number = new BigDecimal(chars);
Number number = getNumber();
if (number == null) {
return 0;
}
final int prime = 31;
int result = 1;
result = prime * result + ((number == null) ? 0 : number.hashCode());
return result;
return number.hashCode();
}
@Override
@@ -104,19 +104,9 @@ public class SQLNumberExpr extends SQLNumericLiteralExpr implements SQLValuableE
if (getClass() != obj.getClass()) {
return false;
}
SQLNumberExpr other = (SQLNumberExpr) obj;
if (other.chars != null && other.number == null) {
other.number = new BigDecimal(other.chars);
}
if (number == null) {
if (other.number != null) {
return false;
}
} else if (!number.equals(other.number)) {
return false;
}
return true;
SQLNumberExpr other = (SQLNumberExpr) obj;
return Utils.equals(getNumber(), other.getNumber());
}
public SQLNumberExpr clone() {