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

Method exec

src/org/apache/pig/builtin/TOP.java:326–382  ·  view source on GitHub ↗
(Tuple input)

Source from the content-addressed store, hash-verified

324 * @see org.apache.pig.EvalFunc#exec(org.apache.pig.data.Tuple)
325 */
326 @Override
327 public Tuple exec(Tuple input) throws IOException {
328 if (input == null || input.size() < 1) {
329 return null;
330 }
331 try {
332 DataBag bagOfIntermediates = (DataBag) input.get(0);
333 Iterator<Tuple> intermediateIterator = bagOfIntermediates.iterator();
334 if (!intermediateIterator.hasNext()) {
335 return null;
336 }
337 Tuple peekTuple = intermediateIterator.next();
338 if (peekTuple == null || peekTuple.size() < 3 ) return null;
339 int n = (Integer) peekTuple.get(0);
340 int fieldNum = (Integer) peekTuple.get(1);
341 DataBag inputBag = (DataBag) peekTuple.get(2);
342 boolean allInputBagsNull = true;
343
344 PriorityQueue<Tuple> store = new PriorityQueue<Tuple>(n + 1,
345 new TupleComparator(fieldNum, sortDesc));
346
347 if (inputBag != null) {
348 allInputBagsNull = false;
349 updateTop(store, n, inputBag);
350 }
351
352 while (intermediateIterator.hasNext()) {
353 Tuple t = intermediateIterator.next();
354 if (t == null || t.size() < 3 ) continue;
355 inputBag = (DataBag) t.get(2);
356 if (inputBag != null) {
357 allInputBagsNull = false;
358 updateTop(store, n, inputBag);
359 }
360 }
361
362 Tuple retTuple = mTupleFactory.newTuple(3);
363 retTuple.set(0, n);
364 retTuple.set(1,fieldNum);
365 DataBag outputBag = null;
366 if (!allInputBagsNull) {
367 outputBag = mBagFactory.newDefaultBag();
368 for (Tuple t : store) {
369 outputBag.add(t);
370 }
371 }
372 retTuple.set(2, outputBag);
373 if (log.isDebugEnabled()) {
374 if (randomizer.nextInt(1000) == 1) log.debug("outputting "+retTuple.toDelimitedString("\t"));
375 }
376 return retTuple;
377 } catch (ExecException e) {
378 throw new RuntimeException("ExecException executing function: ", e);
379 } catch (Exception e) {
380 throw new RuntimeException("General Exception executing function: ", e);
381 }
382 }
383

Callers

nothing calls this directly

Calls 13

sizeMethod · 0.95
getMethod · 0.95
iteratorMethod · 0.95
setMethod · 0.95
addMethod · 0.95
toDelimitedStringMethod · 0.95
debugMethod · 0.80
newTupleMethod · 0.65
hasNextMethod · 0.45
nextMethod · 0.45
updateTopMethod · 0.45
newDefaultBagMethod · 0.45

Tested by

no test coverage detected