MAPREDUCE-5905. CountersStrings.toEscapedCompactStrings outputs unnecessary null strings. Contributed by Akira AJISAKA.
(cherry picked from commit 3ba18362f2
)
This commit is contained in:
parent
5b27d9e076
commit
1035f550b9
|
@ -107,6 +107,9 @@ Release 2.8.0 - UNRELEASED
|
||||||
MAPREDUCE-6345. Documentation fix for when CRLA is enabled for MRAppMaster
|
MAPREDUCE-6345. Documentation fix for when CRLA is enabled for MRAppMaster
|
||||||
logs. (Rohit Agarwal via gera)
|
logs. (Rohit Agarwal via gera)
|
||||||
|
|
||||||
|
MAPREDUCE-5905. CountersStrings.toEscapedCompactStrings outputs
|
||||||
|
unnecessary "null" strings. (Akira AJISAKA via ozawa)
|
||||||
|
|
||||||
Release 2.7.1 - UNRELEASED
|
Release 2.7.1 - UNRELEASED
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -151,25 +151,12 @@ public class CountersStrings {
|
||||||
public static <C extends Counter, G extends CounterGroupBase<C>,
|
public static <C extends Counter, G extends CounterGroupBase<C>,
|
||||||
T extends AbstractCounters<C, G>>
|
T extends AbstractCounters<C, G>>
|
||||||
String toEscapedCompactString(T counters) {
|
String toEscapedCompactString(T counters) {
|
||||||
String[] groupsArray;
|
StringBuilder builder = new StringBuilder();
|
||||||
int length = 0;
|
|
||||||
synchronized(counters) {
|
synchronized(counters) {
|
||||||
groupsArray = new String[counters.countCounters()];
|
|
||||||
int i = 0;
|
|
||||||
// First up, obtain the escaped string for each group so that we can
|
|
||||||
// determine the buffer length apriori.
|
|
||||||
for (G group : counters) {
|
for (G group : counters) {
|
||||||
String escapedString = toEscapedCompactString(group);
|
builder.append(toEscapedCompactString(group));
|
||||||
groupsArray[i++] = escapedString;
|
|
||||||
length += escapedString.length();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now construct the buffer
|
|
||||||
StringBuilder builder = new StringBuilder(length);
|
|
||||||
for (String group : groupsArray) {
|
|
||||||
builder.append(group);
|
|
||||||
}
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.hadoop.mapred;
|
package org.apache.hadoop.mapred;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -84,6 +85,8 @@ public class TestCounters {
|
||||||
*/
|
*/
|
||||||
private void testCounter(Counters counter) throws ParseException {
|
private void testCounter(Counters counter) throws ParseException {
|
||||||
String compactEscapedString = counter.makeEscapedCompactString();
|
String compactEscapedString = counter.makeEscapedCompactString();
|
||||||
|
assertFalse("compactEscapedString should not contain null",
|
||||||
|
compactEscapedString.contains("null"));
|
||||||
|
|
||||||
Counters recoveredCounter =
|
Counters recoveredCounter =
|
||||||
Counters.fromEscapedCompactString(compactEscapedString);
|
Counters.fromEscapedCompactString(compactEscapedString);
|
||||||
|
|
Loading…
Reference in New Issue