diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java index afecb1e..7bc69a4 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java @@ -1209,11 +1209,21 @@ public static ArrayList makeList(Object... olist) { return (ret); } + private static ConcurrentHashMap tableDescriptorCache = + new ConcurrentHashMap(); + private static ConcurrentHashMap partitionDescriptorCache = + new ConcurrentHashMap(); + public static TableDesc getTableDesc(Table tbl) { - Properties props = tbl.getMetadata(); - props.put(serdeConstants.SERIALIZATION_LIB, tbl.getDeserializer().getClass().getName()); - return (new TableDesc(tbl.getInputFormatClass(), tbl - .getOutputFormatClass(), props)); + TableDesc ret = tableDescriptorCache.get(tbl); + if (ret == null) { + Properties props = tbl.getMetadata(); + props.put(serdeConstants.SERIALIZATION_LIB, tbl.getDeserializer().getClass().getName()); + ret = new TableDesc(tbl.getInputFormatClass(), tbl + .getOutputFormatClass(), props); + tableDescriptorCache.put(tbl, ret); + } + return ret; } // column names and column types are all delimited by comma @@ -1227,7 +1237,12 @@ public static TableDesc getTableDesc(String cols, String colTypes) { } public static PartitionDesc getPartitionDesc(Partition part) throws HiveException { - return (new PartitionDesc(part)); + PartitionDesc ret = partitionDescriptorCache.get(part); + if (ret == null) { + ret = new PartitionDesc(part); + partitionDescriptorCache.put(part, ret); + } + return ret; } public static PartitionDesc getPartitionDescFromTableDesc(TableDesc tblDesc, Partition part) diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java index 08ff2e9..e8ae8de 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/Partition.java @@ -639,4 +639,40 @@ public void checkValidity() throws HiveException { Table.validateColumns(getCols(), table.getPartCols()); } } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((tPartition == null) ? 0 : tPartition.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Partition other = (Partition) obj; + if (tPartition == null) { + if (other.tPartition != null) { + return false; + } + } else if (!tPartition.equals(other.tPartition)) { + return false; + } + return true; + } }