Search in sources :

Example 21 with ASTNode

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;
}
Also used : Hive(org.apache.hadoop.hive.ql.metadata.Hive) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 22 with ASTNode

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;
}
Also used : ArrayList(java.util.ArrayList) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) Privilege(org.apache.hadoop.hive.ql.security.authorization.Privilege) PrivilegeDesc(org.apache.hadoop.hive.ql.plan.PrivilegeDesc) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 23 with ASTNode

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());
}
Also used : ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) Test(org.junit.Test)

Example 24 with ASTNode

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());
}
Also used : ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) Test(org.junit.Test)

Example 25 with ASTNode

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;
}
Also used : ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode)

Aggregations

ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)49 ArrayList (java.util.ArrayList)8 ParseException (org.apache.hadoop.hive.ql.parse.ParseException)5 DDLWork (org.apache.hadoop.hive.ql.plan.DDLWork)5 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)5 WindowingException (com.sap.hadoop.windowing.WindowingException)4 InputInfo (com.sap.hadoop.windowing.query2.translate.QueryTranslationInfo.InputInfo)4 ParseDriver (org.apache.hadoop.hive.ql.parse.ParseDriver)4 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)4 PrincipalDesc (org.apache.hadoop.hive.ql.plan.PrincipalDesc)4 PrivilegeObjectDesc (org.apache.hadoop.hive.ql.plan.PrivilegeObjectDesc)4 BigDecimal (java.math.BigDecimal)3 RexNode (org.apache.calcite.rex.RexNode)3 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)3 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)3 BaseSemanticAnalyzer (org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer)3 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)3 ArgDef (com.sap.hadoop.windowing.query2.definition.ArgDef)2 QueryInputDef (com.sap.hadoop.windowing.query2.definition.QueryInputDef)2 IOException (java.io.IOException)2