Search in sources :

Example 1 with InvalidPartitionException

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

the class ObjectStore method getPartitionStr.

private String getPartitionStr(Table tbl, Map<String, String> partName) throws InvalidPartitionException {
    if (tbl.getPartitionKeysSize() != partName.size()) {
        throw new InvalidPartitionException("Number of partition columns in table: " + tbl.getPartitionKeysSize() + " doesn't match with number of supplied partition values: " + partName.size());
    }
    final List<String> storedVals = new ArrayList<String>(tbl.getPartitionKeysSize());
    for (FieldSchema partKey : tbl.getPartitionKeys()) {
        String partVal = partName.get(partKey.getName());
        if (null == partVal) {
            throw new InvalidPartitionException("No value found for partition column: " + partKey.getName());
        }
        storedVals.add(partVal);
    }
    return join(storedVals, ',');
}
Also used : MFieldSchema(org.apache.hadoop.hive.metastore.model.MFieldSchema) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) ArrayList(java.util.ArrayList) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException)

Example 2 with InvalidPartitionException

use of org.apache.hadoop.hive.metastore.api.InvalidPartitionException 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)

Aggregations

InvalidPartitionException (org.apache.hadoop.hive.metastore.api.InvalidPartitionException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)1 UnknownPartitionException (org.apache.hadoop.hive.metastore.api.UnknownPartitionException)1 UnknownTableException (org.apache.hadoop.hive.metastore.api.UnknownTableException)1 MFieldSchema (org.apache.hadoop.hive.metastore.model.MFieldSchema)1 CommandNeedRetryException (org.apache.hadoop.hive.ql.CommandNeedRetryException)1 Driver (org.apache.hadoop.hive.ql.Driver)1 TException (org.apache.thrift.TException)1