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;
}
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);
}
}
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;
}
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;
}
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());
}
Aggregations