Search in sources :

Example 1 with UnknownTableException

use of org.apache.hadoop.hive.metastore.api.UnknownTableException in project hive by apache.

the class ObjectStore method markPartitionForEvent.

@Override
public Table markPartitionForEvent(String dbName, String tblName, Map<String, String> partName, PartitionEventType evtType) throws MetaException, UnknownTableException, InvalidPartitionException, UnknownPartitionException {
    LOG.debug("Begin executing markPartitionForEvent");
    boolean success = false;
    Table tbl = null;
    try {
        openTransaction();
        // Make sure dbName and tblName are valid.
        tbl = getTable(dbName, tblName);
        if (null == tbl) {
            throw new UnknownTableException("Table: " + tblName + " is not found.");
        }
        pm.makePersistent(new MPartitionEvent(dbName, tblName, getPartitionStr(tbl, partName), evtType.getValue()));
        success = commitTransaction();
        LOG.debug("Done executing markPartitionForEvent");
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
    return tbl;
}
Also used : UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) Table(org.apache.hadoop.hive.metastore.api.Table) MVersionTable(org.apache.hadoop.hive.metastore.model.MVersionTable) MTable(org.apache.hadoop.hive.metastore.model.MTable) MPartitionEvent(org.apache.hadoop.hive.metastore.model.MPartitionEvent)

Example 2 with UnknownTableException

use of org.apache.hadoop.hive.metastore.api.UnknownTableException in project hive by apache.

the class ObjectStore method isPartitionMarkedForEvent.

@Override
public boolean isPartitionMarkedForEvent(String dbName, String tblName, Map<String, String> partName, PartitionEventType evtType) throws UnknownTableException, MetaException, InvalidPartitionException, UnknownPartitionException {
    boolean success = false;
    Query query = null;
    try {
        LOG.debug("Begin Executing isPartitionMarkedForEvent");
        openTransaction();
        query = pm.newQuery(MPartitionEvent.class, "dbName == t1 && tblName == t2 && partName == t3 && eventType == t4");
        query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3, int t4");
        // Make sure dbName and tblName are valid.
        Table tbl = getTable(dbName, tblName);
        if (null == tbl) {
            throw new UnknownTableException("Table: " + tblName + " is not found.");
        }
        Collection<MPartitionEvent> partEvents = (Collection<MPartitionEvent>) query.executeWithArray(dbName, tblName, getPartitionStr(tbl, partName), evtType.getValue());
        pm.retrieveAll(partEvents);
        success = commitTransaction();
        LOG.debug("Done executing isPartitionMarkedForEvent");
        return (partEvents != null && !partEvents.isEmpty()) ? true : false;
    } finally {
        if (!success) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
}
Also used : UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) Table(org.apache.hadoop.hive.metastore.api.Table) MVersionTable(org.apache.hadoop.hive.metastore.model.MVersionTable) MTable(org.apache.hadoop.hive.metastore.model.MTable) Query(javax.jdo.Query) MPartitionEvent(org.apache.hadoop.hive.metastore.model.MPartitionEvent) Collection(java.util.Collection)

Example 3 with UnknownTableException

use of org.apache.hadoop.hive.metastore.api.UnknownTableException in project hive by apache.

the class TestMarkPartition method testMarkingPartitionSet.

