| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
package org.apache.hadoop.hive.contrib.mr; |
| 19 |
|
|
| 20 |
|
import java.io.BufferedReader; |
| 21 |
|
import java.io.InputStream; |
| 22 |
|
import java.io.InputStreamReader; |
| 23 |
|
import java.io.OutputStream; |
| 24 |
|
import java.io.OutputStreamWriter; |
| 25 |
|
import java.io.PrintWriter; |
| 26 |
|
import java.io.Reader; |
| 27 |
|
import java.io.Writer; |
| 28 |
|
import java.util.Iterator; |
| 29 |
|
import java.util.NoSuchElementException; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
|
|
|
| 82.6% |
Uncovered Elements: 4 (23) |
Complexity: 8 |
Complexity Density: 0.57 |
|
| 51 |
|
public final class GenericMR { |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
0
|
public void map(final InputStream in, final OutputStream out,... |
| 53 |
|
final Mapper mapper) throws Exception { |
| 54 |
0
|
map(new InputStreamReader(in), new OutputStreamWriter(out), mapper); |
| 55 |
|
} |
| 56 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 57 |
3
|
public void map(final Reader in, final Writer out, final Mapper mapper) throws Exception {... |
| 58 |
3
|
handle(in, out, new RecordProcessor() { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 59 |
4
|
@Override... |
| 60 |
|
public void processNext(RecordReader reader, Output output) throws Exception { |
| 61 |
4
|
mapper.map(reader.next(), output); |
| 62 |
|
} |
| 63 |
|
}); |
| 64 |
|
} |
| 65 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 66 |
0
|
public void reduce(final InputStream in, final OutputStream out,... |
| 67 |
|
final Reducer reducer) throws Exception { |
| 68 |
0
|
reduce(new InputStreamReader(in), new OutputStreamWriter(out), reducer); |
| 69 |
|
} |
| 70 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 71 |
3
|
public void reduce(final Reader in, final Writer out, final Reducer reducer) throws Exception {... |
| 72 |
3
|
handle(in, out, new RecordProcessor() { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 73 |
5
|
@Override... |
| 74 |
|
public void processNext(RecordReader reader, Output output) throws Exception { |
| 75 |
5
|
reducer.reduce(reader.peek()[0], new KeyRecordIterator( |
| 76 |
|
reader.peek()[0], reader), output); |
| 77 |
|
} |
| 78 |
|
}); |
| 79 |
|
} |
| 80 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 81 |
6
|
private void handle(final Reader in, final Writer out,... |
| 82 |
|
final RecordProcessor processor) throws Exception { |
| 83 |
6
|
final RecordReader reader = new RecordReader(in); |
| 84 |
6
|
final OutputStreamOutput output = new OutputStreamOutput(out); |
| 85 |
|
|
| 86 |
6
|
try { |
| 87 |
14
|
while (reader.hasNext()) { |
| 88 |
9
|
processor.processNext(reader, output); |
| 89 |
|
} |
| 90 |
|
} finally { |
| 91 |
6
|
try { |
| 92 |
6
|
output.close(); |
| 93 |
|
} finally { |
| 94 |
6
|
reader.close(); |
| 95 |
|
} |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 99 |
|
private static interface RecordProcessor { |
| 100 |
|
void processNext(final RecordReader reader, final Output output) throws Exception; |
| 101 |
|
} |
| 102 |
|
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 5 |
Complexity Density: 0.71 |
|
| 103 |
|
private static final class KeyRecordIterator implements Iterator<String[]> { |
| 104 |
|
private final String key; |
| 105 |
|
private final RecordReader reader; |
| 106 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 107 |
5
|
private KeyRecordIterator(final String key, final RecordReader reader) {... |
| 108 |
5
|
this.key = key; |
| 109 |
5
|
this.reader = reader; |
| 110 |
|
} |
| 111 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 112 |
20
|
@Override... |
| 113 |
|
public boolean hasNext() { |
| 114 |
20
|
return (reader.hasNext() && key.equals(reader.peek()[0])); |
| 115 |
|
} |
| 116 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 117 |
9
|
@Override... |
| 118 |
|
public String[] next() { |
| 119 |
9
|
if (!hasNext()) { |
| 120 |
1
|
throw new NoSuchElementException(); |
| 121 |
|
} |
| 122 |
|
|
| 123 |
8
|
return reader.next(); |
| 124 |
|
} |
| 125 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 126 |
0
|
@Override... |
| 127 |
|
public void remove() { |
| 128 |
0
|
throw new UnsupportedOperationException(); |
| 129 |
|
} |
| 130 |
|
} |
| 131 |
|
|
|
|
|
| 86.4% |
Uncovered Elements: 3 (22) |
Complexity: 9 |
Complexity Density: 0.69 |
|
| 132 |
|
private static final class RecordReader { |
| 133 |
|
private final BufferedReader reader; |
| 134 |
|
private String[] next; |
| 135 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 136 |
0
|
private RecordReader(final InputStream in) {... |
| 137 |
0
|
this(new InputStreamReader(in)); |
| 138 |
|
} |
| 139 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 140 |
6
|
private RecordReader(final Reader in) {... |
| 141 |
6
|
reader = new BufferedReader(in); |
| 142 |
6
|
next = readNext(); |
| 143 |
|
} |
| 144 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 145 |
12
|
private String[] next() {... |
| 146 |
12
|
final String[] ret = next; |
| 147 |
|
|
| 148 |
12
|
next = readNext(); |
| 149 |
|
|
| 150 |
12
|
return ret; |
| 151 |
|
} |
| 152 |
|
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 153 |
18
|
private String[] readNext() {... |
| 154 |
18
|
try { |
| 155 |
18
|
final String line = reader.readLine(); |
| 156 |
18
|
return (line == null ? null : line.split("\t")); |
| 157 |
|
} catch (final Exception e) { |
| 158 |
0
|
throw new RuntimeException(e); |
| 159 |
|
} |
| 160 |
|
} |
| 161 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 162 |
34
|
private boolean hasNext() {... |
| 163 |
34
|
return next != null; |
| 164 |
|
} |
| 165 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 166 |
27
|
private String[] peek() {... |
| 167 |
27
|
return next; |
| 168 |
|
} |
| 169 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 170 |
6
|
private void close() throws Exception {... |
| 171 |
6
|
reader.close(); |
| 172 |
|
|
| 173 |
|
} |
| 174 |
|
} |
| 175 |
|
|
|
|
|
| 82.6% |
Uncovered Elements: 4 (23) |
Complexity: 9 |
Complexity Density: 0.75 |
|
| 176 |
|
private static final class OutputStreamOutput implements Output { |
| 177 |
|
private final PrintWriter out; |
| 178 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 179 |
0
|
private OutputStreamOutput(final OutputStream out) {... |
| 180 |
0
|
this(new OutputStreamWriter(out)); |
| 181 |
|
} |
| 182 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 183 |
6
|
private OutputStreamOutput(final Writer out) {... |
| 184 |
6
|
this.out = new PrintWriter(out); |
| 185 |
|
} |
| 186 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 187 |
6
|
public void close() throws Exception {... |
| 188 |
6
|
out.close(); |
| 189 |
|
} |
| 190 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 191 |
10
|
@Override... |
| 192 |
|
public void collect(String[] record) throws Exception { |
| 193 |
10
|
out.println(_join(record, "\t")); |
| 194 |
|
} |
| 195 |
|
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
| 196 |
10
|
private static String _join(final String[] record, final String separator) {... |
| 197 |
10
|
if (record == null || record.length == 0) { |
| 198 |
0
|
return ""; |
| 199 |
|
} |
| 200 |
10
|
final StringBuilder sb = new StringBuilder(); |
| 201 |
30
|
for (int i = 0; i < record.length; i++) { |
| 202 |
20
|
if (i > 0) { |
| 203 |
10
|
sb.append(separator); |
| 204 |
|
} |
| 205 |
20
|
sb.append(record[i]); |
| 206 |
|
} |
| 207 |
10
|
return sb.toString(); |
| 208 |
|
} |
| 209 |
|
} |
| 210 |
|
} |