use of org.apache.hadoop.hive.ql.parse.ASTNode in project hive by apache.
the class CreateDatabaseHook method preAnalyze.
@Override
public ASTNode preAnalyze(HiveSemanticAnalyzerHookContext context, ASTNode ast) throws SemanticException {
Hive db;
try {
db = context.getHive();
} catch (HiveException e) {
throw new SemanticException("Couldn't get Hive DB instance in semantic analysis phase.", e);
}
// Analyze and create tbl properties object
int numCh = ast.getChildCount();
databaseName = BaseSemanticAnalyzer.getUnescapedName((ASTNode) ast.getChild(0));
for (int num = 1; num < numCh; num++) {
ASTNode child = (ASTNode) ast.getChild(num);
switch(child.getToken().getType()) {
case HiveParser.TOK_IFNOTEXISTS:
try {
List<String> dbs = db.getDatabasesByPattern(databaseName);
if (dbs != null && dbs.size() > 0) {
// db exists
return ast;
}
} catch (HiveException e) {
throw new SemanticException(e);
}
break;
}
}
return ast;
}
use of org.apache.hadoop.hive.ql.parse.ASTNode in project hive by apache.
the class HiveAuthorizationTaskFactoryImpl method analyzePrivilegeListDef.
private List<PrivilegeDesc> analyzePrivilegeListDef(ASTNode node) throws SemanticException {
List<PrivilegeDesc> ret = new ArrayList<PrivilegeDesc>();
for (int i = 0; i < node.getChildCount(); i++) {
ASTNode privilegeDef = (ASTNode) node.getChild(i);
ASTNode privilegeType = (ASTNode) privilegeDef.getChild(0);
Privilege privObj = PrivilegeRegistry.getPrivilege(privilegeType.getType());
if (privObj == null) {
throw new SemanticException("Undefined privilege " + PrivilegeType.getPrivTypeByToken(privilegeType.getType()));
}
List<String> cols = null;
if (privilegeDef.getChildCount() > 1) {
cols = BaseSemanticAnalyzer.getColumnNames((ASTNode) privilegeDef.getChild(1));
}
PrivilegeDesc privilegeDesc = new PrivilegeDesc(privObj, cols);
ret.add(privilegeDesc);
}
return ret;
}
use of org.apache.hadoop.hive.ql.parse.ASTNode in project hive by apache.
the class TestTransactionStatement method testAutoCommit.
@Test
public void testAutoCommit() throws ParseException {
ASTNode ast = parse("SET AUTOCOMMIT TRUE");
Assert.assertEquals("AST doesn't match", "(tok_set_autocommit tok_true)", ast.toStringTree());
ast = parse("SET AUTOCOMMIT FALSE");
Assert.assertEquals("AST doesn't match", "(tok_set_autocommit tok_false)", ast.toStringTree());
}
use of org.apache.hadoop.hive.ql.parse.ASTNode in project hive by apache.
the class TestTransactionStatement method testTxnCommitRollback.
@Test
public void testTxnCommitRollback() throws ParseException {
ASTNode ast = parse("COMMIT");
Assert.assertEquals("AST doesn't match", "tok_commit", ast.toStringTree());
ast = parse("COMMIT WORK");
Assert.assertEquals("AST doesn't match", "tok_commit", ast.toStringTree());
ast = parse("ROLLBACK");
Assert.assertEquals("AST doesn't match", "tok_rollback", ast.toStringTree());
ast = parse("ROLLBACK WORK");
Assert.assertEquals("AST doesn't match", "tok_rollback", ast.toStringTree());
}
use of org.apache.hadoop.hive.ql.parse.ASTNode in project hive by apache.
the class ASTConverter method buildUDTFAST.
private ASTNode buildUDTFAST(String functionName, List<ASTNode> children) {
ASTNode node = (ASTNode) ParseDriver.adaptor.create(HiveParser.TOK_FUNCTION, "TOK_FUNCTION");
node.addChild((ASTNode) ParseDriver.adaptor.create(HiveParser.Identifier, functionName));
for (ASTNode c : children) {
ParseDriver.adaptor.addChild(node, c);
}
return node;
}
Aggregations