Search in sources :

Example 1 with AlterTableDropPartitionDesc

use of org.apache.hadoop.hive.ql.ddl.table.partition.drop.AlterTableDropPartitionDesc in project hive by apache.

the class HCatSemanticAnalyzer method authorizeDDLWork.

@Override
protected void authorizeDDLWork(HiveSemanticAnalyzerHookContext cntxt, Hive hive, DDLWork work) throws HiveException {
    DDLDesc ddlDesc = work.getDDLDesc();
    if (ddlDesc instanceof ShowDatabasesDesc) {
        authorize(HiveOperation.SHOWDATABASES.getInputRequiredPrivileges(), HiveOperation.SHOWDATABASES.getOutputRequiredPrivileges());
    } else if (ddlDesc instanceof DropDatabaseDesc) {
        DropDatabaseDesc dropDb = (DropDatabaseDesc) ddlDesc;
        Database db = cntxt.getHive().getDatabase(dropDb.getDatabaseName());
        if (db != null) {
            // if above returned a null, then the db does not exist - probably a
            // "drop database if exists" clause - don't try to authorize then.
            authorize(db, Privilege.DROP);
        }
    } else if (ddlDesc instanceof DescDatabaseDesc) {
        DescDatabaseDesc descDb = (DescDatabaseDesc) ddlDesc;
        Database db = cntxt.getHive().getDatabase(descDb.getDatabaseName());
        authorize(db, Privilege.SELECT);
    } else if (ddlDesc instanceof SwitchDatabaseDesc) {
        SwitchDatabaseDesc switchDb = (SwitchDatabaseDesc) ddlDesc;
        Database db = cntxt.getHive().getDatabase(switchDb.getDatabaseName());
        authorize(db, Privilege.SELECT);
    } else if (ddlDesc instanceof ShowTablesDesc) {
        ShowTablesDesc showTables = (ShowTablesDesc) ddlDesc;
        String dbName = showTables.getDbName() == null ? SessionState.get().getCurrentDatabase() : showTables.getDbName();
        authorize(cntxt.getHive().getDatabase(dbName), Privilege.SELECT);
    } else if (ddlDesc instanceof DescTableDesc) {
        // we should be careful when authorizing table based on just the
        // table name. If columns have separate authorization domain, it
        // must be honored
        DescTableDesc descTable = (DescTableDesc) ddlDesc;
        String tableName = extractTableName(descTable.getDbTableName());
        authorizeTable(cntxt.getHive(), tableName, Privilege.SELECT);
    } else if (ddlDesc instanceof ShowTableStatusDesc) {
        ShowTableStatusDesc showTableStatus = (ShowTableStatusDesc) ddlDesc;
        String dbName = showTableStatus.getDbName() == null ? SessionState.get().getCurrentDatabase() : showTableStatus.getDbName();
        authorize(cntxt.getHive().getDatabase(dbName), Privilege.SELECT);
    } else if (ddlDesc instanceof AlterTableDropPartitionDesc) {
        AlterTableDropPartitionDesc dropPartition = (AlterTableDropPartitionDesc) ddlDesc;
        // this is actually a ALTER TABLE DROP PARITITION statement
        for (AlterTableDropPartitionDesc.PartitionDesc partSpec : dropPartition.getPartSpecs()) {
            // partitions are not added as write entries in drop partitions in Hive
            Table table = hive.getTable(SessionState.get().getCurrentDatabase(), dropPartition.getTableName());
            List<Partition> partitions = null;
            try {
                partitions = hive.getPartitionsByFilter(table, partSpec.getPartSpec().getExprString());
            } catch (Exception e) {
                throw new HiveException(e);
            }
            for (Partition part : partitions) {
                authorize(part, Privilege.DROP);
            }
        }
    } else if (ddlDesc instanceof ShowPartitionsDesc) {
        ShowPartitionsDesc showParts = (ShowPartitionsDesc) ddlDesc;
        String tableName = extractTableName(showParts.getTabName());
        authorizeTable(cntxt.getHive(), tableName, Privilege.SELECT);
    } else if (ddlDesc instanceof AlterTableSetLocationDesc) {
        AlterTableSetLocationDesc alterTable = (AlterTableSetLocationDesc) ddlDesc;
        Table table = hive.getTable(SessionState.get().getCurrentDatabase(), Utilities.getDbTableName(alterTable.getDbTableName())[1], false);
        Partition part = null;
        if (alterTable.getPartitionSpec() != null) {
            part = hive.getPartition(table, alterTable.getPartitionSpec(), false);
        }
        String newLocation = alterTable.getLocation();
        /* Hcat requires ALTER_DATA privileges for ALTER TABLE LOCATION statements
      * for the old table/partition location and the new location.
      */
        if (part != null) {
            // authorize for the old
            authorize(part, Privilege.ALTER_DATA);
            // location, and new location
            part.setLocation(newLocation);
            authorize(part, Privilege.ALTER_DATA);
        } else {
            // authorize for the old
            authorize(table, Privilege.ALTER_DATA);
            // location, and new location
            table.getTTable().getSd().setLocation(newLocation);
            authorize(table, Privilege.ALTER_DATA);
        }
    }
}
Also used : DropDatabaseDesc(org.apache.hadoop.hive.ql.ddl.database.drop.DropDatabaseDesc) AlterTableDropPartitionDesc(org.apache.hadoop.hive.ql.ddl.table.partition.drop.AlterTableDropPartitionDesc) Partition(org.apache.hadoop.hive.ql.metadata.Partition) Table(org.apache.hadoop.hive.ql.metadata.Table) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) DescTableDesc(org.apache.hadoop.hive.ql.ddl.table.info.desc.DescTableDesc) SwitchDatabaseDesc(org.apache.hadoop.hive.ql.ddl.database.use.SwitchDatabaseDesc) ShowDatabasesDesc(org.apache.hadoop.hive.ql.ddl.database.show.ShowDatabasesDesc) HCatException(org.apache.hive.hcatalog.common.HCatException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) ShowPartitionsDesc(org.apache.hadoop.hive.ql.ddl.table.partition.show.ShowPartitionsDesc) ShowTablesDesc(org.apache.hadoop.hive.ql.ddl.table.info.show.tables.ShowTablesDesc) ShowTableStatusDesc(org.apache.hadoop.hive.ql.ddl.table.info.show.status.ShowTableStatusDesc) Database(org.apache.hadoop.hive.metastore.api.Database) AlterTableDropPartitionDesc(org.apache.hadoop.hive.ql.ddl.table.partition.drop.AlterTableDropPartitionDesc) List(java.util.List) AlterTableSetLocationDesc(org.apache.hadoop.hive.ql.ddl.table.storage.set.location.AlterTableSetLocationDesc) DescDatabaseDesc(org.apache.hadoop.hive.ql.ddl.database.desc.DescDatabaseDesc) DDLDesc(org.apache.hadoop.hive.ql.ddl.DDLDesc)

