MCPcopy Create free account
hub / github.com/apache/pig / testBzipInPig

Method testBzipInPig

test/org/apache/pig/test/TestBZip.java:97–148  ·  view source on GitHub ↗

Tests the end-to-end writing and reading of a BZip file.

()

Source from the content-addressed store, hash-verified

95 * Tests the end-to-end writing and reading of a BZip file.
96 */
97 @Test
98 public void testBzipInPig() throws Exception {
99 PigServer pig = new PigServer(cluster.getExecType(), properties);
100
101 File in = folder.newFile("junit-in.bz2");
102
103 File out = folder.newFile("junit-out.bz2");
104 out.delete();
105 String clusterOutput = Util.removeColon(out.getAbsolutePath());
106
107 CBZip2OutputStream cos =
108 new CBZip2OutputStream(new FileOutputStream(in));
109 for (int i = 1; i < 100; i++) {
110 StringBuffer sb = new StringBuffer();
111 sb.append(i).append("\n").append(-i).append("\n");
112 byte bytes[] = sb.toString().getBytes();
113 cos.write(bytes);
114 }
115 cos.close();
116
117 pig.registerQuery("AA = load '"
118 + Util.generateURI(in.getAbsolutePath(), pig.getPigContext())
119 + "';");
120 pig.registerQuery("A = foreach (group (filter AA by $0 > 0) all) generate flatten($1);");
121 pig.registerQuery("store A into '" + Util.encodeEscape(clusterOutput) + "';");
122 FileSystem fs = FileSystem.get(ConfigurationUtil.toConfiguration(
123 pig.getPigContext().getProperties()));
124 FileStatus[] outputFiles = fs.listStatus(new Path(clusterOutput),
125 Util.getSuccessMarkerPathFilter());
126 FSDataInputStream is = fs.open(outputFiles[0].getPath());
127 CBZip2InputStream cis = new CBZip2InputStream(is, -1, out.length());
128
129 // Just a sanity check, to make sure it was a bzip file; we
130 // will do the value verification later
131 assertEquals(100, cis.read(new byte[100]));
132 cis.close();
133
134 pig.registerQuery("B = load '" + Util.encodeEscape(clusterOutput) + "';");
135
136 Iterator<Tuple> i = pig.openIterator("B");
137 HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
138 while (i.hasNext()) {
139 Integer val = DataType.toInteger(i.next().get(0));
140 map.put(val, val);
141 }
142
143 assertEquals(new Integer(99), new Integer(map.keySet().size()));
144
145 for (int j = 1; j < 100; j++) {
146 assertEquals(new Integer(j), map.get(j));
147 }
148 }
149
150 /**
151 * Tests the end-to-end writing and reading of a BZip file using absolute path with a trailing /.

Callers

nothing calls this directly

Calls 15

removeColonMethod · 0.95
writeMethod · 0.95
closeMethod · 0.95
registerQueryMethod · 0.95
generateURIMethod · 0.95
getPigContextMethod · 0.95
encodeEscapeMethod · 0.95
toConfigurationMethod · 0.95
readMethod · 0.95
closeMethod · 0.95
openIteratorMethod · 0.95

Tested by

no test coverage detected