public void testMarkingPartitionSet() throws CommandNeedRetryException, MetaException, TException, NoSuchObjectException, UnknownDBException, UnknownTableException, InvalidPartitionException, UnknownPartitionException, InterruptedException {
    HiveMetaStoreClient msc = new HiveMetaStoreClient(hiveConf);
    driver = new Driver(hiveConf);
    driver.run("drop database if exists hive2215 cascade");
    driver.run("create database hive2215");
    driver.run("use hive2215");
    driver.run("drop table if exists tmptbl");
    driver.run("create table tmptbl (a string) partitioned by (b string)");
    driver.run("alter table tmptbl add partition (b='2011')");
    Map<String, String> kvs = new HashMap<String, String>();
    kvs.put("b", "'2011'");
    msc.markPartitionForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
    assert msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
    Thread.sleep(10000);
    assert !msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
    kvs.put("b", "'2012'");
    assert !msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
    try {
        msc.markPartitionForEvent("hive2215", "tmptbl2", kvs, PartitionEventType.LOAD_DONE);
        assert false;
    } catch (Exception e) {
        assert e instanceof UnknownTableException;
    }
    try {
        msc.isPartitionMarkedForEvent("hive2215", "tmptbl2", kvs, PartitionEventType.LOAD_DONE);
        assert false;
    } catch (Exception e) {
        assert e instanceof UnknownTableException;
    }
    kvs.put("a", "'2012'");
    try {
        msc.isPartitionMarkedForEvent("hive2215", "tmptbl", kvs, PartitionEventType.LOAD_DONE);
        assert false;
    } catch (Exception e) {
        assert e instanceof InvalidPartitionException;
    }
}
Also used : UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) HashMap(java.util.HashMap) Driver(org.apache.hadoop.hive.ql.Driver) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) TException(org.apache.thrift.TException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) CommandNeedRetryException(org.apache.hadoop.hive.ql.CommandNeedRetryException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException)

Example 4 with UnknownTableException

use of org.apache.hadoop.hive.metastore.api.UnknownTableException in project drill by apache.

the class DrillHiveMetaStoreClient method getHiveReadEntryHelper.

/** Helper method which gets table metadata. Retries once if the first call to fetch the metadata fails */
protected static HiveReadEntry getHiveReadEntryHelper(final IMetaStoreClient mClient, final String dbName, final String tableName) throws TException {
    Table table = null;
    try {
        table = mClient.getTable(dbName, tableName);
    } catch (MetaException | NoSuchObjectException e) {
        throw e;
    } catch (TException e) {
        logger.warn("Failure while attempting to get hive table. Retries once. ", e);
        try {
            mClient.close();
        } catch (Exception ex) {
            logger.warn("Failure while attempting to close existing hive metastore connection. May leak connection.", ex);
        }
        mClient.reconnect();
        table = mClient.getTable(dbName, tableName);
    }
    if (table == null) {
        throw new UnknownTableException(String.format("Unable to find table '%s'.", tableName));
    }
    List<Partition> partitions;
    try {
        partitions = mClient.listPartitions(dbName, tableName, (short) -1);
    } catch (NoSuchObjectException | MetaException e) {
        throw e;
    } catch (TException e) {
        logger.warn("Failure while attempting to get hive partitions. Retries once. ", e);
        try {
            mClient.close();
        } catch (Exception ex) {
            logger.warn("Failure while attempting to close existing hive metastore connection. May leak connection.", ex);
        }
        mClient.reconnect();
        partitions = mClient.listPartitions(dbName, tableName, (short) -1);
    }
    List<HiveTableWrapper.HivePartitionWrapper> hivePartitionWrappers = Lists.newArrayList();
    HiveTableWithColumnCache hiveTable = new HiveTableWithColumnCache(table, new ColumnListsCache(table));
    for (Partition partition : partitions) {
        hivePartitionWrappers.add(createPartitionWithSpecColumns(hiveTable, partition));
    }
    if (hivePartitionWrappers.isEmpty()) {
        hivePartitionWrappers = null;
    }
    return new HiveReadEntry(new HiveTableWrapper(hiveTable), hivePartitionWrappers);
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) UserException(org.apache.drill.common.exceptions.UserException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) HiveAccessControlException(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAccessControlException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

UnknownTableException (org.apache.hadoop.hive.metastore.api.UnknownTableException)4 Table (org.apache.hadoop.hive.metastore.api.Table)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)2 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)2 MPartitionEvent (org.apache.hadoop.hive.metastore.model.MPartitionEvent)2 MTable (org.apache.hadoop.hive.metastore.model.MTable)2 MVersionTable (org.apache.hadoop.hive.metastore.model.MVersionTable)2 TException (org.apache.thrift.TException)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Query (javax.jdo.Query)1 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 UserException (org.apache.drill.common.exceptions.UserException)1 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)1 InvalidPartitionException (org.apache.hadoop.hive.metastore.api.InvalidPartitionException)1 Partition (org.apache.hadoop.hive.metastore.api.Partition)1 UnknownPartitionException (org.apache.hadoop.hive.metastore.api.UnknownPartitionException)1