typ1.getFields().add(new FieldSchema("name", Constants.STRING_TYPE_NAME, ""));
typ1.getFields().add(new FieldSchema("income", Constants.INT_TYPE_NAME, ""));
ret = client.createType(typ1);
assertTrue("Unable to create type " + typeName, ret);
Table tbl = new Table();
tbl.setDbName(dbName);
tbl.setTableName(tblName);
StorageDescriptor sd = new StorageDescriptor();
tbl.setSd(sd);
sd.setCols(typ1.getFields());
sd.setCompressed(false);
sd.setNumBuckets(1);
sd.setParameters(new HashMap<String, String>());
sd.getParameters().put("test_param_1", "Use this for comments etc");
sd.setBucketCols(new ArrayList<String>(2));
sd.getBucketCols().add("name");
sd.setSerdeInfo(new SerDeInfo());
sd.getSerdeInfo().setName(tbl.getTableName());
sd.getSerdeInfo().setParameters(new HashMap<String, String>());
sd.getSerdeInfo().getParameters().put(Constants.SERIALIZATION_FORMAT, "1");
sd.setSortCols(new ArrayList<Order>());
tbl.setPartitionKeys(new ArrayList<FieldSchema>(2));
tbl.getPartitionKeys().add(new FieldSchema("ds", Constants.STRING_TYPE_NAME, ""));
tbl.getPartitionKeys().add(new FieldSchema("hr", Constants.INT_TYPE_NAME, ""));
client.createTable(tbl);
Partition part = new Partition();
part.setDbName(dbName);
part.setTableName(tblName);
part.setValues(vals);
part.setParameters(new HashMap<String, String>());
part.setSd(tbl.getSd());
part.getSd().setSerdeInfo(tbl.getSd().getSerdeInfo());
part.getSd().setLocation(tbl.getSd().getLocation() + "/part1");
Partition retp = client.add_partition(part);
assertNotNull("Unable to create partition " + part, retp);
Partition part2 = client.getPartition(dbName, tblName, part.getValues());
assertTrue("Partitions are not same",part.equals(part2));
FileSystem fs = FileSystem.get(this.hiveConf);
Path partPath = new Path(part2.getSd().getLocation());
assertTrue(fs.exists(partPath));
ret = client.dropPartition(dbName, tblName, part.getValues(), true);
assertTrue(ret);
assertFalse(fs.exists(partPath));
// add the partition again so that drop table with a partition can be tested
retp = client.add_partition(part);
assertNotNull("Unable to create partition " + part, ret);
client.dropTable(dbName, tblName);
ret = client.dropType(typeName);
assertTrue("Unable to drop type " + typeName, ret);
//recreate table as external, drop partition and it should
//still exist
tbl.setParameters(new HashMap<String, String>());
tbl.getParameters().put("EXTERNAL", "TRUE");
client.createTable(tbl);
retp = client.add_partition(part);
assertTrue(fs.exists(partPath));
client.dropPartition(dbName, tblName, part.getValues(), true);
assertTrue(fs.exists(partPath));