(Tuple tuple)
| 407 | * @see org.apache.pig.EvalFunc#exec(org.apache.pig.data.Tuple) |
| 408 | */ |
| 409 | @Override |
| 410 | public DataBag exec(Tuple tuple) throws IOException { |
| 411 | if (tuple == null || tuple.size() < 1) { |
| 412 | return null; |
| 413 | } |
| 414 | try { |
| 415 | DataBag bagOfIntermediates = (DataBag) tuple.get(0); |
| 416 | Iterator<Tuple> intermediateIterator = bagOfIntermediates.iterator(); |
| 417 | if (!intermediateIterator.hasNext()) { |
| 418 | return null; |
| 419 | } |
| 420 | Tuple peekTuple = intermediateIterator.next(); |
| 421 | if (peekTuple == null || peekTuple.size() < 3 ) return null; |
| 422 | int n = (Integer) peekTuple.get(0); |
| 423 | int fieldNum = (Integer) peekTuple.get(1); |
| 424 | DataBag inputBag = (DataBag) peekTuple.get(2); |
| 425 | boolean allInputBagsNull = true; |
| 426 | |
| 427 | PriorityQueue<Tuple> store = new PriorityQueue<Tuple>(n + 1, |
| 428 | new TupleComparator(fieldNum, sortDesc)); |
| 429 | if (inputBag != null) { |
| 430 | allInputBagsNull = false; |
| 431 | updateTop(store, n, inputBag); |
| 432 | } |
| 433 | |
| 434 | while (intermediateIterator.hasNext()) { |
| 435 | Tuple t = intermediateIterator.next(); |
| 436 | if (t == null || t.size() < 3 ) continue; |
| 437 | inputBag = (DataBag) t.get(2); |
| 438 | if (inputBag != null) { |
| 439 | allInputBagsNull = false; |
| 440 | updateTop(store, n, inputBag); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if (allInputBagsNull) { |
| 445 | return null; |
| 446 | } |
| 447 | |
| 448 | DataBag outputBag = mBagFactory.newDefaultBag(); |
| 449 | for (Tuple t : store) { |
| 450 | outputBag.add(t); |
| 451 | } |
| 452 | if (log.isDebugEnabled()) { |
| 453 | if (randomizer.nextInt(1000) == 1) for (Tuple t : outputBag) log.debug("outputting "+t.toDelimitedString("\t")); |
| 454 | } |
| 455 | return outputBag; |
| 456 | } catch (ExecException e) { |
| 457 | throw new RuntimeException("ExecException executing function: ", e); |
| 458 | } catch (Exception e) { |
| 459 | throw new RuntimeException("General Exception executing function: ", e); |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 |
nothing calls this directly
no test coverage detected