diff --git a/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java b/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java index 0483e91..e6af00d 100644 --- a/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java +++ b/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java @@ -57,6 +57,7 @@ import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.hdfs.DFSClient; +import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSNNTopology; @@ -1148,10 +1149,22 @@ public HdfsEncryptionShim(URI uri, Configuration conf) throws IOException { DistributedFileSystem dfs = (DistributedFileSystem)FileSystem.get(uri, conf); this.conf = conf; - this.keyProvider = dfs.getClient().getKeyProvider(); + this.keyProvider = isEncryptionEnabled(dfs.getClient(), dfs.getConf()) ? + dfs.getClient().getKeyProvider() : null; this.hdfsAdmin = new HdfsAdmin(uri, conf); } + private boolean isEncryptionEnabled(DFSClient client, Configuration conf) { + try { + DFSClient.class.getMethod("isHDFSEncryptionEnabled"); + } catch (NoSuchMethodException e) { + // the method is available since Hadoop-2.7.1 + // if we run with an older Hadoop, check this ourselves + return !conf.getTrimmed(DFSConfigKeys.DFS_ENCRYPTION_KEY_PROVIDER_URI, "").isEmpty(); + } + return client.isHDFSEncryptionEnabled(); + } + @Override public boolean isPathEncrypted(Path path) throws IOException { Path fullPath;