Search in sources :

Example 46 with DDLWork

use of org.apache.hadoop.hive.ql.plan.DDLWork in project hive by apache.

the class TaskCompiler method patchUpAfterCTASorMaterializedView.

private void patchUpAfterCTASorMaterializedView(final List<Task<? extends Serializable>> rootTasks, final HashSet<WriteEntity> outputs, Task<? extends Serializable> createTask) {
    // clear the mapredWork output file from outputs for CTAS
    // DDLWork at the tail of the chain will have the output
    Iterator<WriteEntity> outIter = outputs.iterator();
    while (outIter.hasNext()) {
        switch(outIter.next().getType()) {
            case DFS_DIR:
            case LOCAL_DIR:
                outIter.remove();
                break;
            default:
                break;
        }
    }
    // find all leaf tasks and make the DDLTask as a dependent task on all of them
    HashSet<Task<? extends Serializable>> leaves = new LinkedHashSet<>();
    getLeafTasks(rootTasks, leaves);
    assert (leaves.size() > 0);
    Task<? extends Serializable> targetTask = createTask;
    for (Task<? extends Serializable> task : leaves) {
        if (task instanceof StatsTask) {
            // StatsTask require table to already exist
            for (Task<? extends Serializable> parentOfStatsTask : task.getParentTasks()) {
                parentOfStatsTask.addDependentTask(createTask);
            }
            for (Task<? extends Serializable> parentOfCrtTblTask : createTask.getParentTasks()) {
                parentOfCrtTblTask.removeDependentTask(task);
            }
            createTask.addDependentTask(task);
            targetTask = task;
        } else {
            task.addDependentTask(createTask);
        }
    }
    // Add task to insert / delete materialized view from registry if needed
    if (createTask instanceof DDLTask) {
        DDLTask ddlTask = (DDLTask) createTask;
        DDLWork work = ddlTask.getWork();
        String tableName = null;
        boolean retrieveAndInclude = false;
        boolean disableRewrite = false;
        if (work.getCreateViewDesc() != null && work.getCreateViewDesc().isMaterialized()) {
            tableName = work.getCreateViewDesc().getViewName();
            retrieveAndInclude = work.getCreateViewDesc().isRewriteEnabled();
        } else if (work.getAlterMaterializedViewDesc() != null) {
            tableName = work.getAlterMaterializedViewDesc().getMaterializedViewName();
            if (work.getAlterMaterializedViewDesc().isRewriteEnable()) {
                retrieveAndInclude = true;
            } else {
                disableRewrite = true;
            }
        } else {
            return;
        }
        targetTask.addDependentTask(TaskFactory.get(new MaterializedViewDesc(tableName, retrieveAndInclude, disableRewrite, false), conf));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FetchTask(org.apache.hadoop.hive.ql.exec.FetchTask) DDLTask(org.apache.hadoop.hive.ql.exec.DDLTask) Task(org.apache.hadoop.hive.ql.exec.Task) StatsTask(org.apache.hadoop.hive.ql.exec.StatsTask) Serializable(java.io.Serializable) MaterializedViewDesc(org.apache.hadoop.hive.ql.exec.MaterializedViewDesc) StatsTask(org.apache.hadoop.hive.ql.exec.StatsTask) DDLWork(org.apache.hadoop.hive.ql.plan.DDLWork) DDLTask(org.apache.hadoop.hive.ql.exec.DDLTask) WriteEntity(org.apache.hadoop.hive.ql.hooks.WriteEntity)

Example 47 with DDLWork

use of org.apache.hadoop.hive.ql.plan.DDLWork in project hive by apache.

the class HiveAuthorizationTaskFactoryImpl method createRevokeTask.

@Override
public Task<? extends Serializable> createRevokeTask(ASTNode ast, HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) throws SemanticException {
    List<PrivilegeDesc> privilegeDesc = analyzePrivilegeListDef((ASTNode) ast.getChild(0));
    List<PrincipalDesc> principalDesc = AuthorizationParseUtils.analyzePrincipalListDef((ASTNode) ast.getChild(1));
    PrivilegeObjectDesc hiveObj = null;
    boolean grantOption = false;
    if (ast.getChildCount() > 2) {
        ASTNode astChild = (ASTNode) ast.getChild(2);
        hiveObj = analyzePrivilegeObject(astChild, outputs);
        if (null != ast.getFirstChildWithType(HiveParser.TOK_GRANT_OPTION_FOR)) {
            grantOption = true;
        }
    }
    RevokeDesc revokeDesc = new RevokeDesc(privilegeDesc, principalDesc, hiveObj, grantOption);
    return TaskFactory.get(new DDLWork(inputs, outputs, revokeDesc));
}
Also used : PrincipalDesc(org.apache.hadoop.hive.ql.plan.PrincipalDesc) DDLWork(org.apache.hadoop.hive.ql.plan.DDLWork) PrivilegeObjectDesc(org.apache.hadoop.hive.ql.plan.PrivilegeObjectDesc) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) RevokeDesc(org.apache.hadoop.hive.ql.plan.RevokeDesc) PrivilegeDesc(org.apache.hadoop.hive.ql.plan.PrivilegeDesc)

Example 48 with DDLWork

use of org.apache.hadoop.hive.ql.plan.DDLWork in project hive by apache.

the class HiveAuthorizationTaskFactoryImpl method createShowRolesTask.

@Override
public Task<? extends Serializable> createShowRolesTask(ASTNode ast, Path resFile, HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) throws SemanticException {
    RoleDDLDesc showRolesDesc = new RoleDDLDesc(null, null, RoleDDLDesc.RoleOperation.SHOW_ROLES, null);
    showRolesDesc.setResFile(resFile.toString());
    return TaskFactory.get(new DDLWork(inputs, outputs, showRolesDesc));
}
Also used : DDLWork(org.apache.hadoop.hive.ql.plan.DDLWork) RoleDDLDesc(org.apache.hadoop.hive.ql.plan.RoleDDLDesc)

Example 49 with DDLWork

use of org.apache.hadoop.hive.ql.plan.DDLWork in project hive by apache.

the class HiveAuthorizationTaskFactoryImpl method createShowCurrentRoleTask.

@Override
public Task<? extends Serializable> createShowCurrentRoleTask(HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs, Path resFile) throws SemanticException {
    RoleDDLDesc ddlDesc = new RoleDDLDesc(null, RoleDDLDesc.RoleOperation.SHOW_CURRENT_ROLE);
    ddlDesc.setResFile(resFile.toString());
    return TaskFactory.get(new DDLWork(inputs, outputs, ddlDesc));
}
Also used : DDLWork(org.apache.hadoop.hive.ql.plan.DDLWork) RoleDDLDesc(org.apache.hadoop.hive.ql.plan.RoleDDLDesc)

Example 50 with DDLWork

use of org.apache.hadoop.hive.ql.plan.DDLWork in project hive by apache.

the class HiveAuthorizationTaskFactoryImpl method createShowGrantTask.

@Override
public Task<? extends Serializable> createShowGrantTask(ASTNode ast, Path resultFile, HashSet<ReadEntity> inputs, HashSet<WriteEntity> outputs) throws SemanticException {
    PrincipalDesc principalDesc = null;
    PrivilegeObjectDesc privHiveObj = null;
    ASTNode param = null;
    if (ast.getChildCount() > 0) {
        param = (ASTNode) ast.getChild(0);
        principalDesc = AuthorizationParseUtils.getPrincipalDesc(param);
        if (principalDesc != null) {
            // shift one
            param = (ASTNode) ast.getChild(1);
        }
    }
    if (param != null) {
        if (param.getType() == HiveParser.TOK_RESOURCE_ALL) {
            privHiveObj = new PrivilegeObjectDesc();
        } else if (param.getType() == HiveParser.TOK_PRIV_OBJECT_COL) {
            privHiveObj = parsePrivObject(param);
        }
    }
    ShowGrantDesc showGrant = new ShowGrantDesc(resultFile.toString(), principalDesc, privHiveObj);
    return TaskFactory.get(new DDLWork(inputs, outputs, showGrant));
}
Also used : PrincipalDesc(org.apache.hadoop.hive.ql.plan.PrincipalDesc) DDLWork(org.apache.hadoop.hive.ql.plan.DDLWork) PrivilegeObjectDesc(org.apache.hadoop.hive.ql.plan.PrivilegeObjectDesc) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) ShowGrantDesc(org.apache.hadoop.hive.ql.plan.ShowGrantDesc)

Aggregations

DDLWork (org.apache.hadoop.hive.ql.plan.DDLWork)141 AlterTableDesc (org.apache.hadoop.hive.ql.plan.AlterTableDesc)26 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)24 ReadEntity (org.apache.hadoop.hive.ql.hooks.ReadEntity)24 Table (org.apache.hadoop.hive.ql.metadata.Table)22 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)20 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)20 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)20 PrincipalDesc (org.apache.hadoop.hive.ql.plan.PrincipalDesc)20 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)19 DefaultConstraint (org.apache.hadoop.hive.ql.metadata.DefaultConstraint)19 NotNullConstraint (org.apache.hadoop.hive.ql.metadata.NotNullConstraint)19 HashMap (java.util.HashMap)17 LinkedHashMap (java.util.LinkedHashMap)16 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)14 Task (org.apache.hadoop.hive.ql.exec.Task)11 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)11 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)10 Serializable (java.io.Serializable)9