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

Method testBzipInPig2

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

Tests the end-to-end writing and reading of a BZip file using absolute path with a trailing /.

()

Source from the content-addressed store, hash-verified

151 * Tests the end-to-end writing and reading of a BZip file using absolute path with a trailing /.
152 */
153 @Test
154 public void testBzipInPig2() throws Exception {
155 PigServer pig = new PigServer(cluster.getExecType(), properties);
156
157 File in = folder.newFile("junit-in.bz2");
158
159 File out = folder.newFile("junit-out.bz2");
160 out.delete();
161 String clusterOutput = Util.removeColon(out.getAbsolutePath());
162
163 CBZip2OutputStream cos =
164 new CBZip2OutputStream(new FileOutputStream(in));
165 for (int i = 1; i < 100; i++) {
166 StringBuffer sb = new StringBuffer();
167 sb.append(i).append("\n").append(-i).append("\n");
168 byte bytes[] = sb.toString().getBytes();
169 cos.write(bytes);
170 }
171 cos.close();
172
173 pig.registerQuery("AA = load '"
174 + Util.generateURI(in.getAbsolutePath(), pig.getPigContext())
175 + "';");
176 pig.registerQuery("A = foreach (group (filter AA by $0 > 0) all) generate flatten($1);");
177 pig.registerQuery("store A into '" + Util.encodeEscape(clusterOutput) + "/';");
178 FileSystem fs = FileSystem.get(ConfigurationUtil.toConfiguration(
179 pig.getPigContext().getProperties()));
180 FileStatus[] outputFiles = fs.listStatus(new Path(clusterOutput),
181 Util.getSuccessMarkerPathFilter());
182 FSDataInputStream is = fs.open(outputFiles[0].getPath());
183 CBZip2InputStream cis = new CBZip2InputStream(is, -1, out.length());
184
185 // Just a sanity check, to make sure it was a bzip file; we
186 // will do the value verification later
187 assertEquals(100, cis.read(new byte[100]));
188 cis.close();
189
190 pig.registerQuery("B = load '" + Util.encodeEscape(clusterOutput) + "';");
191
192 Iterator<Tuple> i = pig.openIterator("B");
193 HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
194 while (i.hasNext()) {
195 Integer val = DataType.toInteger(i.next().get(0));
196 map.put(val, val);
197 }
198
199 assertEquals(new Integer(99), new Integer(map.keySet().size()));
200
201 for (int j = 1; j < 100; j++) {
202 assertEquals(new Integer(j), map.get(j));
203 }
204 }
205
206 //see PIG-2391
207 @Test

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