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 c4b5971..a8acc2e 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 @@ -308,10 +308,12 @@ public void renameTable(String dbName, String oldName, String newName) throws HCatException { List hcatPtns = new ArrayList(); try { + Table table = hmsClient.getTable(checkDB(dbName), tblName); List hivePtns = hmsClient.listPartitions( - checkDB(dbName), tblName, (short) -1); + table.getDbName(), table.getTableName(), (short) -1); + List partCols = HCatSchemaUtils.getHCatFields(table.getPartitionKeys()); for (Partition ptn : hivePtns) { - hcatPtns.add(new HCatPartition(ptn)); + hcatPtns.add(new HCatPartition(partCols, ptn)); } } catch (NoSuchObjectException e) { throw new ObjectNotFoundException( @@ -369,7 +371,7 @@ public HCatPartition getPartition(String dbName, String tableName, Partition hivePartition = hmsClient.getPartition(checkDB(dbName), tableName, ptnValues); if (hivePartition != null) { - partition = new HCatPartition(hivePartition); + partition = new HCatPartition(partitionColumns, hivePartition); } } catch (MetaException e) { throw new HCatException( @@ -458,10 +460,12 @@ private void dropPartition(Partition partition, boolean ifExists) String tblName, String filter) throws HCatException { List hcatPtns = new ArrayList(); try { + Table table = hmsClient.getTable(checkDB(dbName), tblName); List hivePtns = hmsClient.listPartitionsByFilter( - checkDB(dbName), tblName, filter, (short) -1); + table.getDbName(), table.getTableName(), filter, (short) -1); + List partCols = HCatSchemaUtils.getHCatFields(table.getPartitionKeys()); for (Partition ptn : hivePtns) { - hcatPtns.add(new HCatPartition(ptn)); + hcatPtns.add(new HCatPartition(partCols, ptn)); } } catch (MetaException e) { throw new HCatException("MetaException while fetching partitions.", 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 ee1b6bf..3ec3735 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 @@ -18,11 +18,9 @@ */ package org.apache.hive.hcatalog.api; -import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.Order; import org.apache.hadoop.hive.metastore.api.Partition; import org.apache.hadoop.hive.metastore.api.StorageDescriptor; @@ -38,6 +36,7 @@ private String tableName; private String dbName; private List values; + private List partCols; private List tableCols; private int createTime; private int lastAccessTime; @@ -45,6 +44,10 @@ private Map parameters; HCatPartition(Partition partition) throws HCatException { + this(null, partition); + } + + HCatPartition(List partCols, Partition partition) throws HCatException { this.tableName = partition.getTableName(); this.dbName = partition.getDbName(); this.createTime = partition.getCreateTime(); @@ -52,10 +55,8 @@ this.parameters = partition.getParameters(); this.values = partition.getValues(); this.sd = partition.getSd(); - this.tableCols = new ArrayList(); - for (FieldSchema fs : this.sd.getCols()) { - this.tableCols.add(HCatSchemaUtils.getHCatFieldSchema(fs)); - } + this.tableCols = HCatSchemaUtils.getHCatFields(sd.getCols()); + this.partCols = partCols; } /** @@ -86,6 +87,15 @@ public String getDatabaseName() { } /** + * Gets the partition columns of the table. + * + * @return the partition columns + */ + public List getPartColumns() { + return this.partCols; + } + + /** * 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 04029ed..f088b86 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 @@ -706,6 +706,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) {