mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved odps parser
This commit is contained in:
@@ -157,13 +157,6 @@ public class HiveOutputVisitor extends SQLASTOutputVisitor implements HiveASTVis
|
||||
}
|
||||
x.getTableSource().accept(this);
|
||||
|
||||
List<SQLExpr> columns = x.getColumns();
|
||||
if (columns.size() > 0) {
|
||||
print('(');
|
||||
printAndAccept(columns, ", ");
|
||||
print(')');
|
||||
}
|
||||
|
||||
List<SQLAssignItem> partitions = x.getPartitions();
|
||||
int partitionSize = partitions.size();
|
||||
if (partitionSize > 0) {
|
||||
@@ -183,6 +176,14 @@ public class HiveOutputVisitor extends SQLASTOutputVisitor implements HiveASTVis
|
||||
}
|
||||
print(')');
|
||||
}
|
||||
|
||||
List<SQLExpr> columns = x.getColumns();
|
||||
if (columns.size() > 0) {
|
||||
print(" (");
|
||||
printAndAccept(columns, ", ");
|
||||
print(')');
|
||||
}
|
||||
|
||||
if (x.isIfNotExists()) {
|
||||
print0(ucase ? " IF NOT EXISTS" : " if not exists");
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ public interface SchemaResolveVisitor extends SQLASTVisitor {
|
||||
static class Context {
|
||||
public final Context parent;
|
||||
public final SQLObject object;
|
||||
public final int level;
|
||||
|
||||
private SQLTableSource tableSource;
|
||||
|
||||
@@ -85,6 +86,9 @@ public interface SchemaResolveVisitor extends SQLASTVisitor {
|
||||
public Context(SQLObject object, Context parent) {
|
||||
this.object = object;
|
||||
this.parent = parent;
|
||||
this.level = parent == null
|
||||
? 0
|
||||
: parent.level + 1;
|
||||
}
|
||||
|
||||
public SQLTableSource getFrom() {
|
||||
|
||||
@@ -1396,6 +1396,9 @@ class SchemaResolveVisitorFactory {
|
||||
|
||||
static void resolve(SchemaResolveVisitor visitor, SQLSelectQueryBlock x) {
|
||||
SchemaResolveVisitor.Context ctx = visitor.createContext(x);
|
||||
if (ctx != null && ctx.level >= 32) {
|
||||
return;
|
||||
}
|
||||
|
||||
SQLTableSource from = x.getFrom();
|
||||
|
||||
|
||||
@@ -27,13 +27,18 @@ import java.util.Map;
|
||||
|
||||
public class ExportTables extends UDF {
|
||||
|
||||
public String evaluate(String sql) {
|
||||
return evaluate(sql, null);
|
||||
public String evaluate(String sql) throws Throwable {
|
||||
return evaluate(sql, null, false);
|
||||
}
|
||||
|
||||
public String evaluate(String sql, String dbTypeName) {
|
||||
public String evaluate(String sql, String dbTypeName) throws Throwable {
|
||||
return evaluate(sql, dbTypeName, false);
|
||||
}
|
||||
|
||||
public String evaluate(String sql, String dbTypeName, boolean throwError) throws Throwable {
|
||||
DbType dbType = dbTypeName == null ? null : DbType.valueOf(dbTypeName);
|
||||
|
||||
Throwable error = null;
|
||||
try {
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, dbType);
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType);
|
||||
@@ -54,8 +59,16 @@ public class ExportTables extends UDF {
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
} catch (Exception ignored) {
|
||||
// skip
|
||||
} catch (StackOverflowError ignored) {
|
||||
// skip
|
||||
}
|
||||
|
||||
if (throwError && error != null) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user