Example 2 with AlterTableDropPartitionDesc

use of org.apache.hadoop.hive.ql.ddl.table.partition.drop.AlterTableDropPartitionDesc in project hive by apache.

the class LoadPartitions method dropPartitionTask.

private Task<?> dropPartitionTask(Table table, Map<String, String> partSpec) throws SemanticException {
    Task<DDLWork> dropPtnTask = null;
    Map<Integer, List<ExprNodeGenericFuncDesc>> partSpecsExpr = ReplUtils.genPartSpecs(table, Collections.singletonList(partSpec));
    if (partSpecsExpr.size() > 0) {
        AlterTableDropPartitionDesc dropPtnDesc = new AlterTableDropPartitionDesc(HiveTableName.of(table), partSpecsExpr, true, event.replicationSpec());
        dropPtnTask = TaskFactory.get(new DDLWork(new HashSet<>(), new HashSet<>(), dropPtnDesc, true, (new Path(context.dumpDirectory)).getParent().toString(), this.metricCollector), context.hiveConf);
    }
    return dropPtnTask;
}
Also used : AlterTableDropPartitionDesc(org.apache.hadoop.hive.ql.ddl.table.partition.drop.AlterTableDropPartitionDesc) Path(org.apache.hadoop.fs.Path) DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) LinkedList(java.util.LinkedList) List(java.util.List)

