mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor sql parser.
This commit is contained in:
@@ -26,7 +26,7 @@ public class SQLOver extends SQLObjectImpl {
|
||||
protected SQLOrderBy orderBy;
|
||||
|
||||
// for db2
|
||||
protected SQLExpr of;
|
||||
protected SQLName of;
|
||||
|
||||
protected SQLExpr windowing;
|
||||
protected WindowingType windowingType = WindowingType.ROWS;
|
||||
@@ -71,11 +71,11 @@ public class SQLOver extends SQLObjectImpl {
|
||||
this.orderBy = orderBy;
|
||||
}
|
||||
|
||||
public SQLExpr getOf() {
|
||||
public SQLName getOf() {
|
||||
return of;
|
||||
}
|
||||
|
||||
public void setOf(SQLExpr of) {
|
||||
public void setOf(SQLName of) {
|
||||
if (of != null) {
|
||||
of.setParent(this);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,9 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable, SQLRe
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, this.arguments);
|
||||
acceptChild(visitor, this.keep);
|
||||
acceptChild(visitor, this.over);
|
||||
acceptChild(visitor, this.withinGroup);
|
||||
}
|
||||
|
||||
visitor.endVisit(this);
|
||||
|
||||
@@ -22,12 +22,12 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
|
||||
protected String name;
|
||||
private transient String lowerName;
|
||||
private transient long hashCode64;
|
||||
protected String name;
|
||||
private String lowerName;
|
||||
private long hashCode64;
|
||||
|
||||
private transient SQLObject resolvedColumn;
|
||||
private transient SQLObject resolvedOwnerObject;
|
||||
private SQLObject resolvedColumn;
|
||||
private SQLObject resolvedOwnerObject;
|
||||
|
||||
public SQLIdentifierExpr(){
|
||||
|
||||
@@ -125,6 +125,10 @@ public class SQLIdentifierExpr extends SQLExprImpl implements SQLName {
|
||||
return null;
|
||||
}
|
||||
|
||||
public SQLObject getResolvedColumnObject() {
|
||||
return resolvedColumn;
|
||||
}
|
||||
|
||||
public void setResolvedColumn(SQLColumnDefinition resolvedColumn) {
|
||||
this.resolvedColumn = resolvedColumn;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
|
||||
private transient long hashCode64;
|
||||
|
||||
private transient SQLColumnDefinition resolvedColumn;
|
||||
private transient SQLObject resolvedTableSource;
|
||||
private transient SQLObject resolvedOwnerObject;
|
||||
|
||||
public SQLPropertyExpr(String owner, String name){
|
||||
this(new SQLIdentifierExpr(owner), name);
|
||||
@@ -119,7 +119,7 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
|
||||
} else if (owner == null){
|
||||
hash = FnvHash.BASIC;
|
||||
} else {
|
||||
hash = FnvHash.fnv_64_lower(owner.toString());
|
||||
hash = FnvHash.fnv1a_64_lower(owner.toString());
|
||||
|
||||
hash ^= '.';
|
||||
hash *= FnvHash.PRIME;
|
||||
@@ -170,7 +170,7 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
|
||||
|
||||
x.hashCode64 = hashCode64;
|
||||
x.resolvedColumn = resolvedColumn;
|
||||
x.resolvedTableSource = resolvedTableSource;
|
||||
x.resolvedOwnerObject = resolvedOwnerObject;
|
||||
|
||||
return x;
|
||||
}
|
||||
@@ -214,41 +214,45 @@ public class SQLPropertyExpr extends SQLExprImpl implements SQLName {
|
||||
}
|
||||
|
||||
public SQLTableSource getResolvedTableSource() {
|
||||
if (resolvedTableSource instanceof SQLTableSource) {
|
||||
return (SQLTableSource) resolvedTableSource;
|
||||
if (resolvedOwnerObject instanceof SQLTableSource) {
|
||||
return (SQLTableSource) resolvedOwnerObject;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setResolvedTableSource(SQLTableSource resolvedTableSource) {
|
||||
this.resolvedTableSource = resolvedTableSource;
|
||||
this.resolvedOwnerObject = resolvedTableSource;
|
||||
}
|
||||
|
||||
public void setResolvedProcedure(SQLCreateProcedureStatement stmt) {
|
||||
this.resolvedTableSource = stmt;
|
||||
this.resolvedOwnerObject = stmt;
|
||||
}
|
||||
|
||||
public void setResolvedOwnerObject(SQLObject resolvedOwnerObject) {
|
||||
this.resolvedTableSource = resolvedOwnerObject;
|
||||
this.resolvedOwnerObject = resolvedOwnerObject;
|
||||
}
|
||||
|
||||
public SQLCreateProcedureStatement getResolvedProcudure() {
|
||||
if (this.resolvedTableSource instanceof SQLCreateProcedureStatement) {
|
||||
return (SQLCreateProcedureStatement) this.resolvedTableSource;
|
||||
if (this.resolvedOwnerObject instanceof SQLCreateProcedureStatement) {
|
||||
return (SQLCreateProcedureStatement) this.resolvedOwnerObject;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public SQLObject getResolvedOwnerObject() {
|
||||
return resolvedOwnerObject;
|
||||
}
|
||||
|
||||
public SQLDataType computeDataType() {
|
||||
if (resolvedColumn != null) {
|
||||
return resolvedColumn.getDataType();
|
||||
}
|
||||
|
||||
if (resolvedTableSource != null
|
||||
&& resolvedTableSource instanceof SQLSubqueryTableSource) {
|
||||
SQLSelect select = ((SQLSubqueryTableSource) resolvedTableSource).getSelect();
|
||||
if (resolvedOwnerObject != null
|
||||
&& resolvedOwnerObject instanceof SQLSubqueryTableSource) {
|
||||
SQLSelect select = ((SQLSubqueryTableSource) resolvedOwnerObject).getSelect();
|
||||
SQLSelectQueryBlock queryBlock = select.getFirstQueryBlock();
|
||||
if (queryBlock == null) {
|
||||
return null;
|
||||
|
||||
@@ -32,7 +32,6 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
|
||||
protected SQLExpr expr;
|
||||
private List<SQLName> partitions;
|
||||
|
||||
private SchemaObject schemaObject;
|
||||
|
||||
public SQLExprTableSource(){
|
||||
|
||||
@@ -50,7 +50,10 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
protected SQLLimit limit;
|
||||
|
||||
// for oracle
|
||||
protected List<SQLExpr> forUpdateOf;
|
||||
protected List<SQLExpr> forUpdateOf;
|
||||
|
||||
protected List<SQLExpr> distributeBy;
|
||||
protected List<SQLSelectOrderByItem> sortBy;
|
||||
|
||||
public SQLSelectQueryBlock(){
|
||||
|
||||
@@ -308,6 +311,14 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
this.noCycle = noCycle;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getDistributeBy() {
|
||||
return distributeBy;
|
||||
}
|
||||
|
||||
public List<SQLSelectOrderByItem> getSortBy() {
|
||||
return sortBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
@@ -500,7 +511,7 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean selectItemHashAllColumn() {
|
||||
public boolean selectItemHasAllColumn() {
|
||||
for (SQLSelectItem item : this.selectList) {
|
||||
SQLExpr expr = item.getExpr();
|
||||
|
||||
@@ -512,7 +523,7 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
SQLSelect subSelect = ((SQLSubqueryTableSource) from).select;
|
||||
SQLSelectQueryBlock queryBlock = subSelect.getQueryBlock();
|
||||
if (queryBlock != null) {
|
||||
return queryBlock.selectItemHashAllColumn();
|
||||
return queryBlock.selectItemHasAllColumn();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -522,6 +533,23 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
return false;
|
||||
}
|
||||
|
||||
public SQLSelectItem findAllColumnSelectItem() {
|
||||
SQLSelectItem allColumnItem = null;
|
||||
for (SQLSelectItem item : this.selectList) {
|
||||
SQLExpr expr = item.getExpr();
|
||||
|
||||
boolean allColumn = expr instanceof SQLAllColumnExpr
|
||||
|| (expr instanceof SQLPropertyExpr && ((SQLPropertyExpr) expr).getName().equals("*"));
|
||||
|
||||
if (allColumnItem != null) {
|
||||
return null; // duplicateAllColumn
|
||||
}
|
||||
allColumnItem = item;
|
||||
}
|
||||
|
||||
return allColumnItem;
|
||||
}
|
||||
|
||||
public SQLColumnDefinition findColumn(String columnName) {
|
||||
if (from == null) {
|
||||
return null;
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLUpdateStatement extends SQLStatementImpl implements SQLReplaceable {
|
||||
protected SQLWithSubqueryClause with; // for pg
|
||||
|
||||
protected final List<SQLUpdateSetItem> items = new ArrayList<SQLUpdateSetItem>();
|
||||
protected SQLExpr where;
|
||||
@@ -161,4 +162,15 @@ public class SQLUpdateStatement extends SQLStatementImpl implements SQLReplaceab
|
||||
}
|
||||
this.orderBy = orderBy;
|
||||
}
|
||||
|
||||
public SQLWithSubqueryClause getWith() {
|
||||
return with;
|
||||
}
|
||||
|
||||
public void setWith(SQLWithSubqueryClause with) {
|
||||
if (with != null) {
|
||||
with.setParent(this);
|
||||
}
|
||||
this.with = with;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,15 @@ public class SQLWithSubqueryClause extends SQLObjectImpl {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
if (subQuery != null) {
|
||||
SQLSelectQueryBlock queryBlock = subQuery.getFirstQueryBlock();
|
||||
if (queryBlock != null) {
|
||||
if (queryBlock.findSelectItem(columnNameHash) != null) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ public class DB2ExprParser extends SQLExprParser {
|
||||
static {
|
||||
String[] strings = { "AVG", "COUNT", "MAX", "MIN", "STDDEV", "SUM", "ROW_NUMBER",
|
||||
"ROWNUMBER" };
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv1a_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv1a_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
|
||||
@@ -63,10 +63,10 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
|
||||
static {
|
||||
String[] strings = { "AVG", "COUNT", "GROUP_CONCAT", "MAX", "MIN", "STDDEV", "SUM" };
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv1a_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv1a_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
|
||||
+9
-52
@@ -69,9 +69,6 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
repository.resolve(x);
|
||||
}
|
||||
|
||||
setAliasMap();
|
||||
getAliasMap().put("DUAL", null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -87,8 +84,6 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
repository.resolve(x);
|
||||
}
|
||||
|
||||
setAliasMap();
|
||||
|
||||
setMode(x, Mode.Delete);
|
||||
|
||||
accept(x.getFrom());
|
||||
@@ -96,10 +91,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
x.getTableSource().accept(this);
|
||||
|
||||
if (x.getTableSource() instanceof SQLExprTableSource) {
|
||||
SQLName tableName = (SQLName) ((SQLExprTableSource) x.getTableSource()).getExpr();
|
||||
String ident = tableName.toString();
|
||||
|
||||
TableStat stat = this.getTableStat(ident);
|
||||
TableStat stat = this.getTableStat(x.getExprTableSource());
|
||||
stat.incrementDeleteCount();
|
||||
}
|
||||
|
||||
@@ -112,7 +104,6 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
}
|
||||
|
||||
public void endVisit(MySqlDeleteStatement x) {
|
||||
setAliasMap(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,27 +120,10 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
setMode(x, Mode.Insert);
|
||||
|
||||
setAliasMap();
|
||||
TableStat stat = getTableStat(x.getTableSource());
|
||||
|
||||
SQLName tableName = x.getTableName();
|
||||
|
||||
String ident = null;
|
||||
if (tableName instanceof SQLIdentifierExpr) {
|
||||
ident = ((SQLIdentifierExpr) tableName).getName();
|
||||
} else if (tableName instanceof SQLPropertyExpr) {
|
||||
SQLPropertyExpr propertyExpr = (SQLPropertyExpr) tableName;
|
||||
if (propertyExpr.getOwner() instanceof SQLIdentifierExpr) {
|
||||
ident = propertyExpr.toString();
|
||||
}
|
||||
}
|
||||
|
||||
if (ident != null) {
|
||||
TableStat stat = getTableStat(ident);
|
||||
if (stat != null) {
|
||||
stat.incrementInsertCount();
|
||||
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
putAliasMap(aliasMap, x.getAlias(), ident);
|
||||
putAliasMap(aliasMap, ident, ident);
|
||||
}
|
||||
|
||||
accept(x.getColumns());
|
||||
@@ -299,26 +273,12 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
setMode(x, Mode.Replace);
|
||||
|
||||
setAliasMap();
|
||||
|
||||
SQLName tableName = x.getTableName();
|
||||
|
||||
String ident = null;
|
||||
if (tableName instanceof SQLIdentifierExpr) {
|
||||
ident = ((SQLIdentifierExpr) tableName).getName();
|
||||
} else if (tableName instanceof SQLPropertyExpr) {
|
||||
SQLPropertyExpr propertyExpr = (SQLPropertyExpr) tableName;
|
||||
if (propertyExpr.getOwner() instanceof SQLIdentifierExpr) {
|
||||
ident = propertyExpr.toString();
|
||||
}
|
||||
}
|
||||
TableStat stat = getTableStat(tableName);
|
||||
|
||||
if (ident != null) {
|
||||
TableStat stat = getTableStat(ident);
|
||||
if (stat != null) {
|
||||
stat.incrementInsertCount();
|
||||
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
putAliasMap(aliasMap, ident, ident);
|
||||
}
|
||||
|
||||
accept(x.getColumns());
|
||||
@@ -480,7 +440,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
SQLName tableName = x.getTableName();
|
||||
if (tableName != null) {
|
||||
String table = tableName.toString();
|
||||
getTableStat(table);
|
||||
getTableStat(tableName);
|
||||
|
||||
SQLName columnName = x.getColumnName();
|
||||
if (columnName != null) {
|
||||
@@ -1217,12 +1177,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlDeclareStatement x) {
|
||||
for (SQLDeclareItem item : x.getVarList()) {
|
||||
SQLName var = (SQLName) item.getName();
|
||||
this.variants.put(var.toString(), var);
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1355,4 +1310,6 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
public void endVisit(MySqlFlushStatement x) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -35,11 +35,9 @@ public class OdpsSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
|
||||
protected List<SQLHint> hints;
|
||||
|
||||
protected List<SQLExpr> distributeBy = new ArrayList<SQLExpr>();
|
||||
protected List<SQLSelectOrderByItem> sortBy = new ArrayList<SQLSelectOrderByItem>(2);
|
||||
|
||||
public OdpsSelectQueryBlock(){
|
||||
|
||||
distributeBy = new ArrayList<SQLExpr>();
|
||||
sortBy = new ArrayList<SQLSelectOrderByItem>(2);
|
||||
}
|
||||
|
||||
public SQLOrderBy getOrderBy() {
|
||||
@@ -50,13 +48,7 @@ public class OdpsSelectQueryBlock extends SQLSelectQueryBlock {
|
||||
this.orderBy = orderBy;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getDistributeBy() {
|
||||
return distributeBy;
|
||||
}
|
||||
|
||||
public List<SQLSelectOrderByItem> getSortBy() {
|
||||
return sortBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
@@ -46,10 +46,10 @@ public class OdpsExprParser extends SQLExprParser {
|
||||
"ROW_NUMBER",
|
||||
"WM_CONCAT"//
|
||||
};
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv1a_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv1a_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
|
||||
+1
-12
@@ -64,20 +64,14 @@ public class OdpsSchemaStatVisitor extends SchemaStatVisitor implements OdpsASTV
|
||||
public boolean visit(OdpsInsert x) {
|
||||
setMode(x, TableStat.Mode.Insert);
|
||||
|
||||
setAliasMap();
|
||||
|
||||
SQLExprTableSource tableSource = x.getTableSource();
|
||||
SQLExpr tableName = tableSource.getExpr();
|
||||
|
||||
if (tableName instanceof SQLName) {
|
||||
String ident = ((SQLName) tableName).toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
TableStat stat = getTableStat(tableName);
|
||||
stat.incrementInsertCount();
|
||||
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
putAliasMap(aliasMap, tableSource.getAlias(), ident);
|
||||
putAliasMap(aliasMap, ident, ident);
|
||||
}
|
||||
|
||||
for (SQLAssignItem partition : x.getPartitions()) {
|
||||
@@ -289,11 +283,6 @@ public class OdpsSchemaStatVisitor extends SchemaStatVisitor implements OdpsASTV
|
||||
|
||||
@Override
|
||||
public boolean visit(OdpsValuesTableSource x) {
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
if (aliasMap != null && x.getAlias() != null) {
|
||||
putAliasMap(aliasMap, x.getAlias(), null);
|
||||
addSubQuery(x.getAlias(), x);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public class OracleDbLinkExpr extends SQLExprImpl implements SQLName, OracleExpr
|
||||
} else if (expr == null){
|
||||
hash = FnvHash.BASIC;
|
||||
} else {
|
||||
hash = FnvHash.fnv_64_lower(expr.toString());
|
||||
hash = FnvHash.fnv1a_64_lower(expr.toString());
|
||||
|
||||
hash ^= '.';
|
||||
hash *= FnvHash.PRIME;
|
||||
|
||||
@@ -111,10 +111,10 @@ public class OracleExprParser extends SQLExprParser {
|
||||
"VARIANCE", //
|
||||
"WM_CONCAT"
|
||||
};
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv1a_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv1a_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
|
||||
+39
-109
@@ -63,6 +63,7 @@ import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.stat.TableStat.Column;
|
||||
import com.alibaba.druid.stat.TableStat.Mode;
|
||||
import com.alibaba.druid.stat.TableStat.Relationship;
|
||||
import com.alibaba.druid.util.FnvConstants;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
@@ -74,10 +75,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
public OracleSchemaStatVisitor(List<Object> parameters){
|
||||
super(JdbcConstants.ORACLE, parameters);
|
||||
this.variants.put("DUAL", null);
|
||||
this.variants.put("NOTFOUND", null);
|
||||
this.variants.put("TRUE", null);
|
||||
this.variants.put("FALSE", null);
|
||||
}
|
||||
|
||||
protected Column getColumn(SQLExpr expr) {
|
||||
@@ -90,42 +87,25 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
public boolean visit(OracleSelectTableReference x) {
|
||||
SQLExpr expr = x.getExpr();
|
||||
|
||||
if (expr instanceof SQLMethodInvokeExpr) {
|
||||
SQLMethodInvokeExpr methodInvoke = (SQLMethodInvokeExpr) expr;
|
||||
if ("TABLE".equalsIgnoreCase(methodInvoke.getMethodName()) && methodInvoke.getParameters().size() == 1) {
|
||||
expr = methodInvoke.getParameters().get(0);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
TableStat stat = getTableStat(x);
|
||||
|
||||
if (expr instanceof SQLName) {
|
||||
String ident;
|
||||
if (((SQLName) expr).nameHashCode64() == FnvConstants.DUAL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (expr instanceof SQLPropertyExpr) {
|
||||
String owner = ((SQLPropertyExpr) expr).getOwner().toString();
|
||||
String name = ((SQLPropertyExpr) expr).getName();
|
||||
|
||||
if (aliasMap.containsKey(owner)) {
|
||||
owner = aliasMap.get(owner);
|
||||
SQLPropertyExpr propertyExpr = (SQLPropertyExpr) expr;
|
||||
if (isSubQueryOrParamOrVariant(propertyExpr)) {
|
||||
return false;
|
||||
}
|
||||
} else if (expr instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr identifierExpr = (SQLIdentifierExpr) expr;
|
||||
if (isSubQueryOrParamOrVariant(identifierExpr)) {
|
||||
return false;
|
||||
}
|
||||
ident = owner + "." + name;
|
||||
} else {
|
||||
ident = expr.toString();
|
||||
}
|
||||
|
||||
if (containsSubQuery(ident)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("DUAL".equalsIgnoreCase(ident)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
x.putAttribute(ATTR_TABLE, ident);
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
|
||||
Mode mode = getMode();
|
||||
switch (mode) {
|
||||
case Delete:
|
||||
@@ -147,23 +127,15 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
break;
|
||||
}
|
||||
|
||||
putAliasMap(aliasMap, x.getAlias(), ident);
|
||||
putAliasMap(aliasMap, ident, ident);
|
||||
return false;
|
||||
}
|
||||
|
||||
accept(x.getExpr());
|
||||
// accept(x.getExpr());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void endVisit(SQLSelect x) {
|
||||
if (x.getQuery() != null) {
|
||||
String table = (String) x.getQuery().getAttribute(ATTR_TABLE);
|
||||
if (table != null) {
|
||||
x.putAttribute(ATTR_TABLE, table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean visit(OracleUpdateStatement x) {
|
||||
@@ -172,7 +144,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
repository.resolve(x);
|
||||
}
|
||||
|
||||
setAliasMap();
|
||||
setMode(x, Mode.Update);
|
||||
|
||||
SQLTableSource tableSource = x.getTableSource();
|
||||
@@ -187,10 +158,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
stat.incrementUpdateCount();
|
||||
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
aliasMap.put(ident, ident);
|
||||
aliasMap.put(tableSource.getAlias(), ident);
|
||||
} else {
|
||||
tableSource.accept(this);
|
||||
}
|
||||
@@ -220,9 +187,7 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
}
|
||||
}
|
||||
|
||||
visit((SQLSelectQueryBlock) x);
|
||||
|
||||
return true;
|
||||
return visit((SQLSelectQueryBlock) x);
|
||||
}
|
||||
|
||||
public void endVisit(OracleSelectQueryBlock x) {
|
||||
@@ -366,29 +331,29 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
@Override
|
||||
public boolean visit(OracleSelectJoin x) {
|
||||
super.visit(x);
|
||||
|
||||
for (SQLExpr item : x.getUsing()) {
|
||||
if (item instanceof SQLIdentifierExpr) {
|
||||
String columnName = ((SQLIdentifierExpr) item).getName();
|
||||
String leftTable = (String) x.getLeft().getAttribute(ATTR_TABLE);
|
||||
String rightTable = (String) x.getRight().getAttribute(ATTR_TABLE);
|
||||
if (leftTable != null && rightTable != null) {
|
||||
Relationship relationship = new Relationship();
|
||||
relationship.setLeft(new Column(leftTable, columnName));
|
||||
relationship.setRight(new Column(rightTable, columnName));
|
||||
relationship.setOperator("USING");
|
||||
relationships.add(relationship);
|
||||
}
|
||||
|
||||
if (leftTable != null) {
|
||||
addColumn(leftTable, columnName);
|
||||
}
|
||||
|
||||
if (rightTable != null) {
|
||||
addColumn(rightTable, columnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// for (SQLExpr item : x.getUsing()) {
|
||||
// if (item instanceof SQLIdentifierExpr) {
|
||||
// String columnName = ((SQLIdentifierExpr) item).getName();
|
||||
// String leftTable = (String) x.getLeft().getAttribute(ATTR_TABLE);
|
||||
// String rightTable = (String) x.getRight().getAttribute(ATTR_TABLE);
|
||||
// if (leftTable != null && rightTable != null) {
|
||||
// Relationship relationship = new Relationship();
|
||||
// relationship.setLeft(new Column(leftTable, columnName));
|
||||
// relationship.setRight(new Column(rightTable, columnName));
|
||||
// relationship.setOperator("USING");
|
||||
// relationships.add(relationship);
|
||||
// }
|
||||
//
|
||||
// if (leftTable != null) {
|
||||
// addColumn(leftTable, columnName);
|
||||
// }
|
||||
//
|
||||
// if (rightTable != null) {
|
||||
// addColumn(rightTable, columnName);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -422,18 +387,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
accept(x.getSelect());
|
||||
accept(x.getPivot());
|
||||
accept(x.getFlashback());
|
||||
|
||||
String table = (String) x.getSelect().getAttribute(ATTR_TABLE);
|
||||
if (x.getAlias() != null) {
|
||||
if (table != null) {
|
||||
this.aliasMap.put(x.getAlias(), table);
|
||||
}
|
||||
addSubQuery(x.getAlias(), x.getSelect());
|
||||
}
|
||||
|
||||
if (table != null) {
|
||||
x.putAttribute(ATTR_TABLE, table);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -471,15 +424,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleWithSubqueryEntry x) {
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
if (aliasMap != null) {
|
||||
String alias = x.getAlias();
|
||||
|
||||
if (alias != null) {
|
||||
putAliasMap(aliasMap, alias, null);
|
||||
addSubQuery(alias, x.getSubQuery());
|
||||
}
|
||||
}
|
||||
x.getSubQuery().accept(this);
|
||||
return false;
|
||||
}
|
||||
@@ -701,14 +645,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
stat.incrementInsertCount();
|
||||
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
if (aliasMap != null) {
|
||||
if (x.getAlias() != null) {
|
||||
putAliasMap(aliasMap, x.getAlias(), ident);
|
||||
}
|
||||
putAliasMap(aliasMap, ident, ident);
|
||||
}
|
||||
}
|
||||
|
||||
accept(x.getColumns());
|
||||
@@ -734,8 +670,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
x.putAttribute("_original_use_mode", getMode());
|
||||
setMode(x, Mode.Insert);
|
||||
|
||||
setAliasMap();
|
||||
|
||||
accept(x.getSubQuery());
|
||||
accept(x.getEntries());
|
||||
|
||||
@@ -1008,12 +942,8 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleForStatement x) {
|
||||
SQLName index = x.getIndex();
|
||||
this.getVariants().put(index.toString(), x);
|
||||
|
||||
x.getRange().accept(this);
|
||||
accept(x.getStatements());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
-10
@@ -25,8 +25,6 @@ public class PGUpdateStatement extends SQLUpdateStatement implements PGSQLStatem
|
||||
|
||||
private boolean only = false;
|
||||
|
||||
private SQLWithSubqueryClause with;
|
||||
|
||||
public PGUpdateStatement(){
|
||||
super (JdbcConstants.POSTGRESQL);
|
||||
}
|
||||
@@ -39,14 +37,6 @@ public class PGUpdateStatement extends SQLUpdateStatement implements PGSQLStatem
|
||||
this.only = only;
|
||||
}
|
||||
|
||||
public SQLWithSubqueryClause getWith() {
|
||||
return with;
|
||||
}
|
||||
|
||||
public void setWith(SQLWithSubqueryClause with) {
|
||||
this.with = with;
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
accept0((PGASTVisitor) visitor);
|
||||
}
|
||||
|
||||
@@ -54,10 +54,10 @@ public class PGExprParser extends SQLExprParser {
|
||||
|
||||
static {
|
||||
String[] strings = { "AVG", "COUNT", "MAX", "MIN", "STDDEV", "SUM", "ROW_NUMBER" };
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv1a_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv1a_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
|
||||
+1
-24
@@ -101,8 +101,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
x.getWith().accept(this);
|
||||
}
|
||||
|
||||
setAliasMap();
|
||||
|
||||
SQLTableSource using = x.getUsing();
|
||||
if (using != null) {
|
||||
using.accept(this);
|
||||
@@ -111,9 +109,7 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
x.putAttribute("_original_use_mode", getMode());
|
||||
setMode(x, Mode.Delete);
|
||||
|
||||
String ident = ((SQLIdentifierExpr) x.getTableName()).getName();
|
||||
|
||||
TableStat stat = getTableStat(ident, x.getAlias());
|
||||
TableStat stat = getTableStat(x.getTableName());
|
||||
stat.incrementDeleteCount();
|
||||
|
||||
accept(x.getWhere());
|
||||
@@ -133,8 +129,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
repository.resolve(x);
|
||||
}
|
||||
|
||||
setAliasMap();
|
||||
|
||||
if (x.getWith() != null) {
|
||||
x.getWith().accept(this);
|
||||
}
|
||||
@@ -149,14 +143,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
stat.incrementInsertCount();
|
||||
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
if (aliasMap != null) {
|
||||
if (x.getAlias() != null) {
|
||||
aliasMap.put(x.getAlias(), ident);
|
||||
}
|
||||
aliasMap.put(ident, ident);
|
||||
}
|
||||
}
|
||||
|
||||
accept(x.getColumns());
|
||||
@@ -191,10 +177,6 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
repository.resolve(x);
|
||||
}
|
||||
|
||||
Map<String, String> oldAliasMap = getAliasMap();
|
||||
|
||||
setAliasMap();
|
||||
|
||||
if (x.getWith() != null) {
|
||||
x.getWith().accept(this);
|
||||
}
|
||||
@@ -206,14 +188,9 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
|
||||
accept(x.getFrom());
|
||||
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
aliasMap.put(ident, ident);
|
||||
|
||||
accept(x.getItems());
|
||||
accept(x.getWhere());
|
||||
|
||||
setAliasMap(oldAliasMap);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -44,10 +44,10 @@ public class SQLServerExprParser extends SQLExprParser {
|
||||
|
||||
static {
|
||||
String[] strings = { "AVG", "COUNT", "MAX", "MIN", "ROW_NUMBER", "STDDEV", "SUM" };
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv1a_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv1a_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
|
||||
-5
@@ -84,16 +84,11 @@ public class SQLServerSchemaStatVisitor extends SchemaStatVisitor implements SQL
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerUpdateStatement x) {
|
||||
setAliasMap();
|
||||
|
||||
String ident = x.getTableName().toString();
|
||||
|
||||
TableStat stat = getTableStat(ident);
|
||||
stat.incrementUpdateCount();
|
||||
|
||||
Map<String, String> aliasMap = getAliasMap();
|
||||
aliasMap.put(ident, ident);
|
||||
|
||||
accept(x.getItems());
|
||||
accept(x.getFrom());
|
||||
accept(x.getWhere());
|
||||
|
||||
@@ -1529,7 +1529,7 @@ public class Lexer {
|
||||
if (stringVal == null) {
|
||||
stringVal = subString(mark, bufPos);
|
||||
}
|
||||
this.hash_lower = FnvHash.fnv_64_lower(stringVal);
|
||||
this.hash_lower = FnvHash.fnv1a_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 = FnvHash.fnv_64_lower(stringVal);
|
||||
this.hash_lower = FnvHash.fnv1a_64_lower(stringVal);
|
||||
}
|
||||
return hash_lower;
|
||||
}
|
||||
|
||||
@@ -56,10 +56,10 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
static {
|
||||
String[] strings = { "AVG", "COUNT", "MAX", "MIN", "STDDEV", "SUM" };
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv1a_64_lower(strings, true);
|
||||
AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
|
||||
for (String str : strings) {
|
||||
long hash = FnvHash.fnv_64_lower(str);
|
||||
long hash = FnvHash.fnv1a_64_lower(str);
|
||||
int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
|
||||
AGGREGATE_FUNCTIONS[index] = str;
|
||||
}
|
||||
@@ -896,7 +896,6 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
|
||||
String methodName = null;
|
||||
boolean isAggregate = false;
|
||||
String aggMethodName = null;
|
||||
SQLMethodInvokeExpr methodInvokeExpr;
|
||||
SQLExpr owner = null;
|
||||
@@ -933,7 +932,7 @@ public class SQLExprParser extends SQLParser {
|
||||
} else if (expr instanceof SQLPropertyExpr) {
|
||||
methodName = expr.toString();
|
||||
aggMethodName = SQLUtils.normalize(methodName);
|
||||
hash_lower = FnvHash.fnv_64_lower(aggMethodName);
|
||||
hash_lower = FnvHash.fnv1a_64_lower(aggMethodName);
|
||||
aggMethodName = getAggreateFunction(hash_lower);
|
||||
|
||||
owner = ((SQLPropertyExpr) expr).getOwner();
|
||||
@@ -1229,7 +1228,7 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
|
||||
public boolean isAggreateFunction(String word) {
|
||||
long hash_lower = FnvHash.fnv_64_lower(word);
|
||||
long hash_lower = FnvHash.fnv1a_64_lower(word);
|
||||
return isAggreateFunction(hash_lower);
|
||||
}
|
||||
|
||||
@@ -1296,7 +1295,7 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
if (lexer.token == Token.OF) {
|
||||
lexer.nextToken();
|
||||
SQLExpr of = this.expr();
|
||||
SQLName of = this.name();
|
||||
over.setOf(of);
|
||||
}
|
||||
|
||||
|
||||
@@ -203,6 +203,11 @@ class SchemaResolveVisitorFactory {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLOver x) {
|
||||
resolve(this, x);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(Option option) {
|
||||
return (options & option.mask) != 0;
|
||||
@@ -346,6 +351,11 @@ class SchemaResolveVisitorFactory {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLOver x) {
|
||||
resolve(this, x);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(Option option) {
|
||||
return (options & option.mask) != 0;
|
||||
@@ -397,12 +407,28 @@ class SchemaResolveVisitorFactory {
|
||||
public boolean visit(OracleForStatement x) {
|
||||
Context ctx = createContext(x);
|
||||
|
||||
SQLExpr index = x.getIndex();
|
||||
SQLName index = x.getIndex();
|
||||
SQLExpr range = x.getRange();
|
||||
|
||||
if (index != null) {
|
||||
SQLDeclareItem declareItem = new SQLDeclareItem(index, null);
|
||||
declareItem.setParent(x);
|
||||
|
||||
if (index instanceof SQLIdentifierExpr) {
|
||||
((SQLIdentifierExpr) index).setResolvedDeclareItem(declareItem);
|
||||
}
|
||||
declareItem.setResolvedObject(range);
|
||||
ctx.declare(declareItem);
|
||||
if (range instanceof SQLQueryExpr) {
|
||||
SQLSelect select = ((SQLQueryExpr) range).getSubQuery();
|
||||
SQLSubqueryTableSource tableSource = new SQLSubqueryTableSource(select);
|
||||
declareItem.setResolvedObject(tableSource);
|
||||
}
|
||||
|
||||
index.accept(this);
|
||||
}
|
||||
|
||||
SQLExpr range = x.getRange();
|
||||
|
||||
if (range != null) {
|
||||
range.accept(this);
|
||||
}
|
||||
@@ -583,6 +609,11 @@ class SchemaResolveVisitorFactory {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLOver x) {
|
||||
resolve(this, x);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(Option option) {
|
||||
return (options & option.mask) != 0;
|
||||
@@ -751,6 +782,11 @@ class SchemaResolveVisitorFactory {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLOver x) {
|
||||
resolve(this, x);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(Option option) {
|
||||
return (options & option.mask) != 0;
|
||||
@@ -930,6 +966,11 @@ class SchemaResolveVisitorFactory {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLOver x) {
|
||||
resolve(this, x);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(Option option) {
|
||||
return (options & option.mask) != 0;
|
||||
@@ -1081,6 +1122,11 @@ class SchemaResolveVisitorFactory {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLOver x) {
|
||||
resolve(this, x);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(Option option) {
|
||||
return (options & option.mask) != 0;
|
||||
@@ -1217,6 +1263,11 @@ class SchemaResolveVisitorFactory {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLOver x) {
|
||||
resolve(this, x);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(Option option) {
|
||||
return (options & option.mask) != 0;
|
||||
@@ -1297,6 +1348,11 @@ class SchemaResolveVisitorFactory {
|
||||
static void resolve(SchemaResolveVisitor visitor, SQLUpdateStatement x) {
|
||||
SchemaResolveVisitor.Context ctx = visitor.createContext(x);
|
||||
|
||||
SQLWithSubqueryClause with = x.getWith();
|
||||
if (with != null) {
|
||||
with.accept(visitor);
|
||||
}
|
||||
|
||||
SQLTableSource table = x.getTableSource();
|
||||
SQLTableSource from = x.getFrom();
|
||||
|
||||
@@ -1453,7 +1509,7 @@ class SchemaResolveVisitorFactory {
|
||||
&& right instanceof SQLExprTableSource) {
|
||||
SQLSelect leftSelect = ((SQLSubqueryTableSource) left).getSelect();
|
||||
if (leftSelect.getQuery() instanceof SQLSelectQueryBlock) {
|
||||
boolean hasAllColumn = ((SQLSelectQueryBlock) leftSelect.getQuery()).selectItemHashAllColumn();
|
||||
boolean hasAllColumn = ((SQLSelectQueryBlock) leftSelect.getQuery()).selectItemHasAllColumn();
|
||||
if (!hasAllColumn) {
|
||||
tableSource = right;
|
||||
}
|
||||
@@ -1462,7 +1518,7 @@ class SchemaResolveVisitorFactory {
|
||||
&& left instanceof SQLExprTableSource) {
|
||||
SQLSelect rightSelect = ((SQLSubqueryTableSource) right).getSelect();
|
||||
if (rightSelect.getQuery() instanceof SQLSelectQueryBlock) {
|
||||
boolean hasAllColumn = ((SQLSelectQueryBlock) rightSelect.getQuery()).selectItemHashAllColumn();
|
||||
boolean hasAllColumn = ((SQLSelectQueryBlock) rightSelect.getQuery()).selectItemHasAllColumn();
|
||||
if (!hasAllColumn) {
|
||||
tableSource = left;
|
||||
}
|
||||
@@ -1629,8 +1685,10 @@ class SchemaResolveVisitorFactory {
|
||||
SQLDeclareItem declareItem = parentCtx.findDeclare(owner_hash);
|
||||
if (declareItem != null) {
|
||||
SQLObject resolvedObject = declareItem.getResolvedObject();
|
||||
if (resolvedObject instanceof SQLCreateProcedureStatement) {
|
||||
x.setResolvedProcedure((SQLCreateProcedureStatement) resolvedObject);
|
||||
if (resolvedObject instanceof SQLCreateProcedureStatement
|
||||
|| resolvedObject instanceof SQLCreateFunctionStatement
|
||||
|| resolvedObject instanceof SQLTableSource) {
|
||||
x.setResolvedOwnerObject(resolvedObject);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1661,7 +1719,7 @@ class SchemaResolveVisitorFactory {
|
||||
}
|
||||
}
|
||||
|
||||
for (SchemaResolveVisitor.Context parentCtx = ctx.parent;
|
||||
for (SchemaResolveVisitor.Context parentCtx = ctx;
|
||||
parentCtx != null;
|
||||
parentCtx = parentCtx.parent) {
|
||||
|
||||
@@ -1675,6 +1733,9 @@ class SchemaResolveVisitorFactory {
|
||||
} else if (parentCtx.object instanceof SQLInsertStatement) {
|
||||
SQLInsertStatement insertStmt = (SQLInsertStatement) parentCtx.object;
|
||||
with = insertStmt.getWith();
|
||||
} else if (parentCtx.object instanceof SQLUpdateStatement) {
|
||||
SQLUpdateStatement updateStmt = (SQLUpdateStatement) parentCtx.object;
|
||||
with = updateStmt.getWith();
|
||||
}
|
||||
|
||||
if (with != null) {
|
||||
@@ -2082,17 +2143,20 @@ class SchemaResolveVisitorFactory {
|
||||
}
|
||||
|
||||
static void resolve(SchemaResolveVisitor visitor, SQLCreateFunctionStatement x) {
|
||||
SchemaResolveVisitor.Context ctx = visitor.createContext(x);
|
||||
|
||||
{
|
||||
SQLDeclareItem declareItem = new SQLDeclareItem(x.getName().clone(), null);
|
||||
declareItem.setResolvedObject(x);
|
||||
|
||||
SchemaResolveVisitor.Context parentCtx = visitor.getContext();
|
||||
if (parentCtx != null) {
|
||||
SQLDeclareItem declareItem = new SQLDeclareItem(x.getName().clone(), null);
|
||||
declareItem.setResolvedObject(x);
|
||||
parentCtx.declare(declareItem);
|
||||
} else {
|
||||
ctx.declare(declareItem);
|
||||
}
|
||||
}
|
||||
|
||||
SchemaResolveVisitor.Context ctx = visitor.createContext(x);
|
||||
|
||||
for (SQLParameter parameter : x.getParameters()) {
|
||||
parameter.accept(visitor);
|
||||
}
|
||||
@@ -2105,17 +2169,21 @@ class SchemaResolveVisitorFactory {
|
||||
visitor.popContext();
|
||||
}
|
||||
static void resolve(SchemaResolveVisitor visitor, SQLCreateProcedureStatement x) {
|
||||
SchemaResolveVisitor.Context ctx = visitor.createContext(x);
|
||||
|
||||
{
|
||||
SQLDeclareItem declareItem = new SQLDeclareItem(x.getName().clone(), null);
|
||||
declareItem.setResolvedObject(x);
|
||||
|
||||
|
||||
SchemaResolveVisitor.Context parentCtx = visitor.getContext();
|
||||
if (parentCtx != null) {
|
||||
SQLDeclareItem declareItem = new SQLDeclareItem(x.getName().clone(), null);
|
||||
declareItem.setResolvedObject(x);
|
||||
parentCtx.declare(declareItem);
|
||||
} else {
|
||||
ctx.declare(declareItem);
|
||||
}
|
||||
}
|
||||
|
||||
SchemaResolveVisitor.Context ctx = visitor.createContext(x);
|
||||
|
||||
for (SQLParameter parameter : x.getParameters()) {
|
||||
parameter.accept(visitor);
|
||||
}
|
||||
@@ -2212,6 +2280,23 @@ class SchemaResolveVisitorFactory {
|
||||
}
|
||||
}
|
||||
|
||||
static void resolve(SchemaResolveVisitor visitor, SQLOver x) {
|
||||
SQLName of = x.getOf();
|
||||
SQLOrderBy orderBy = x.getOrderBy();
|
||||
List<SQLExpr> partitionBy = x.getPartitionBy();
|
||||
|
||||
|
||||
if (of == null // skip if of is not null
|
||||
&& orderBy != null) {
|
||||
orderBy.accept(visitor);
|
||||
}
|
||||
|
||||
if (partitionBy != null) {
|
||||
for (SQLExpr expr : partitionBy) {
|
||||
expr.accept(visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkParameter(SchemaResolveVisitor visitor, SQLIdentifierExpr x) {
|
||||
if (x.getResolvedParameter() != null) {
|
||||
@@ -2245,6 +2330,24 @@ class SchemaResolveVisitorFactory {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (parentCtx.object instanceof SQLSelect) {
|
||||
SQLSelect select = (SQLSelect) parentCtx.object;
|
||||
SQLWithSubqueryClause with = select.getWithSubQuery();
|
||||
if (with != null) {
|
||||
SQLWithSubqueryClause.Entry entry = with.findEntry(hash);
|
||||
if (entry != null) {
|
||||
x.setResolvedTableSource(entry);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SQLDeclareItem declareItem = parentCtx.findDeclare(hash);
|
||||
if (declareItem != null) {
|
||||
x.setResolvedDeclareItem(declareItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user