Search in sources :

Example 1 with AlterMaterializedViewDesc

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

the class DDLSemanticAnalyzer method analyzeAlterMaterializedViewRewrite.

private void analyzeAlterMaterializedViewRewrite(String mvName, ASTNode ast) throws SemanticException {
    // Value for the flag
    boolean enableFlag;
    switch(ast.getChild(0).getType()) {
        case HiveParser.TOK_REWRITE_ENABLED:
            enableFlag = true;
            break;
        case HiveParser.TOK_REWRITE_DISABLED:
            enableFlag = false;
            break;
        default:
            throw new SemanticException("Invalid alter materialized view expression");
    }
    AlterMaterializedViewDesc alterMVDesc = new AlterMaterializedViewDesc(AlterMaterializedViewTypes.UPDATE_REWRITE_FLAG);
    alterMVDesc.setMaterializedViewName(mvName);
    alterMVDesc.setRewriteEnableFlag(enableFlag);
    // It can be fully qualified name or use default database
    Table materializedViewTable = getTable(mvName, true);
    // only uses transactional (MM and ACID) tables
    if (enableFlag) {
        for (String tableName : materializedViewTable.getCreationMetadata().getTablesUsed()) {
            Table table = getTable(tableName, true);
            if (!AcidUtils.isTransactionalTable(table)) {
                throw new SemanticException("Automatic rewriting for materialized view cannot " + "be enabled if the materialized view uses non-transactional tables");
            }
        }
    }
    inputs.add(new ReadEntity(materializedViewTable));
    outputs.add(new WriteEntity(materializedViewTable, WriteEntity.WriteType.DDL_EXCLUSIVE));
    rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), alterMVDesc)));
}
Also used : ReadEntity(org.apache.hadoop.hive.ql.hooks.ReadEntity) Table(org.apache.hadoop.hive.ql.metadata.Table) DDLWork(org.apache.hadoop.hive.ql.plan.DDLWork) WriteEntity(org.apache.hadoop.hive.ql.hooks.WriteEntity) AlterMaterializedViewDesc(org.apache.hadoop.hive.ql.plan.AlterMaterializedViewDesc)

Aggregations

ReadEntity (org.apache.hadoop.hive.ql.hooks.ReadEntity)1 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)1 Table (org.apache.hadoop.hive.ql.metadata.Table)1 AlterMaterializedViewDesc (org.apache.hadoop.hive.ql.plan.AlterMaterializedViewDesc)1 DDLWork (org.apache.hadoop.hive.ql.plan.DDLWork)1