Example 3 with AlterTableDropPartitionDesc

use of org.apache.hadoop.hive.ql.ddl.table.partition.drop.AlterTableDropPartitionDesc in project hive by apache.

the class DropPartitionHandler method handle.

@Override
public List<Task<?>> handle(Context context) throws SemanticException {
    try {
        DropPartitionMessage msg = deserializer.getDropPartitionMessage(context.dmd.getPayload());
        String actualDbName = context.isDbNameEmpty() ? msg.getDB() : context.dbName;
        String actualTblName = msg.getTable();
        Map<Integer, List<ExprNodeGenericFuncDesc>> partSpecs = ReplUtils.genPartSpecs(new Table(msg.getTableObj()), msg.getPartitions());
        if (partSpecs.size() > 0) {
            AlterTableDropPartitionDesc dropPtnDesc = new AlterTableDropPartitionDesc(HiveTableName.ofNullable(actualTblName, actualDbName), partSpecs, true, context.eventOnlyReplicationSpec());
            Task<DDLWork> dropPtnTask = TaskFactory.get(new DDLWork(readEntitySet, writeEntitySet, dropPtnDesc, true, context.getDumpDirectory(), context.getMetricCollector()), context.hiveConf);
            context.log.debug("Added drop ptn task : {}:{},{}", dropPtnTask.getId(), dropPtnDesc.getTableName(), msg.getPartitions());
            updatedMetadata.set(context.dmd.getEventTo().toString(), actualDbName, actualTblName, null);
            return Collections.singletonList(dropPtnTask);
        } else {
            throw new SemanticException("DROP PARTITION EVENT does not return any part descs for event message :" + context.dmd.getPayload());
        }
    } catch (Exception e) {
        throw (e instanceof SemanticException) ? (SemanticException) e : new SemanticException("Error reading message members", e);
    }
}
Also used : AlterTableDropPartitionDesc(org.apache.hadoop.hive.ql.ddl.table.partition.drop.AlterTableDropPartitionDesc) Table(org.apache.hadoop.hive.ql.metadata.Table) DropPartitionMessage(org.apache.hadoop.hive.metastore.messaging.DropPartitionMessage) DDLWork(org.apache.hadoop.hive.ql.ddl.DDLWork) List(java.util.List) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Aggregations

List (java.util.List)3 AlterTableDropPartitionDesc (org.apache.hadoop.hive.ql.ddl.table.partition.drop.AlterTableDropPartitionDesc)3 DDLWork (org.apache.hadoop.hive.ql.ddl.DDLWork)2 Table (org.apache.hadoop.hive.ql.metadata.Table)2 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)2 LinkedList (java.util.LinkedList)1 Path (org.apache.hadoop.fs.Path)1 Database (org.apache.hadoop.hive.metastore.api.Database)1 DropPartitionMessage (org.apache.hadoop.hive.metastore.messaging.DropPartitionMessage)1 DDLDesc (org.apache.hadoop.hive.ql.ddl.DDLDesc)1 DescDatabaseDesc (org.apache.hadoop.hive.ql.ddl.database.desc.DescDatabaseDesc)1 DropDatabaseDesc (org.apache.hadoop.hive.ql.ddl.database.drop.DropDatabaseDesc)1 ShowDatabasesDesc (org.apache.hadoop.hive.ql.ddl.database.show.ShowDatabasesDesc)1 SwitchDatabaseDesc (org.apache.hadoop.hive.ql.ddl.database.use.SwitchDatabaseDesc)1 DescTableDesc (org.apache.hadoop.hive.ql.ddl.table.info.desc.DescTableDesc)1 ShowTableStatusDesc (org.apache.hadoop.hive.ql.ddl.table.info.show.status.ShowTableStatusDesc)1 ShowTablesDesc (org.apache.hadoop.hive.ql.ddl.table.info.show.tables.ShowTablesDesc)1 ShowPartitionsDesc (org.apache.hadoop.hive.ql.ddl.table.partition.show.ShowPartitionsDesc)1 AlterTableSetLocationDesc (org.apache.hadoop.hive.ql.ddl.table.storage.set.location.AlterTableSetLocationDesc)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1