mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge branch 'master' into master
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -88,21 +88,44 @@ public final class ExportParameterVisitorUtils {
|
||||
if (param instanceof SQLCharExpr) {
|
||||
value = ((SQLCharExpr) param).getText();
|
||||
replace = true;
|
||||
}
|
||||
|
||||
if (param instanceof SQLBooleanExpr) {
|
||||
} else if (param instanceof SQLBooleanExpr) {
|
||||
value = ((SQLBooleanExpr) param).getBooleanValue();
|
||||
replace = true;
|
||||
}
|
||||
|
||||
if (param instanceof SQLNumericLiteralExpr) {
|
||||
} else if (param instanceof SQLNumericLiteralExpr) {
|
||||
value = ((SQLNumericLiteralExpr) param).getNumber();
|
||||
replace = true;
|
||||
}
|
||||
|
||||
if (param instanceof SQLHexExpr) {
|
||||
} else if (param instanceof SQLHexExpr) {
|
||||
value = ((SQLHexExpr) param).toBytes();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLTimestampExpr || param instanceof SQLDateExpr) {
|
||||
value = ((SQLTimestampExpr) param).getValue();
|
||||
replace = true;
|
||||
} else if (param instanceof SQLListExpr) {
|
||||
SQLListExpr list = ((SQLListExpr) param);
|
||||
|
||||
List<Object> listValues = new ArrayList<Object>();
|
||||
for (int i = 0; i < list.getItems().size(); i++) {
|
||||
SQLExpr listItem = list.getItems().get(i);
|
||||
|
||||
if (listItem instanceof SQLCharExpr) {
|
||||
Object listValue = ((SQLCharExpr) listItem).getText();
|
||||
listValues.add(listValue);
|
||||
} else if (listItem instanceof SQLBooleanExpr) {
|
||||
Object listValue = ((SQLBooleanExpr) listItem).getBooleanValue();
|
||||
listValues.add(listValue);
|
||||
} else if (listItem instanceof SQLNumericLiteralExpr) {
|
||||
Object listValue = ((SQLNumericLiteralExpr) listItem).getNumber();
|
||||
listValues.add(listValue);
|
||||
} else if (param instanceof SQLHexExpr) {
|
||||
Object listValue = ((SQLHexExpr) listItem).toBytes();
|
||||
listValues.add(listValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (listValues.size() == list.getItems().size()) {
|
||||
value = listValues;
|
||||
replace = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (replace) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@ package com.alibaba.druid.sql.visitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2OutputVisitor;
|
||||
@@ -61,9 +62,24 @@ public class ParameterizedOutputVisitorUtils {
|
||||
return parameterize(sql, dbType, null, outParameters);
|
||||
}
|
||||
|
||||
|
||||
private static void configVisitorFeatures(ParameterizedVisitor visitor, VisitorFeature ...features) {
|
||||
if(features != null) {
|
||||
for (int i = 0; i < features.length; i++) {
|
||||
visitor.config(features[i], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String parameterize(String sql
|
||||
, String dbType
|
||||
, SQLSelectListCache selectListCache, List<Object> outParameters) {
|
||||
, List<Object> outParameters, VisitorFeature ...features) {
|
||||
return parameterize(sql, dbType, null, outParameters, features);
|
||||
}
|
||||
|
||||
public static String parameterize(String sql
|
||||
, String dbType
|
||||
, SQLSelectListCache selectListCache, List<Object> outParameters, VisitorFeature ...visitorFeatures) {
|
||||
|
||||
final SQLParserFeature[] features = outParameters == null
|
||||
? defaultFeatures2
|
||||
@@ -85,6 +101,7 @@ public class ParameterizedOutputVisitorUtils {
|
||||
if (outParameters != null) {
|
||||
visitor.setOutputParameters(outParameters);
|
||||
}
|
||||
configVisitorFeatures(visitor, visitorFeatures);
|
||||
|
||||
for (int i = 0; i < statementList.size(); i++) {
|
||||
SQLStatement stmt = statementList.get(i);
|
||||
@@ -133,13 +150,13 @@ public class ParameterizedOutputVisitorUtils {
|
||||
public static long parameterizeHash(String sql
|
||||
, String dbType
|
||||
, List<Object> outParameters) {
|
||||
return parameterizeHash(sql, dbType, null, outParameters);
|
||||
return parameterizeHash(sql, dbType, null, outParameters, null);
|
||||
}
|
||||
|
||||
public static long parameterizeHash(String sql
|
||||
, String dbType
|
||||
, SQLSelectListCache selectListCache
|
||||
, List<Object> outParameters) {
|
||||
, List<Object> outParameters, VisitorFeature ...visitorFeatures) {
|
||||
|
||||
final SQLParserFeature[] features = outParameters == null
|
||||
? defaultFeatures2
|
||||
@@ -162,6 +179,7 @@ public class ParameterizedOutputVisitorUtils {
|
||||
if (outParameters != null) {
|
||||
visitor.setOutputParameters(outParameters);
|
||||
}
|
||||
configVisitorFeatures(visitor, visitorFeatures);
|
||||
|
||||
if (stmtSize == 1) {
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
@@ -276,4 +294,18 @@ public class ParameterizedOutputVisitorUtils {
|
||||
|
||||
return new SQLASTOutputVisitor(out, true);
|
||||
}
|
||||
|
||||
public static String restore(String sql, String dbType, List<Object> parameters) {
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, dbType);
|
||||
visitor.setInputParameters(parameters);
|
||||
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
stmt.accept(visitor);
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -799,4 +799,50 @@ public interface SQLASTVisitor {
|
||||
|
||||
boolean visit(SQLDropTypeStatement x);
|
||||
void endVisit(SQLDropTypeStatement x);
|
||||
|
||||
boolean visit(SQLExternalRecordFormat x);
|
||||
void endVisit(SQLExternalRecordFormat x);
|
||||
|
||||
boolean visit(SQLArrayDataType x);
|
||||
void endVisit(SQLArrayDataType x);
|
||||
|
||||
boolean visit(SQLMapDataType x);
|
||||
void endVisit(SQLMapDataType x);
|
||||
|
||||
boolean visit(SQLStructDataType x);
|
||||
void endVisit(SQLStructDataType x);
|
||||
|
||||
boolean visit(SQLStructDataType.Field x);
|
||||
void endVisit(SQLStructDataType.Field x);
|
||||
|
||||
boolean visit(SQLDropMaterializedViewStatement x);
|
||||
void endVisit(SQLDropMaterializedViewStatement x);
|
||||
|
||||
boolean visit(SQLAlterTableRenameIndex x);
|
||||
void endVisit(SQLAlterTableRenameIndex x);
|
||||
|
||||
boolean visit(SQLAlterSequenceStatement x);
|
||||
void endVisit(SQLAlterSequenceStatement x);
|
||||
|
||||
boolean visit(SQLAlterTableExchangePartition x);
|
||||
void endVisit(SQLAlterTableExchangePartition x);
|
||||
|
||||
boolean visit(SQLValuesExpr x);
|
||||
void endVisit(SQLValuesExpr x);
|
||||
|
||||
boolean visit(SQLValuesTableSource x);
|
||||
void endVisit(SQLValuesTableSource x);
|
||||
|
||||
boolean visit(SQLContainsExpr x);
|
||||
void endVisit(SQLContainsExpr x);
|
||||
|
||||
boolean visit(SQLRealExpr x);
|
||||
void endVisit(SQLRealExpr x);
|
||||
|
||||
boolean visit(SQLWindow x);
|
||||
void endVisit(SQLWindow x);
|
||||
|
||||
boolean visit(SQLDumpStatement x);
|
||||
void endVisit(SQLDumpStatement x);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +24,6 @@ import com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeUpdateClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLWhileStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeclareStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCommitStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
|
||||
public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
protected int features;
|
||||
@@ -1866,6 +1865,149 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
|
||||
}
|
||||
|
||||
public boolean visit(SQLExternalRecordFormat x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void endVisit(SQLExternalRecordFormat x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLArrayDataType x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLArrayDataType x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLMapDataType x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLMapDataType x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLStructDataType x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLStructDataType x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLStructDataType.Field x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLStructDataType.Field x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropMaterializedViewStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLDropMaterializedViewStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableRenameIndex x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLAlterTableRenameIndex x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterSequenceStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLAlterSequenceStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableExchangePartition x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLAlterTableExchangePartition x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLValuesExpr x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLValuesExpr x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLValuesTableSource x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void endVisit(SQLValuesTableSource x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLContainsExpr x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void endVisit(SQLContainsExpr x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLRealExpr x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void endVisit(SQLRealExpr x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLWindow x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void endVisit(SQLWindow x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDumpStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void endVisit(SQLDumpStatement x) {
|
||||
|
||||
}
|
||||
|
||||
public final boolean isEnabled(VisitorFeature feature) {
|
||||
return VisitorFeature.isEnabled(this.features, feature);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -73,6 +73,14 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
public SchemaRepository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
public void setRepository(SchemaRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public SchemaStatVisitor(List<Object> parameters){
|
||||
this((String) null, parameters);
|
||||
}
|
||||
@@ -248,13 +256,35 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (tableSource instanceof SQLWithSubqueryClause.Entry
|
||||
|| tableSource instanceof SQLSubqueryTableSource) {
|
||||
SQLTableSource xx = tableSource.findTableSourceWithColumn(x.nameHashCode64());
|
||||
if (xx != null) {
|
||||
} else if (tableSource instanceof SQLWithSubqueryClause.Entry) {
|
||||
return false;
|
||||
} else if (tableSource instanceof SQLSubqueryTableSource) {
|
||||
SQLSelectQueryBlock queryBlock = ((SQLSubqueryTableSource) tableSource).getSelect().getQueryBlock();
|
||||
if (queryBlock == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SQLSelectItem selectItem = queryBlock.findSelectItem(x.nameHashCode64());
|
||||
if (selectItem == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SQLExpr selectItemExpr = selectItem.getExpr();
|
||||
SQLTableSource columnTableSource = null;
|
||||
if (selectItemExpr instanceof SQLIdentifierExpr) {
|
||||
columnTableSource = ((SQLIdentifierExpr) selectItemExpr).getResolvedTableSource();
|
||||
} else if (selectItemExpr instanceof SQLPropertyExpr) {
|
||||
columnTableSource = ((SQLPropertyExpr) selectItemExpr).getResolvedTableSource();
|
||||
}
|
||||
|
||||
if (columnTableSource instanceof SQLExprTableSource && ((SQLExprTableSource) columnTableSource).getExpr() instanceof SQLName) {
|
||||
SQLName tableExpr = (SQLName) ((SQLExprTableSource) columnTableSource).getExpr();
|
||||
if (tableExpr instanceof SQLIdentifierExpr) {
|
||||
tableName = ((SQLIdentifierExpr) tableExpr).normalizedName();
|
||||
} else if (tableExpr instanceof SQLPropertyExpr) {
|
||||
tableName = ((SQLPropertyExpr) tableExpr).normalizedName();
|
||||
}
|
||||
}
|
||||
// skip
|
||||
} else {
|
||||
boolean skip = false;
|
||||
for (SQLObject parent = x.getParent();parent != null;parent = parent.getParent()) {
|
||||
@@ -509,6 +539,22 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
return aggregateFunctions;
|
||||
}
|
||||
|
||||
public boolean visit(SQLBetweenExpr x) {
|
||||
SQLObject parent = x.getParent();
|
||||
|
||||
SQLExpr test = x.getTestExpr();
|
||||
SQLExpr begin = x.getBeginExpr();
|
||||
SQLExpr end = x.getEndExpr();
|
||||
|
||||
statExpr(test);
|
||||
statExpr(begin);
|
||||
statExpr(end);
|
||||
|
||||
handleCondition(test, "BETWEEN", begin, end);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLBinaryOpExpr x) {
|
||||
SQLObject parent = x.getParent();
|
||||
|
||||
@@ -617,11 +663,18 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
if (valueColumn != null) {
|
||||
continue;
|
||||
}
|
||||
Object value = SQLEvalVisitorUtils.eval(dbType, item, parameters, false);
|
||||
if (value == SQLEvalVisitor.EVAL_VALUE_NULL) {
|
||||
value = null;
|
||||
|
||||
Object value;
|
||||
if (item instanceof SQLMethodInvokeExpr) {
|
||||
value = item.toString();
|
||||
} else {
|
||||
value = SQLEvalVisitorUtils.eval(dbType, item, parameters, false);
|
||||
if (value == SQLEvalVisitor.EVAL_VALUE_NULL) {
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
condition.getValues().add(value);
|
||||
|
||||
condition.addValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -716,6 +769,19 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
return new Column("UNKNOWN", column);
|
||||
}
|
||||
|
||||
if (expr instanceof SQLMethodInvokeExpr) {
|
||||
SQLMethodInvokeExpr methodInvokeExpr = (SQLMethodInvokeExpr) expr;
|
||||
List<SQLExpr> arguments = methodInvokeExpr.getParameters();
|
||||
long nameHash = methodInvokeExpr.methodNameHashCode64();
|
||||
if (nameHash == FnvHash.Constants.DATE_FORMAT) {
|
||||
if (arguments.size() == 2
|
||||
&& arguments.get(0) instanceof SQLName
|
||||
&& arguments.get(1) instanceof SQLCharExpr) {
|
||||
return getColumn(arguments.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -905,6 +971,10 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
public boolean visit(SQLSelectQueryBlock x) {
|
||||
if (x.getFrom() == null) {
|
||||
for (SQLSelectItem selectItem : x.getSelectList()) {
|
||||
statExpr(
|
||||
selectItem.getExpr());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1110,11 +1180,10 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
}
|
||||
} else if (tableSource instanceof SQLWithSubqueryClause.Entry
|
||||
|| tableSource instanceof SQLSubqueryTableSource) {
|
||||
return false;
|
||||
} else if (tableSource instanceof SQLUnionQueryTableSource) {
|
||||
return false;
|
||||
} else if (tableSource instanceof SQLLateralViewTableSource) {
|
||||
|| tableSource instanceof SQLSubqueryTableSource
|
||||
|| tableSource instanceof SQLUnionQueryTableSource
|
||||
|| tableSource instanceof SQLLateralViewTableSource
|
||||
|| tableSource instanceof SQLValuesTableSource) {
|
||||
return false;
|
||||
} else {
|
||||
if (x.getResolvedProcudure() != null) {
|
||||
@@ -1245,6 +1314,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
} else if (tableSource instanceof SQLWithSubqueryClause.Entry
|
||||
|| tableSource instanceof SQLSubqueryTableSource
|
||||
|| tableSource instanceof SQLValuesTableSource
|
||||
|| tableSource instanceof SQLLateralViewTableSource) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -1359,43 +1429,61 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
public boolean visit(SQLAllColumnExpr x) {
|
||||
SQLTableSource tableSource = x.getResolvedTableSource();
|
||||
if (tableSource == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
statAllColumn(x, tableSource);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void statAllColumn(SQLAllColumnExpr x, SQLTableSource tableSource) {
|
||||
if (tableSource instanceof SQLExprTableSource) {
|
||||
SQLExprTableSource exprTableSource = (SQLExprTableSource) tableSource;
|
||||
SQLName expr = exprTableSource.getName();
|
||||
statAllColumn(x, (SQLExprTableSource) tableSource);
|
||||
return;
|
||||
}
|
||||
|
||||
SQLCreateTableStatement createStmt = null;
|
||||
if (tableSource instanceof SQLJoinTableSource) {
|
||||
SQLJoinTableSource join = (SQLJoinTableSource) tableSource;
|
||||
statAllColumn(x, join.getLeft());
|
||||
statAllColumn(x, join.getRight());
|
||||
}
|
||||
}
|
||||
|
||||
SchemaObject tableObject = exprTableSource.getSchemaObject();
|
||||
if (tableObject != null) {
|
||||
SQLStatement stmt = tableObject.getStatement();
|
||||
if (stmt instanceof SQLCreateTableStatement) {
|
||||
createStmt = (SQLCreateTableStatement) stmt;
|
||||
}
|
||||
}
|
||||
private void statAllColumn(SQLAllColumnExpr x, SQLExprTableSource tableSource) {
|
||||
SQLExprTableSource exprTableSource = tableSource;
|
||||
SQLName expr = exprTableSource.getName();
|
||||
|
||||
if (createStmt != null
|
||||
&& createStmt.getTableElementList().size() > 0) {
|
||||
SQLName tableName = createStmt.getName();
|
||||
for (SQLTableElement e : createStmt.getTableElementList()) {
|
||||
if (e instanceof SQLColumnDefinition) {
|
||||
SQLColumnDefinition columnDefinition = (SQLColumnDefinition) e;
|
||||
SQLName columnName = columnDefinition.getName();
|
||||
Column column = addColumn(tableName.toString(), columnName.toString());
|
||||
if (isParentSelectItem(x.getParent())) {
|
||||
column.setSelec(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (expr != null) {
|
||||
Column column = addColumn(expr.toString(), "*");
|
||||
if (isParentSelectItem(x.getParent())) {
|
||||
column.setSelec(true);
|
||||
}
|
||||
SQLCreateTableStatement createStmt = null;
|
||||
|
||||
SchemaObject tableObject = exprTableSource.getSchemaObject();
|
||||
if (tableObject != null) {
|
||||
SQLStatement stmt = tableObject.getStatement();
|
||||
if (stmt instanceof SQLCreateTableStatement) {
|
||||
createStmt = (SQLCreateTableStatement) stmt;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
if (createStmt != null
|
||||
&& createStmt.getTableElementList().size() > 0) {
|
||||
SQLName tableName = createStmt.getName();
|
||||
for (SQLTableElement e : createStmt.getTableElementList()) {
|
||||
if (e instanceof SQLColumnDefinition) {
|
||||
SQLColumnDefinition columnDefinition = (SQLColumnDefinition) e;
|
||||
SQLName columnName = columnDefinition.getName();
|
||||
Column column = addColumn(tableName.toString(), columnName.toString());
|
||||
if (isParentSelectItem(x.getParent())) {
|
||||
column.setSelec(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (expr != null) {
|
||||
Column column = addColumn(expr.toString(), "*");
|
||||
if (isParentSelectItem(x.getParent())) {
|
||||
column.setSelec(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<TableStat.Name, TableStat> getTables() {
|
||||
@@ -1729,13 +1817,6 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void endVisit(SQLDeleteStatement x) {
|
||||
|
||||
}
|
||||
|
||||
public void endVisit(SQLUpdateStatement x) {
|
||||
}
|
||||
|
||||
public boolean visit(SQLCreateTableStatement x) {
|
||||
if (repository != null
|
||||
&& x.getParent() == null) {
|
||||
@@ -2416,4 +2497,41 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
public boolean visit(SQLDropTypeStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLExternalRecordFormat x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLCreateDatabaseStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableExchangePartition x) {
|
||||
SQLExprTableSource table = x.getTable();
|
||||
if (table != null) {
|
||||
table.accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLDumpStatement x) {
|
||||
if (repository != null
|
||||
&& x.getParent() == null) {
|
||||
repository.resolve(x);
|
||||
}
|
||||
|
||||
final SQLExprTableSource into = x.getInto();
|
||||
if (into != null) {
|
||||
into.accept(this);
|
||||
}
|
||||
|
||||
final SQLSelect select = x.getSelect();
|
||||
if (select != null) {
|
||||
select.accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,13 @@ public enum VisitorFeature {
|
||||
OutputUseInsertValueClauseOriginalString,
|
||||
OutputSkipSelectListCacheString,
|
||||
OutputSkipInsertColumnsString,
|
||||
OutputParameterizedQuesUnMergeInList,
|
||||
OutputParameterizedQuesUnMergeOr,
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
OutputKeepParenthesisWhenNotExpr
|
||||
;
|
||||
|
||||
private VisitorFeature(){
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
Reference in New Issue
Block a user