Search in sources :

Example 11 with Partition

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

the class StreamingAssert method getPartitionLocation.

private Path getPartitionLocation() throws NoSuchObjectException, MetaException, TException {
    Path partitionLocacation;
    if (partition.isEmpty()) {
        partitionLocacation = new Path(table.getSd().getLocation());
    } else {
        // TODO: calculate this instead. Just because we're writing to the location doesn't mean that it'll
        // always be wanted in the meta store right away.
        List<Partition> partitionEntries = metaStoreClient.listPartitions(table.getDbName(), table.getTableName(), partition, (short) 1);
        partitionLocacation = new Path(partitionEntries.get(0).getSd().getLocation());
    }
    return partitionLocacation;
}
Also used : Path(org.apache.hadoop.fs.Path) Partition(org.apache.hadoop.hive.metastore.api.Partition)

Example 12 with Partition

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

the class MetadataJSONSerializer method deserializePartition.

@Override
public HCatPartition deserializePartition(String hcatPartitionStringRep) throws HCatException {
    try {
        Partition partition = new Partition();
        new TDeserializer(new TJSONProtocol.Factory()).deserialize(partition, hcatPartitionStringRep, "UTF-8");
        return new HCatPartition(null, partition);
    } catch (TException exception) {
        if (LOG.isDebugEnabled())
            LOG.debug("Could not de-serialize partition from: " + hcatPartitionStringRep);
        throw new HCatException("Could not de-serialize HCatPartition.", exception);
    }
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) TDeserializer(org.apache.thrift.TDeserializer) HCatException(org.apache.hive.hcatalog.common.HCatException) LoggerFactory(org.slf4j.LoggerFactory)

Example 13 with Partition

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

the class HCatClientHMSImpl method listPartitionsByFilter.

