Skip to content

Commit 45f51df

Browse files
committed
Decode value of items for the job Configuration which was encoded by hive,such as hive.query.string
1 parent 4f4b846 commit 45f51df

File tree

4 files changed

+52
-6
lines changed
  • hadoop-mapreduce-project/hadoop-mapreduce-client

4 files changed

+52
-6
lines changed

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/ConfBlock.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222
import static org.apache.hadoop.yarn.webapp.view.JQueryUI._TH;
2323

2424
import java.io.IOException;
25+
import java.io.UnsupportedEncodingException;
26+
import java.net.URLDecoder;
27+
import java.util.HashSet;
28+
import java.util.Set;
2529

30+
import org.apache.hadoop.conf.Configuration;
2631
import org.apache.hadoop.fs.Path;
32+
import org.apache.hadoop.mapreduce.MRJobConfig;
2733
import org.apache.hadoop.mapreduce.v2.api.records.JobId;
2834
import org.apache.hadoop.mapreduce.v2.app.AppContext;
2935
import org.apache.hadoop.mapreduce.v2.app.job.Job;
@@ -48,6 +54,20 @@ public class ConfBlock extends HtmlBlock {
4854
appContext = appctx;
4955
}
5056

57+
/**
58+
* To URLDecode the string value for URLEncoded data.
59+
* @param value string data to be decoded
60+
* @return value data after decoded
61+
* @throws UnsupportedEncodingException if empty string or unsupported enc parameter.
62+
*/
63+
private String urlDecode(String value){
64+
try {
65+
return URLDecoder.decode(value, "UTF-8");
66+
} catch (UnsupportedEncodingException e) {
67+
return value;
68+
}
69+
}
70+
5171
/*
5272
* (non-Javadoc)
5373
* @see org.apache.hadoop.yarn.webapp.view.HtmlBlock#render(org.apache.hadoop.yarn.webapp.view.HtmlBlock.Block)
@@ -95,12 +115,22 @@ public class ConfBlock extends HtmlBlock {
95115
first = false;
96116
buffer.append(sources[i]);
97117
}
118+
Configuration conf = appContext.getJob(jobID).loadConfFile();
119+
String decodeStrings = conf.getTrimmed(MRJobConfig.MR_DECODE_CONFIGS, "");
120+
Set<String> decodeConfigs = new HashSet<>();
121+
for (String config : decodeStrings.split(",")) {
122+
decodeConfigs.add(config.trim());
123+
}
124+
String value = entry.getValue();
125+
if(decodeConfigs.contains(entry.getName())){
126+
value = urlDecode(value);
127+
}
98128
tbody.
99129
tr().
100-
td(entry.getName()).
101-
td(entry.getValue()).
102-
td(buffer.toString()).
103-
__();
130+
td(entry.getName()).
131+
td(value).
132+
td(buffer.toString()).
133+
__();
104134
}
105135
tbody.__().
106136
tfoot().

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestBlocks.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.PrintWriter;
2323
import java.util.HashMap;
2424
import java.util.Map;
25+
import java.net.URLDecoder;
2526

2627
import org.apache.hadoop.mapreduce.MRJobConfig;
2728
import org.apache.hadoop.mapreduce.util.MRJobConfUtil;
@@ -70,12 +71,16 @@ public void testConfigurationBlock() throws Exception {
7071
final String redactedProp = "Key for redaction";
7172
configuration.set(MRJobConfig.MR_JOB_REDACTED_PROPERTIES,
7273
redactedProp);
74+
final String testQueryStringEncoded = "insert+overwrite+table" +
75+
"+test_hive_query_string+values%282%2C1%29";
76+
final String decodeKey = "hive.query.string";
77+
configuration.set("hive.query.string", testQueryStringEncoded);
78+
configuration.set(MRJobConfig.MR_DECODE_CONFIGS, decodeKey);
79+
7380
when(job.getConfFile()).thenReturn(path);
7481
when(job.loadConfFile()).thenReturn(configuration);
75-
7682
when(ctx.getJob(any(JobId.class))).thenReturn(job);
7783

78-
7984
ConfBlockForTest configurationBlock = new ConfBlockForTest(ctx);
8085
PrintWriter pWriter = new PrintWriter(data);
8186
Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);
@@ -94,6 +99,8 @@ public void testConfigurationBlock() throws Exception {
9499
assertTrue(data.toString().contains(redactedProp));
95100
assertTrue(data.toString().contains(
96101
MRJobConfUtil.REDACTION_REPLACEMENT_VAL));
102+
assertTrue(data.toString().contains("hive.query.string"));
103+
assertTrue(data.toString().contains(URLDecoder.decode(testQueryStringEncoded,"UTF-8")));
97104
}
98105

99106
/**

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/MRJobConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,4 +1316,5 @@ public interface MRJobConfig {
13161316
String INPUT_FILE_MANDATORY_PREFIX = "mapreduce.job.input.file.must.";
13171317
String SHUFFLE_KEY_LENGTH = "mapreduce.shuffle-key-length";
13181318
int DEFAULT_SHUFFLE_KEY_LENGTH = 64;
1319+
String MR_DECODE_CONFIGS = "mapreduce.job.decode.configs";
13191320
}

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/resources/mapred-default.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,4 +2282,12 @@
22822282
</description>
22832283
</property>
22842284

2285+
<property>
2286+
<name>mapreduce.job.decode.configs</name>
2287+
<value>hive.query.string</value>
2288+
<description>
2289+
Some Configurations in job is encoded,which should be decoded before rendered.
2290+
</description>
2291+
</property>
2292+
22852293
</configuration>

0 commit comments

Comments
 (0)