From ec3a567117ddfcd899e8f8db84d418a57e4638dd Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Sun, 10 Aug 2014 22:30:09 +0000 Subject: [PATCH] HADOOP-10402. Configuration.getValByRegex does not substitute for variables. (Robert Kanter via kasha) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1617174 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../main/java/org/apache/hadoop/conf/Configuration.java | 3 ++- .../java/org/apache/hadoop/conf/TestConfiguration.java | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index c13ba43e2b9..98f5603a21e 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -115,6 +115,9 @@ Release 2.6.0 - UNRELEASED HADOOP-10929. Typo in Configuration.getPasswordFromCredentialProviders (lmccay via brandonli) + HADOOP-10402. Configuration.getValByRegex does not substitute for + variables. (Robert Kanter via kasha) + Release 2.5.0 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 56a356dd012..4ad96564c85 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -2747,7 +2747,8 @@ public class Configuration implements Iterable>, item.getValue() instanceof String) { m = p.matcher((String)item.getKey()); if(m.find()) { // match - result.put((String) item.getKey(), (String) item.getValue()); + result.put((String) item.getKey(), + substituteVars(getProps().getProperty((String) item.getKey()))); } } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index 67977f93e9d..3bc8365e890 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -178,6 +178,14 @@ public class TestConfiguration extends TestCase { // check that expansion also occurs for getInt() assertTrue(conf.getInt("intvar", -1) == 42); assertTrue(conf.getInt("my.int", -1) == 42); + + Map results = conf.getValByRegex("^my.*file$"); + assertTrue(results.keySet().contains("my.relfile")); + assertTrue(results.keySet().contains("my.fullfile")); + assertTrue(results.keySet().contains("my.file")); + assertEquals(-1, results.get("my.relfile").indexOf("${")); + assertEquals(-1, results.get("my.fullfile").indexOf("${")); + assertEquals(-1, results.get("my.file").indexOf("${")); } public void testFinalParam() throws IOException {