mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved hive parser support.
This commit is contained in:
@@ -216,6 +216,26 @@ public class HiveCreateTableParser extends SQLCreateTableParser {
|
||||
stmt.setStoredAs(name);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.TBLPROPERTIES)) {
|
||||
lexer.nextToken();
|
||||
accept(Token.LPAREN);
|
||||
|
||||
for (;;) {
|
||||
String name = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
accept(Token.EQ);
|
||||
SQLExpr value = this.exprParser.primary();
|
||||
stmt.getTableOptions().put(name, value);
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.AS) {
|
||||
lexer.nextToken();
|
||||
SQLSelect select = this.createSQLSelectParser().select();
|
||||
|
||||
@@ -17,11 +17,13 @@ package com.alibaba.druid.sql.dialect.hive.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.hive.stmt.HiveCreateTableStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HiveOutputVisitor extends SQLASTOutputVisitor implements HiveASTVisitor {
|
||||
public HiveOutputVisitor(Appendable appender) {
|
||||
@@ -142,6 +144,20 @@ public class HiveOutputVisitor extends SQLASTOutputVisitor implements HiveASTVis
|
||||
printExpr(storedAs);
|
||||
}
|
||||
|
||||
Map<String, SQLObject> tableOptions = x.getTableOptions();
|
||||
if (tableOptions.size() > 0) {
|
||||
println();
|
||||
print0(ucase ? "TBLPROPERTIES (" : "tblproperties (");
|
||||
int i = 0;
|
||||
for (Map.Entry<String, SQLObject> option : tableOptions.entrySet()) {
|
||||
print0(option.getKey());
|
||||
print0(" = ");
|
||||
option.getValue().accept(this);
|
||||
++i;
|
||||
}
|
||||
print(')');
|
||||
}
|
||||
|
||||
SQLSelect select = x.getSelect();
|
||||
if (printSelect && select != null) {
|
||||
println();
|
||||
|
||||
@@ -2437,4 +2437,8 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
public boolean visit(SQLExternalRecordFormat x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLCreateDatabaseStatement x) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,5 +630,7 @@ public final class FnvHash {
|
||||
long NOCACHE = fnv1a_64_lower("NOCACHE");
|
||||
long NOPARALLEL = fnv1a_64_lower("NOPARALLEL");
|
||||
long EXIST = fnv1a_64_lower("EXIST");
|
||||
|
||||
long TBLPROPERTIES = fnv1a_64_lower("TBLPROPERTIES");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user