@Override
public List<HCatPartition> listPartitionsByFilter(String dbName, String tblName, String filter) throws HCatException {
    List<HCatPartition> hcatPtns = new ArrayList<HCatPartition>();
    try {
        HCatTable table = getTable(dbName, tblName);
        List<Partition> hivePtns = hmsClient.listPartitionsByFilter(table.getDbName(), table.getTableName(), filter, (short) -1);
        for (Partition ptn : hivePtns) {
            hcatPtns.add(new HCatPartition(table, ptn));
        }
    } catch (MetaException e) {
        throw new HCatException("MetaException while fetching partitions.", e);
    } catch (NoSuchObjectException e) {
        throw new ObjectNotFoundException("NoSuchObjectException while fetching partitions.", e);
    } catch (TException e) {
        throw new ConnectionFailureException("TException while fetching partitions.", e);
    }
    return hcatPtns;
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) ArrayList(java.util.ArrayList) HCatException(org.apache.hive.hcatalog.common.HCatException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 14 with Partition

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

the class HCatClientHMSImpl method getPartitions.

@Override
public List<HCatPartition> getPartitions(String dbName, String tblName) throws HCatException {
    List<HCatPartition> hcatPtns = new ArrayList<HCatPartition>();
    try {
        HCatTable hcatTable = getTable(dbName, tblName);
        List<Partition> hivePtns = hmsClient.listPartitions(checkDB(dbName), tblName, (short) -1);
        for (Partition ptn : hivePtns) {
            hcatPtns.add(new HCatPartition(hcatTable, ptn));
        }
    } catch (NoSuchObjectException e) {
        throw new ObjectNotFoundException("NoSuchObjectException while retrieving partition.", e);
    } catch (MetaException e) {
        throw new HCatException("MetaException while retrieving partition.", e);
    } catch (TException e) {
        throw new ConnectionFailureException("TException while retrieving partition.", e);
    }
    return hcatPtns;
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) ArrayList(java.util.ArrayList) HCatException(org.apache.hive.hcatalog.common.HCatException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 15 with Partition

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

the class TestMetastoreAuthorizationProvider method testSimplePrivileges.

public void testSimplePrivileges() throws Exception {
    if (!isTestEnabled()) {
        System.out.println("Skipping test " + this.getClass().getName());
        return;
    }
    String dbName = getTestDbName();
    String tblName = getTestTableName();
    String userName = setupUser();
    allowCreateDatabase(userName);
    CommandProcessorResponse ret = driver.run("create database " + dbName);
    assertEquals(0, ret.getResponseCode());
    Database db = msc.getDatabase(dbName);
    String dbLocn = db.getLocationUri();
    validateCreateDb(db, dbName);
    disallowCreateInDb(dbName, userName, dbLocn);
    disallowCreateDatabase(userName);
    driver.run("use " + dbName);
    ret = driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName));
    assertEquals(1, ret.getResponseCode());
    // Even if table location is specified table creation should fail
    String tblNameLoc = tblName + "_loc";
    String tblLocation = new Path(dbLocn).getParent().toUri() + "/" + tblNameLoc;
    driver.run("use " + dbName);
    ret = driver.run(String.format("create table %s (a string) partitioned by (b string) location '" + tblLocation + "'", tblNameLoc));
    assertEquals(1, ret.getResponseCode());
    // failure from not having permissions to create table
    ArrayList<FieldSchema> fields = new ArrayList<FieldSchema>(2);
    fields.add(new FieldSchema("a", serdeConstants.STRING_TYPE_NAME, ""));
    Table ttbl = new Table();
    ttbl.setDbName(dbName);
    ttbl.setTableName(tblName);
    StorageDescriptor sd = new StorageDescriptor();
    ttbl.setSd(sd);
    sd.setCols(fields);
    sd.setParameters(new HashMap<String, String>());
    sd.getParameters().put("test_param_1", "Use this for comments etc");
    sd.setSerdeInfo(new SerDeInfo());
    sd.getSerdeInfo().setName(ttbl.getTableName());
    sd.getSerdeInfo().setParameters(new HashMap<String, String>());
    sd.getSerdeInfo().getParameters().put(org.apache.hadoop.hive.serde.serdeConstants.SERIALIZATION_FORMAT, "1");
    sd.getSerdeInfo().setSerializationLib(org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.class.getName());
    sd.setInputFormat(HiveInputFormat.class.getName());
    sd.setOutputFormat(HiveOutputFormat.class.getName());
    ttbl.setPartitionKeys(new ArrayList<FieldSchema>());
    MetaException me = null;
    try {
        msc.createTable(ttbl);
    } catch (MetaException e) {
        me = e;
    }
    assertNoPrivileges(me);
    allowCreateInDb(dbName, userName, dbLocn);
    driver.run("use " + dbName);
    ret = driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName));
    // now it succeeds.
    assertEquals(0, ret.getResponseCode());
    Table tbl = msc.getTable(dbName, tblName);
    validateCreateTable(tbl, tblName, dbName);
    // Table creation should succeed even if location is specified
    driver.run("use " + dbName);
    ret = driver.run(String.format("create table %s (a string) partitioned by (b string) location '" + tblLocation + "'", tblNameLoc));
    assertEquals(0, ret.getResponseCode());
    Table tblLoc = msc.getTable(dbName, tblNameLoc);
    validateCreateTable(tblLoc, tblNameLoc, dbName);
    String fakeUser = "mal";
    List<String> fakeGroupNames = new ArrayList<String>();
    fakeGroupNames.add("groupygroup");
    InjectableDummyAuthenticator.injectUserName(fakeUser);
    InjectableDummyAuthenticator.injectGroupNames(fakeGroupNames);
    InjectableDummyAuthenticator.injectMode(true);
    ret = driver.run(String.format("create table %s (a string) partitioned by (b string)", tblName + "mal"));
    assertEquals(1, ret.getResponseCode());
    ttbl.setTableName(tblName + "mal");
    me = null;
    try {
        msc.createTable(ttbl);
    } catch (MetaException e) {
        me = e;
    }
    assertNoPrivileges(me);
    disallowCreateInTbl(tbl.getTableName(), userName, tbl.getSd().getLocation());
    ret = driver.run("alter table " + tblName + " add partition (b='2011')");
    assertEquals(1, ret.getResponseCode());
    List<String> ptnVals = new ArrayList<String>();
    ptnVals.add("b=2011");
    Partition tpart = new Partition();
    tpart.setDbName(dbName);
    tpart.setTableName(tblName);
    tpart.setValues(ptnVals);
    tpart.setParameters(new HashMap<String, String>());
    tpart.setSd(tbl.getSd().deepCopy());
    tpart.getSd().setSerdeInfo(tbl.getSd().getSerdeInfo().deepCopy());
    tpart.getSd().setLocation(tbl.getSd().getLocation() + "/tpart");
    me = null;
    try {
        msc.add_partition(tpart);
    } catch (MetaException e) {
        me = e;
    }
    assertNoPrivileges(me);
    InjectableDummyAuthenticator.injectMode(false);
    allowCreateInTbl(tbl.getTableName(), userName, tbl.getSd().getLocation());
    ret = driver.run("alter table " + tblName + " add partition (b='2011')");
    assertEquals(0, ret.getResponseCode());
    allowDropOnTable(tblName, userName, tbl.getSd().getLocation());
    allowDropOnDb(dbName, userName, db.getLocationUri());
    ret = driver.run("drop database if exists " + getTestDbName() + " cascade");
    assertEquals(0, ret.getResponseCode());
    InjectableDummyAuthenticator.injectUserName(userName);
    InjectableDummyAuthenticator.injectGroupNames(Arrays.asList(ugi.getGroupNames()));
    InjectableDummyAuthenticator.injectMode(true);
    allowCreateDatabase(userName);
    driver.run("create database " + dbName);
    allowCreateInDb(dbName, userName, dbLocn);
    tbl.setTableType("EXTERNAL_TABLE");
    msc.createTable(tbl);
    disallowDropOnTable(tblName, userName, tbl.getSd().getLocation());
    ret = driver.run("drop table " + tbl.getTableName());
    assertEquals(1, ret.getResponseCode());
}
Also used : Path(org.apache.hadoop.fs.Path) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) ArrayList(java.util.ArrayList) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) HiveOutputFormat(org.apache.hadoop.hive.ql.io.HiveOutputFormat) HiveInputFormat(org.apache.hadoop.hive.ql.io.HiveInputFormat) Database(org.apache.hadoop.hive.metastore.api.Database) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

Partition (org.apache.hadoop.hive.metastore.api.Partition)204 Table (org.apache.hadoop.hive.metastore.api.Table)125 ArrayList (java.util.ArrayList)124 Test (org.junit.Test)88 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)81 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)80 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)69 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)44 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)35 List (java.util.List)34 ColumnStatisticsObj (org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj)28 ColumnStatisticsDesc (org.apache.hadoop.hive.metastore.api.ColumnStatisticsDesc)27 ColumnStatistics (org.apache.hadoop.hive.metastore.api.ColumnStatistics)26 ColumnStatisticsData (org.apache.hadoop.hive.metastore.api.ColumnStatisticsData)26 AggrStats (org.apache.hadoop.hive.metastore.api.AggrStats)25 Database (org.apache.hadoop.hive.metastore.api.Database)24 TException (org.apache.thrift.TException)24 IOException (java.io.IOException)23 Path (org.apache.hadoop.fs.Path)22 HashMap (java.util.HashMap)21