From 754783def2ac81b54f1a24403a78b9b47ed6e091 Mon Sep 17 00:00:00 2001 From: "suresh.bahuguna" Date: Tue, 13 Dec 2016 12:53:55 +0530 Subject: [PATCH] HIVE-15423: Allowing Hive to reverse map IP from hostname for partition info --- .../hive/ql/io/HiveFileFormatUtils.java | 20 +++++++++++++++++++ .../apache/hadoop/hive/ql/io/IOConstants.java | 1 + 2 files changed, 21 insertions(+) diff --git a/ql/src/java/org/apache/hadoop/hive/ql/io/HiveFileFormatUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/io/HiveFileFormatUtils.java index 7ad5aa0bde06..56687e64a713 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/io/HiveFileFormatUtils.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/io/HiveFileFormatUtils.java @@ -19,6 +19,8 @@ package org.apache.hadoop.hive.ql.io; import java.io.IOException; +import java.net.InetAddress; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -363,6 +365,24 @@ public static PartitionDesc getPartitionDescFromPathRecursively( } part = doGetPartitionDescFromPath(newPathToPartitionInfo, dir); } + if (part == null && dir.toUri().getAuthority() != null) { + // Exception imminent. Try calling function after reverse mapping hostname + String hostname = dir.toUri().getAuthority(); + hostname = hostname.split(IOConstants.COLON_SEPARATOR)[0]; + + InetAddress inetAddress = InetAddress.getByName(hostname); + String ip = inetAddress.getHostAddress(); + + String dirPath = dir.toString(); + if (!hostname.equalsIgnoreCase(ip)) { + // This check is in place to prevent infinite recursion + dirPath = dirPath.replaceAll(hostname, ip); + Path newpath = new Path(dirPath); + + part = getPartitionDescFromPathRecursively(pathToPartitionInfo, newpath, cacheMap, + ignoreSchema); + } + } if (part != null) { return part; } else { diff --git a/ql/src/java/org/apache/hadoop/hive/ql/io/IOConstants.java b/ql/src/java/org/apache/hadoop/hive/ql/io/IOConstants.java index 9879dfe777ae..d058e8083471 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/io/IOConstants.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/io/IOConstants.java @@ -35,6 +35,7 @@ public final class IOConstants { public static final String PARQUETFILE = "PARQUETFILE"; public static final String AVRO = "AVRO"; public static final String AVROFILE = "AVROFILE"; + public static final String COLON_SEPARATOR = ":"; @VisibleForTesting public static final String CUSTOM_TEXT_SERDE = "CustomTextSerde";