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

Method testStoreComplexDataWithNull

test/org/apache/pig/test/TestStore.java:268–322  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

266 }
267
268 @Test
269 public void testStoreComplexDataWithNull() throws Exception {
270 Tuple inputTuple = GenRandomData.genRandSmallBagTextTupleWithNulls(new Random(), 10, 100);
271 inpDB = DefaultBagFactory.getInstance().newDefaultBag();
272 inpDB.add(inputTuple);
273 storeAndCopyLocally(inpDB);
274 PigStorage ps = new PigStorage("\t");
275 BufferedReader br = new BufferedReader(new FileReader(outputFileName));
276 for(String line=br.readLine();line!=null;line=br.readLine()){
277 System.err.println("Complex data: ");
278 System.err.println(line);
279 String[] flds = line.split("\t",-1);
280 Tuple t = new DefaultTuple();
281
282 ResourceFieldSchema stringfs = new ResourceFieldSchema();
283 stringfs.setType(DataType.CHARARRAY);
284 ResourceFieldSchema intfs = new ResourceFieldSchema();
285 intfs.setType(DataType.INTEGER);
286 ResourceFieldSchema bytefs = new ResourceFieldSchema();
287 bytefs.setType(DataType.BYTEARRAY);
288
289 ResourceSchema tupleSchema = new ResourceSchema();
290 tupleSchema.setFields(new ResourceFieldSchema[]{stringfs, intfs});
291 ResourceFieldSchema tuplefs = new ResourceFieldSchema();
292 tuplefs.setSchema(tupleSchema);
293 tuplefs.setType(DataType.TUPLE);
294
295 ResourceSchema bagSchema = new ResourceSchema();
296 bagSchema.setFields(new ResourceFieldSchema[]{tuplefs});
297 ResourceFieldSchema bagfs = new ResourceFieldSchema();
298 bagfs.setSchema(bagSchema);
299 bagfs.setType(DataType.BAG);
300
301 ResourceSchema mapSchema = new ResourceSchema();
302 mapSchema.setFields(new ResourceFieldSchema[]{bytefs});
303 ResourceFieldSchema mapfs = new ResourceFieldSchema();
304 mapfs.setSchema(mapSchema);
305 mapfs.setType(DataType.MAP);
306
307 t.append(flds[0].compareTo("")!=0 ? ps.getLoadCaster().bytesToBag(flds[0].getBytes(), bagfs) : null);
308 t.append(flds[1].compareTo("")!=0 ? new DataByteArray(flds[1].getBytes()) : null);
309 t.append(flds[2].compareTo("")!=0 ? ps.getLoadCaster().bytesToCharArray(flds[2].getBytes()) : null);
310 t.append(flds[3].compareTo("")!=0 ? ps.getLoadCaster().bytesToDouble(flds[3].getBytes()) : null);
311 t.append(flds[4].compareTo("")!=0 ? ps.getLoadCaster().bytesToFloat(flds[4].getBytes()) : null);
312 t.append(flds[5].compareTo("")!=0 ? ps.getLoadCaster().bytesToInteger(flds[5].getBytes()) : null);
313 t.append(flds[6].compareTo("")!=0 ? ps.getLoadCaster().bytesToLong(flds[6].getBytes()) : null);
314 t.append(flds[7].compareTo("")!=0 ? ps.getLoadCaster().bytesToMap(flds[7].getBytes(), mapfs) : null);
315 t.append(flds[8].compareTo("")!=0 ? ps.getLoadCaster().bytesToTuple(flds[8].getBytes(), tuplefs) : null);
316 t.append(flds[9].compareTo("")!=0 ? ps.getLoadCaster().bytesToBoolean(flds[9].getBytes()) : null);
317 t.append(flds[10].compareTo("")!=0 ? ps.getLoadCaster().bytesToDateTime(flds[10].getBytes()) : null);
318 t.append(flds[11].compareTo("")!=0 ? ps.getLoadCaster().bytesToCharArray(flds[10].getBytes()) : null);
319 assertEquals(inputTuple, t);
320 }
321 br.close();
322 }
323 @Test
324 public void testBinStorageGetSchema() throws IOException, ParserException {
325 String input[] = new String[] { "hello\t1\t10.1", "bye\t2\t20.2" };

Callers

nothing calls this directly

Calls 15

storeAndCopyLocallyMethod · 0.95
setTypeMethod · 0.95
setFieldsMethod · 0.95
setSchemaMethod · 0.95
appendMethod · 0.95
splitMethod · 0.80
addMethod · 0.65
bytesToBagMethod · 0.65
getLoadCasterMethod · 0.65
getBytesMethod · 0.65
bytesToCharArrayMethod · 0.65

Tested by

no test coverage detected