mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
support hive add jar statement
This commit is contained in:
+3
-1
@@ -1 +1,3 @@
|
||||
/target
|
||||
/target
|
||||
/src/test/java/com/alibaba/druid/bvt/inc/
|
||||
/src/test/resources/bvt/inc/
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.alibaba.druid.sql.dialect.hive.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.hive.visitor.HiveASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class HiveAddJarStatement extends SQLStatementImpl {
|
||||
private String path;
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor instanceof HiveASTVisitor) {
|
||||
accept0((HiveASTVisitor) visitor);
|
||||
}
|
||||
}
|
||||
|
||||
protected void accept0(HiveASTVisitor v) {
|
||||
v.visit(this);
|
||||
v.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import com.alibaba.druid.DbType;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.hive.ast.HiveAddJarStatement;
|
||||
import com.alibaba.druid.sql.dialect.hive.ast.HiveInsert;
|
||||
import com.alibaba.druid.sql.dialect.hive.ast.HiveMultiInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.hive.stmt.HiveLoadDataStatement;
|
||||
@@ -186,6 +187,14 @@ public class HiveStatementParser extends SQLStatementParser {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.ADD)) {
|
||||
SQLStatement stmt = parseAdd();
|
||||
if (stmt != null) {
|
||||
statementList.add(stmt);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("MSCK")) {
|
||||
SQLStatement stmt = parseMsck();
|
||||
statementList.add(stmt);
|
||||
@@ -475,6 +484,23 @@ public class HiveStatementParser extends SQLStatementParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
protected SQLStatement parseAdd() {
|
||||
Lexer.SavePoint mark = lexer.mark();
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.identifierEquals("JAR")) {
|
||||
lexer.nextPath();
|
||||
String path = lexer.stringVal();
|
||||
HiveAddJarStatement stmt = new HiveAddJarStatement();
|
||||
stmt.setPath(path);
|
||||
lexer.nextToken();
|
||||
return stmt;
|
||||
}
|
||||
|
||||
lexer.reset(mark);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected SQLStatement parseImport() {
|
||||
lexer.nextToken();
|
||||
SQLImportTableStatement stmt = new SQLImportTableStatement();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.hive.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.hive.ast.HiveAddJarStatement;
|
||||
import com.alibaba.druid.sql.dialect.hive.ast.HiveInsert;
|
||||
import com.alibaba.druid.sql.dialect.hive.ast.HiveInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.hive.ast.HiveMultiInsertStatement;
|
||||
@@ -66,4 +67,10 @@ public interface HiveASTVisitor extends SQLASTVisitor {
|
||||
default void endVisit(HiveMsckRepairStatement x) {
|
||||
}
|
||||
|
||||
default boolean visit(HiveAddJarStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void endVisit(HiveAddJarStatement x) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.hive.ast.HiveAddJarStatement;
|
||||
import com.alibaba.druid.sql.dialect.hive.ast.HiveInsert;
|
||||
import com.alibaba.druid.sql.dialect.hive.ast.HiveInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.hive.ast.HiveMultiInsertStatement;
|
||||
@@ -491,4 +492,10 @@ public class HiveOutputVisitor extends SQLASTOutputVisitor implements HiveASTVis
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(HiveAddJarStatement x) {
|
||||
print0(ucase ? "ADD JAR " : "add jar ");
|
||||
print0(x.getPath());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1132,7 +1132,7 @@ public class Lexer {
|
||||
}
|
||||
stringVal = null;
|
||||
mark = pos;
|
||||
while (!isWhitespace(ch)) {
|
||||
while (!isWhitespace(ch) && ch != ';') {
|
||||
ch = charAt(++pos);
|
||||
}
|
||||
bufPos = pos - mark;
|
||||
|
||||
@@ -724,6 +724,13 @@ public class SQLParserUtils {
|
||||
start = lexer.startPos + lexer.stringVal().length();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("ADD")) {
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals("JAR")) {
|
||||
lexer.nextPath();
|
||||
}
|
||||
}
|
||||
|
||||
lexer.nextToken();
|
||||
token = lexer.token;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user