use of java.io.StringWriter in project hive by apache.
the class TestGenericMR method testKVSplitMap.
public void testKVSplitMap() throws Exception {
final String in = "k1=v1,k2=v2\nk1=v2,k2=v3";
final String expected = "k1\tv1\nk2\tv2\nk1\tv2\nk2\tv3\n";
final StringWriter out = new StringWriter();
new GenericMR().map(new StringReader(in), out, new Mapper() {
public void map(String[] record, Output output) throws Exception {
for (final String kvs : record[0].split(",")) {
final String[] kv = kvs.split("=");
output.collect(new String[] { kv[0], kv[1] });
}
}
});
assertEquals(expected, out.toString());
}
use of java.io.StringWriter in project hive by apache.
the class TestGenericMR method testWordCountReduce.
public void testWordCountReduce() throws Exception {
final String in = "hello\t1\nhello\t2\nokay\t4\nokay\t6\nokay\t2";
final StringWriter out = new StringWriter();
new GenericMR().reduce(new StringReader(in), out, new Reducer() {
@Override
public void reduce(String key, Iterator<String[]> records, Output output) throws Exception {
int count = 0;
while (records.hasNext()) {
count += Integer.parseInt(records.next()[1]);
}
output.collect(new String[] { key, String.valueOf(count) });
}
});
final String expected = "hello\t3\nokay\t12\n";
assertEquals(expected, out.toString());
}
use of java.io.StringWriter in project hive by apache.
the class TestGenericMR method testIdentityMap.
public void testIdentityMap() throws Exception {
final String in = "a\tb\nc\td";
final StringWriter out = new StringWriter();
new GenericMR().map(new StringReader(in), out, identityMapper());
assertEquals(in + "\n", out.toString());
}
use of java.io.StringWriter in project hive by apache.
the class TestLlapWebServices method getURLResponseAsString.
private String getURLResponseAsString(String baseURL) throws IOException {
URL url = new URL(baseURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
StringWriter writer = new StringWriter();
IOUtils.copy(conn.getInputStream(), writer, "UTF-8");
return writer.toString();
}
use of java.io.StringWriter in project hive by apache.
the class InPlaceUpdate method getInPlaceProgressBar.
// [==================>>-----]
private String getInPlaceProgressBar(double percent) {
StringWriter bar = new StringWriter();
bar.append("[");
int remainingChars = PROGRESS_BAR_CHARS - 4;
int completed = (int) (remainingChars * percent);
int pending = remainingChars - completed;
for (int i = 0; i < completed; i++) {
bar.append("=");
}
bar.append(">>");
for (int i = 0; i < pending; i++) {
bar.append("-");
}
bar.append("]");
return bar.toString();
}
Aggregations