Index: ql/src/test/org/apache/hadoop/hive/ql/io/TestHiveFileFormatUtils.java =================================================================== --- ql/src/test/org/apache/hadoop/hive/ql/io/TestHiveFileFormatUtils.java (revision 993445) +++ ql/src/test/org/apache/hadoop/hive/ql/io/TestHiveFileFormatUtils.java (working copy) @@ -130,4 +130,21 @@ } + public void testGetPartitionDescFromPathWithPort() throws IOException { + + PartitionDesc partDesc_1 = new PartitionDesc(); + + Map pathToPartitionInfo = new HashMap(); + Map emptyPathToPartitionInfo = new HashMap(); + + pathToPartitionInfo.put( + new Path("hdfs://mycluster:8020/part1/-mr-10002").toString(), partDesc_1); + + PartitionDesc ret = null; + + ret = HiveFileFormatUtils.getPartitionDescFromPathRecursively( + pathToPartitionInfo, new Path("hdfs://mycluster/part1/-mr-10002/000000_0"), + IOPrepareCache.get().allocatePartitionDescMap()); + assertEquals("file:///tbl/part1 not found.", partDesc_1, ret); + } } Index: ql/src/java/org/apache/hadoop/hive/ql/io/HiveFileFormatUtils.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/io/HiveFileFormatUtils.java (revision 993445) +++ ql/src/java/org/apache/hadoop/hive/ql/io/HiveFileFormatUtils.java (working copy) @@ -20,6 +20,7 @@ import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -322,6 +323,23 @@ dirStrIndex = dirStr.lastIndexOf(File.separator); } } + + // try to match the schema to deal with ignoring ports in URI + if (part == null) { + for (Map.Entry entry: pathToPartitionInfo.entrySet()) { + PartitionDesc partDesc = entry.getValue(); + Path partPath = new Path(entry.getKey()); + URI partURI = partPath.toUri(); + String partScheme = partURI.getScheme(); + if (partScheme != null && partScheme.equals(dir.toUri().getScheme())) { + if (dir.toUri().getPath().startsWith(partURI.getPath())) { + part = partDesc; + break; + } + } + } + } + return part; }