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:
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.2.7_preview_04</version>
|
||||
<version>1.2.7_preview_05</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>druid</name>
|
||||
<description>A JDBC datasource implementation.</description>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.alibaba.druid.bvt.sql.hive;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HiveSelectTest_48 extends TestCase {
|
||||
|
||||
|
||||
public void test_select() throws Exception {
|
||||
String sql = "SELECT account_id FROM taobao_office.cloud_yunpan WHERE dt='2021-04-12' AND target='update'";
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, JdbcConstants.HIVE);
|
||||
SQLStatement sqlStatement = stmtList.get(0);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) sqlStatement;
|
||||
List<SQLSelectItem> list = ((SQLSelectQueryBlock) stmt.getSelect().getQuery()).getSelectList();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user