diff --git hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/schema/HCatSchemaUtils.java hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/schema/HCatSchemaUtils.java index 16c1604..7c12911 100644 --- hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/schema/HCatSchemaUtils.java +++ hcatalog/core/src/main/java/org/apache/hive/hcatalog/data/schema/HCatSchemaUtils.java @@ -102,6 +102,13 @@ public MapBuilder withKeyType(PrimitiveTypeInfo keyType) { } + public static List getHCatFields(List fs) throws HCatException { + List schema = new ArrayList(); + for (FieldSchema field : fs) { + schema.add(getHCatFieldSchema(field)); + } + return schema; + } /** * Convert a HCatFieldSchema to a FieldSchema diff --git hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java index b3afa72..41cb44e 100644 --- hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java +++ hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatClientHMSImpl.java @@ -329,8 +329,7 @@ public void renameTable(String dbName, String oldName, String newName) throws HCatException { List hcatPtns = new ArrayList(); try { - Table table = hmsClient.getTable(dbName, tblName); - HCatTable hcatTable = new HCatTable(table); + HCatTable hcatTable = getTable(dbName, tblName); List hivePtns = hmsClient.listPartitions( checkDB(dbName), tblName, (short) -1); for (Partition ptn : hivePtns) { @@ -374,7 +373,7 @@ public HCatPartition getPartition(String dbName, String tableName, Map partitionSpec) throws HCatException { HCatPartition partition = null; try { - HCatTable hcatTable = getTable(checkDB(dbName), tableName); + HCatTable hcatTable = getTable(dbName, tableName); List partitionColumns = hcatTable.getPartCols(); if (partitionColumns.size() != partitionSpec.size()) { throw new HCatException("Partition-spec doesn't have the right number of partition keys."); @@ -494,7 +493,7 @@ private void dropPartition(Partition partition, boolean ifExists) try { HCatTable table = getTable(dbName, tblName); List hivePtns = hmsClient.listPartitionsByFilter( - checkDB(dbName), tblName, filter, (short) -1); + table.getDbName(), table.getTableName(), filter, (short) -1); for (Partition ptn : hivePtns) { hcatPtns.add(new HCatPartition(table, ptn)); } diff --git hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatPartition.java hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatPartition.java index 52586a0..0d714ff 100644 --- hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatPartition.java +++ hcatalog/webhcat/java-client/src/main/java/org/apache/hive/hcatalog/api/HCatPartition.java @@ -188,6 +188,15 @@ public String getDatabaseName() { } /** + * Gets the partition columns of the table. + * + * @return the partition columns + */ + public List getPartColumns() { + return hcatTable.getPartCols(); + } + + /** * Gets the input format. * * @return the input format diff --git hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java index f9f7b04..842ce71 100644 --- hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java +++ hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java @@ -758,6 +758,11 @@ public void testDropPartitionsWithPartialSpec() throws Exception { assertEquals("Unexpected number of partitions.", 1, partitions.size()); assertArrayEquals("Mismatched partition.", new String[]{"2011_12_31", "AB"}, partitions.get(0).getValues().toArray()); + List partColumns = partitions.get(0).getPartColumns(); + assertEquals(2, partColumns.size()); + assertEquals("dt", partColumns.get(0).getName()); + assertEquals("grid", partColumns.get(1).getName()); + client.dropDatabase(dbName, false, HCatClient.DropDBMode.CASCADE); } catch (Exception unexpected) {