1 22 23 package org.xquark.mediator.plan; 24 25 import java.util.ArrayList ; 26 import java.util.HashMap ; 27 28 import org.xquark.mediator.DOMUtils.*; 29 import org.xquark.mediator.decomposer.Utils; 30 import org.xquark.mediator.runtime.MediatorException; 31 import org.xquark.xquery.parser.ListOpCompExpression; 32 import org.xquark.xquery.parser.XQueryException; 33 import org.xquark.xquery.parser.XQueryExpression; 34 import org.xquark.xquery.parser.hinttree.HintTree; 35 import org.xquark.xquery.parser.util.Constants; 36 37 public class OpSubQuery extends OpMult { 38 private static final String RCSRevision = "$Revision: 1.17 $"; 42 private static final String RCSName = "$Name: $"; 43 private int[] locations = null; 47 private int[] idlocations = null; 48 private boolean pivot = false; 50 private boolean imbricated = false; 51 protected int ordertype = ORDER_SERIALIZATION; 52 protected int outertype = HintTree.NESTED_TYPE; 53 protected ArrayList mergeRestrictions = null; 54 protected ArrayList outsideRestrictions = null; 55 56 62 63 public OpSubQuery(ExecutionPlan plan, XQueryExpression expression, Operator[] children, boolean pivot, boolean imbricated, ArrayList mergeRestrictions, ArrayList outsideRestrictions) throws MediatorException { 64 super(plan, expression, children); 65 ordertype = ORDER_PARALLELIZATION; 66 this.pivot = pivot; 67 this.imbricated = imbricated; 68 this.outertype = HintTree.MERGE_TYPE; 69 this.mergeRestrictions = mergeRestrictions; 70 this.outsideRestrictions = outsideRestrictions; 71 init(); 72 } 73 74 public OpSubQuery(ExecutionPlan plan, XQueryExpression expression, Operator[] children, boolean pivot, boolean imbricated) throws MediatorException { 75 super(plan, expression, children); 76 ordertype = ORDER_PARALLELIZATION; 77 this.pivot = pivot; 78 this.imbricated = imbricated; 79 init(); 80 } 81 82 public boolean getPivot() { 83 return this.pivot; 84 } 85 public boolean getImbricated() { 87 return this.imbricated; 88 } 89 public int getOuterType() { 91 return this.outertype; 92 } 93 94 public ArrayList getMergeRestrictions() { 95 return this.mergeRestrictions; 96 } 97 public ArrayList getOutsideRestrictions() { 98 return this.outsideRestrictions; 99 } 100 101 public void init() throws MediatorException { 102 if (childrenOperator == null) 107 return; 108 this.resetPaths(); 109 if (this.paths == null || this.paths.isEmpty()) { 110 for (int i = 0; i < childrenOperator.length; i++) { 111 Operator operatori = childrenOperator[i]; 112 operatori.setParentOperator(this); 113 if (i != 0 && pivot && operatori.getDepends()) 114 operatori.setPrepared(); 115 addPaths(operatori.getPaths()); 116 } 117 } 118 size = childrenOperator[0].getSize(); idsize = childrenOperator[0].getIdSize(); 120 locations = new int[childrenOperator.length - 1]; 121 idlocations = new int[childrenOperator.length - 1]; 122 for (int k = 1; k < childrenOperator.length; k++) { 123 locations[k - 1] = size; 124 idlocations[k - 1] = idsize; 125 size += childrenOperator[k].getSize(); idsize += childrenOperator[k].getIdSize(); 127 } 128 } 129 130 public int[] getIdLocations() { 131 return idlocations; 132 } 133 public int[] getLocations() { 134 return locations; 135 } 136 137 143 public boolean isSource() { 144 return false; 145 } 146 147 151 public ArrayList getSources() { 152 165 return null; 166 } 167 168 protected boolean shareSameSources() { 169 174 return false; 175 } 176 177 181 public void accept(OperatorVisitor visitor) throws MediatorException { 182 visitor.visit(this); 183 } 184 185 191 public ResultSet executeQuery(DynamicContext context) throws MediatorException { 192 try { 193 OperatorRunnable[] runnables = new OperatorRunnable[childrenOperator.length]; 194 if (ordertype == ORDER_SERIALIZATION) { 195 for (int i = 0; i < childrenOperator.length; i++) { 196 OperatorRunnable ori = childrenOperator[i].getOperatorRunnable(context); 197 runnables[i] = ori; 198 if (!childrenOperator[i].getDepends() || i == 0 || this.outertype == HintTree.MERGE_TYPE) 199 ori.run(); 200 } 201 } else if (ordertype == ORDER_PARALLELIZATION) { 202 Thread [] threads = new Thread [childrenOperator.length]; 203 for (int i = 0; i < childrenOperator.length; i++) { 204 OperatorRunnable ori = childrenOperator[i].getOperatorRunnable((DynamicContext)context.clone()); 205 runnables[i] = ori; 206 if (!childrenOperator[i].getDepends() || i == 0 || this.outertype == HintTree.MERGE_TYPE) { 207 threads[i] = new Thread (ori); 208 threads[i].start(); 209 } 210 } 211 for (int i = 0; i < threads.length; i++) { 213 Thread thread = threads[i]; 214 if (thread != null && thread.isAlive()) 215 thread.join(); 216 } 217 } 218 return getResultSet(context, runnables); 219 } catch (InterruptedException e) { 220 throw new MediatorException("AlgMultOp.executeQuery: " + e.getMessage(), e); 221 } 222 } 223 224 protected ResultSet getResultSet(DynamicContext context, OperatorRunnable[] children) throws MediatorException { 225 return new SubQueryNoPivotResultSet(this, context, children, pivot, imbricated); 226 } 227 228 232 public String toCompleteString(int indent) { 236 StringBuffer buf = new StringBuffer (); 237 buf.append(Utils.makeIndent(indent) + "<" + getClass().getName() + " hasPivot=\"" + pivot + "\" isImbricated=\"" + this.imbricated + " size=" + size + " id size=" + idsize + " isLet=\"" + islet + "\" valueDepends=\"" + valueDepends + "\" whereDepends=\"" + whereDepends + "\">\n"); 238 buf.append(Utils.makeIndent(indent + 1) + "<mergeRestrictions>\n"); 239 buf.append(Utils.makeIndent(indent + 2) + mergeRestrictions + "\n"); 240 buf.append(Utils.makeIndent(indent + 1) + "</mergeRestrictions>\n"); 241 buf.append(Utils.makeIndent(indent + 1) + "<outsideRestrictions>\n"); 242 buf.append(Utils.makeIndent(indent + 2) + outsideRestrictions + "\n"); 243 buf.append(Utils.makeIndent(indent + 1) + "</outsideRestrictions>\n"); 244 256 if (paths != null) { 257 buf.append(Utils.makeIndent(indent + 1) + "<Paths>\n"); 258 for (int i = 0; i < paths.size(); i++) { 259 buf.append(Utils.makeIndent(indent + 2) + "<Path>" + paths.get(i) + "</Path>\n"); 260 } 261 buf.append(Utils.makeIndent(indent + 1) + "</Paths>\n"); 262 } 263 277 for (int i = 0; i < childrenOperator.length; i++) { 278 buf.append(Utils.makeIndent(indent + 1) + "<Element" + (i + 1) + ">\n"); 279 buf.append(childrenOperator[i].toCompleteString(indent + 2)); 280 buf.append(Utils.makeIndent(indent + 1) + "</Element" + (i + 1) + ">\n"); 281 } 282 buf.append(Utils.makeIndent(indent) + "</" + getClass().getName() + ">\n"); 283 return buf.toString(); 284 } 285 } 286 287 abstract class SubQueryResultSet extends MultResultSet { 288 private static final String RCSRevision = "$Revision: 1.17 $"; 292 private static final String RCSName = "$Name: $"; 293 protected int[] locations = null; 297 protected int[] idlocations = null; 298 protected boolean pivot; 299 protected boolean imbricated; 300 306 public SubQueryResultSet(OpSubQuery operator, DynamicContext context, OperatorRunnable[] runnables, boolean pivot, boolean imbricated) throws MediatorException { 308 super(operator, context); 309 this.children = runnables; 310 this.pivot = pivot; 317 this.imbricated = imbricated; 318 this.locations = operator.getLocations(); 320 this.idlocations = operator.getIdLocations(); 321 } 322 323 331 } 332 333 class SubQueryNoPivotResultSet extends SubQueryResultSet { 334 private static final String RCSRevision = "$Revision: 1.17 $"; 338 private static final String RCSName = "$Name: $"; 339 340 private int index = 0; 341 private boolean allLets = true; 343 344 private ResultSet pivotResultSet = null; 345 private ArrayList allTuples = null; 346 private int[] indexes = null; 347 private Tuple tuplepivot = null; 348 private boolean is_used = false; 349 private ArrayList currentTuples = null; 350 private int size = -1; 351 private boolean endindex = false; 352 private int outertype = HintTree.NESTED_TYPE; 353 private SortedKeyMap tm0 = null; 354 private SortedKeyMap tm1 = null; 355 private HashMap pivotindex = null; 356 private int indexindex = 0; 357 358 public SubQueryNoPivotResultSet(OpSubQuery operator, DynamicContext context, OperatorRunnable[] children, boolean pivot, boolean imbricated) throws MediatorException { 359 super(operator, context, children, pivot, imbricated); 360 init(); 361 } 362 363 protected void init() throws MediatorException { 364 size = children.length; 365 if (pivot) { 366 pivotResultSet = children[0].getResultSet(); 367 if (pivotResultSet == null || !pivotResultSet.hasNext()) { 368 pivotResultSet.close(); 369 setFinishedWhenEmpty(); 370 for (int i = 1; i < size; i++) 371 if (!children[i].getOperator().getDepends()) 372 children[i].getResultSet().close(); 373 return; 375 } 376 outertype = ((OpSubQuery) operator).getOuterType(); 377 if (outertype == HintTree.NESTED_TYPE) { 378 allTuples = new ArrayList (size - 1); 379 indexes = new int[size - 1]; 380 for (int i = 1; i < size; i++) { 381 indexes[i - 1] = -1; 382 if (allLets && (!children[i].getOperator().isLet() || children[i].getOperator().getWhereDepends())) 383 allLets = false; 384 } 385 } else { 386 allTuples = new ArrayList (size); 387 indexes = new int[size]; 388 indexes[0] = -1; 389 for (int i = 1; i < size; i++) { 390 indexes[i] = -1; 391 if (allLets && (!children[i].getOperator().isLet() || children[i].getOperator().getWhereDepends())) 392 allLets = false; 393 } 394 } 395 } 396 } 397 398 406 protected void evaluate(boolean non_blocking) throws MediatorException { 407 408 410 412 if (pivot) { 413 if (outertype == HintTree.NESTED_TYPE) { 414 boolean added = false; 415 while (!added) { 416 if (endindex) { 417 endindex = false; 418 if (is_used == false && (imbricated || allLets)) { 419 Tuple newtuple = new Tuple(operator); 420 newtuple.appendTuple(tuplepivot); 421 newtuple.fillIdentifiers(0, tuplepivot); 422 buftuples.add(newtuple); 423 if (!added && non_blocking) 424 added = true; 425 tuplepivot = null; 426 continue; 427 } 428 tuplepivot = null; 429 } 430 if (tuplepivot == null) { 431 if (pivotResultSet.hasNext()) { 432 tuplepivot = pivotResultSet.next(); 433 is_used = false; 434 index = 0; 435 } else { 436 pivotResultSet.close(); 437 setFinishedWhenEmpty(); 438 return; 439 } 440 } 441 Tuple tuple = null; 442 Operator operatori = children[index + 1].getOperator(); 443 if (operatori.getDepends()) { 444 ResultSet subresultset = children[index + 1].getResultSet(); 445 if (subresultset == null) { 446 children[index + 1].getContext().addCurrentTuple(tuplepivot); 447 children[index + 1].run(); 448 subresultset = children[index + 1].getResultSet(); 449 } 450 if (subresultset != null && subresultset.hasNext()) { tuple = subresultset.next(); 452 } else { children[index + 1].getContext().deleteCurrentTuple(tuplepivot); 454 if (subresultset != null) 455 subresultset.close(); 456 allTuples.add(null); 457 children[index + 1].setResultSet(null); 458 if (index == size - 2) 459 endindex = true; 460 else 461 index++; 462 continue; 463 } 464 } else { if (indexes[index] == -1) { ResultSet subresultset = children[index + 1].getResultSet(); 467 if (subresultset.hasNext()) { tuple = subresultset.next(); 469 if (currentTuples == null) 470 currentTuples = new ArrayList (); 471 currentTuples.add(tuple); 472 } else { subresultset.close(); 474 allTuples.add(currentTuples); 475 currentTuples = null; 476 indexes[index] = 0; 477 if (index == size - 2) 478 endindex = true; 479 else 480 index++; 481 continue; 482 } 483 } else { if (indexes[index] == 0) 485 currentTuples = (ArrayList ) allTuples.get(index); 486 if (indexes[index] == ((currentTuples == null) ? 0 : currentTuples.size())) { 487 indexes[index] = 0; 488 if (index == size - 2) 489 endindex = true; 490 else 491 index++; 492 continue; 493 } 494 if (currentTuples != null) 495 tuple = (Tuple) currentTuples.get(indexes[index]); 496 else 497 tuple = null; 498 indexes[index]++; 499 } 500 } 501 502 Tuple newtuple = new Tuple(operator); 503 newtuple.appendTuple(tuplepivot); 504 newtuple.appendTupleAtIndex(locations[index], tuple); 505 newtuple.fillIdentifiers(0, tuplepivot); 506 newtuple.fillIdentifiers(idlocations[index], tuple); 507 if (newtuple != null) { 508 buftuples.add(newtuple); 509 if (!added && non_blocking) 510 added = true; 511 is_used = true; 512 } 513 } 514 } else if (outertype == HintTree.MERGE_TYPE) { 515 if (allTuples.isEmpty()) { 518 pivotindex = new HashMap (); 519 ArrayList tmplist = new ArrayList (); 520 int tmpint = 0; 521 while (pivotResultSet.hasNext()) { 522 Tuple tmptuple = pivotResultSet.next(); 523 tmplist.add(tmptuple); 524 pivotindex.put(tmptuple, new Integer (tmpint++)); 525 } 526 allTuples.add(tmplist); 529 indexes[0] = 0; 530 index = 1; 531 indexindex = 0; 532 } 533 boolean added = false; 535 while (!added) { 536 if (endindex) { 537 endindex = false; 538 indexes[0]++; 539 if (is_used == false && (imbricated || allLets)) { 540 Tuple newtuple = new Tuple(operator); 541 newtuple.appendTuple(tuplepivot); 542 newtuple.fillIdentifiers(0, tuplepivot); 543 buftuples.add(newtuple); 544 if (!added && non_blocking) 545 added = true; 546 tuplepivot = null; 547 continue; 548 } 549 tuplepivot = null; 550 } 551 if (tuplepivot == null) { 552 if (indexes[0] < ((ArrayList ) allTuples.get(0)).size()) { 553 tuplepivot = (Tuple) ((ArrayList ) allTuples.get(0)).get(indexes[0]); 554 is_used = false; 555 index = 1; 556 } else { 557 setFinishedWhenEmpty(); 558 pivotResultSet.close(); 559 return; 560 } 561 } 562 if (children[index].getOperator().getDepends()) { 564 if (indexes[index] == -1) { ResultSet subalgi = children[index].getResultSet(); 568 if (!subalgi.hasNext()) { 569 subalgi.close(); 570 allTuples.add(null); 572 indexes[index] = 0; 574 continue; 575 } 576 while (subalgi.hasNext()) { 577 Tuple tuplei = subalgi.next(); 578 } 579 tm0 = children[0].getResultSet().getIndex(indexindex); 581 tm0.makeIterator(); 582 tm1 = children[index].getResultSet().getIndex(0); 583 tm1.makeIterator(); 584 subalgi.close(); 585 586 HashMap tmpmap = new HashMap (); 587 588 ArrayList mergeRestrictions = (ArrayList ) ((ArrayList ) ((OpSubQuery) operator).getMergeRestrictions()).get(indexindex); 590 XQueryExpression outsideRestrictions = (XQueryExpression) ((ArrayList ) ((OpSubQuery) operator).getOutsideRestrictions()).get(indexindex); 591 indexindex++; 593 int size = mergeRestrictions.size(); 594 ArrayList leftstrings = new ArrayList (size); 595 ArrayList rightstrings = new ArrayList (size); 596 for (int i = 0; i < size; i++) { 597 leftstrings.add(((ListOpCompExpression) mergeRestrictions.get(i)).getExpression1().getStringValue()); 598 rightstrings.add(((ListOpCompExpression) mergeRestrictions.get(i)).getExpression2().getStringValue()); 599 } 600 int operatorNEQ = ((ListOpCompExpression) mergeRestrictions.get(size - 1)).getOperator(); 601 ArrayList leftbuffer = new ArrayList (); 602 ArrayList rightbuffer = new ArrayList (); 603 Tuple left = null; 604 Tuple right = null; 605 int leftindex = -1; 606 Tuple leftfront = null; 607 Tuple rightfront = null; 608 Tuple nextright = null; 609 610 if (operatorNEQ == 0) { 611 while (true) { 612 if (left == null || right == null) 613 if (!tm0.hasNext() || !tm1.hasNext()) { 614 break; 615 } 616 if (left == null) { 618 left = tm0.next(); 619 } 620 if (right == null) { 621 right = tm1.next(); 622 } 623 while (left != null && right != null) { 624 int num = 0; 625 while (num < size) { 626 int res = DOMUtils.simpleCompareNodeValue(left.getPath((String ) leftstrings.get(num)),right.getPath((String ) rightstrings.get(num))); 627 if (res == 0) 628 num++; 629 else { 630 if (res < 0) { 631 if (tm0.hasNext()) { 632 left = tm0.next(); 633 } else 634 left = null; 635 } else if (res > 0) { 636 if (tm1.hasNext()) { 637 right = tm1.next(); 638 } else 639 right = null; 640 } 641 break; 642 } 643 } 644 if (num == size) 645 break; 646 } 647 if (left == null || right == null) { 648 continue; 649 } 650 leftbuffer.clear(); 652 leftbuffer.add(left); 653 rightbuffer.clear(); 654 rightbuffer.add(right); 655 while (true) { 657 leftfront = null; 658 if (tm0.hasNext()) { 659 leftfront = tm0.next(); 660 int num = 0; 661 while (num < size) { 662 int res = DOMUtils.simpleCompareNodeValue(left.getPath((String ) leftstrings.get(num)),leftfront.getPath((String ) leftstrings.get(num))); 663 if (res == 0) 664 num++; 665 else 666 break; 667 } 668 if (num == size) { 669 leftbuffer.add(leftfront); 670 left = leftfront; 671 } else 672 break; 673 } else 674 break; 675 676 } 677 while (true) { 679 rightfront = null; 680 if (tm1.hasNext()) { 681 rightfront = tm1.next(); 682 int num = 0; 683 while (num < size) { 684 int res = DOMUtils.simpleCompareNodeValue(right.getPath((String ) rightstrings.get(num)),rightfront.getPath((String ) rightstrings.get(num))); 685 if (res == 0) 686 num++; 687 else 688 break; 689 } 690 if (num == size) { 691 rightbuffer.add(rightfront); 692 right = rightfront; 693 } else { 694 break; 695 } 696 } else 697 break; 698 } 699 for (int i = 0; i < leftbuffer.size(); i++) { 701 for (int j = 0; j < rightbuffer.size(); j++) { 702 if (outsideRestrictions != null) { 704 ArrayList tmpList = new ArrayList (); 705 tmpList.addAll(context.getCurrentTuples()); 706 tmpList.add(leftbuffer.get(i)); 707 tmpList.add(rightbuffer.get(j)); 708 try { 709 EvaluationVisitor visitor = new EvaluationVisitor(operator.getPlan().getSchemaManager(), tmpList); 710 outsideRestrictions.accept(visitor); 711 if (!visitor.getVerdict()) 712 continue; 713 } catch (XQueryException e) { 714 throw new MediatorException(e.getMessage(), e); 715 } 716 } 717 Integer tmpint = (Integer ) pivotindex.get(leftbuffer.get(i)); 718 ArrayList tmplist = (ArrayList ) tmpmap.get(tmpint); 719 if (tmplist == null) { 720 tmplist = new ArrayList (); 721 tmpmap.put(tmpint, tmplist); 722 } 723 tmplist.add(rightbuffer.get(j)); 724 } 726 } 727 left = leftfront; 728 right = rightfront; 729 } 730 } else { 732 while (true) { 733 if (!tm0.hasNext()) { 734 break; 735 } else if (right == null && nextright == null && !tm1.hasNext() && rightbuffer.isEmpty()) { 736 break; 737 } 738 int num; 739 if (left == null) { 741 left = tm0.next(); 742 } else { 743 leftfront = tm0.next(); 744 num = 0; 745 while (num < size - 1) { 746 int res = DOMUtils.simpleCompareNodeValue(left.getPath((String ) leftstrings.get(num)),leftfront.getPath((String ) leftstrings.get(num))); 747 if (res == 0) 748 num++; 749 else 750 break; 751 } 752 if (num != size - 1) { 753 rightbuffer.clear(); 754 } 755 left = leftfront; 756 } 757 if (right == null) { 758 if (nextright != null) { 759 right = nextright; 760 nextright = null; 761 } else if (tm1.hasNext()) { 762 right = tm1.next(); 763 } 764 } 765 boolean add = false; 767 while (right != null) { 768 num = 0; 769 while (num < size) { 770 int res = DOMUtils.simpleCompareNodeValue(left.getPath((String ) leftstrings.get(num)), right.getPath((String ) rightstrings.get(num))); 771 if (num != size - 1) { 772 if (res == 0) 773 num++; 774 else { 775 if (res < 0) { 776 num = size + 1; 777 break; 778 } else if (res > 0) { 779 if (tm1.hasNext()) { 780 right = tm1.next(); 781 } else 782 right = null; 783 } 784 break; 785 } 786 } else { 787 if ((res == 0 && (operatorNEQ == Constants.GEQ_COMPOP || operatorNEQ == Constants.LEQ_COMPOP)) || (res < 0 && (operatorNEQ == Constants.LT_COMPOP || operatorNEQ == Constants.LEQ_COMPOP)) || (res > 0 && (operatorNEQ == Constants.GEQ_COMPOP || operatorNEQ == Constants.GT_COMPOP))) { 788 num++; 789 } else { 790 num = size + 1; 791 break; 792 } 793 } 794 } 795 if (num == size) { 796 add = true; 797 rightbuffer.add(right); 798 break; 799 } 800 if (num > size) 801 break; 802 } 803 804 if (rightbuffer.isEmpty()) { 805 continue; 806 } 807 if (add) { 809 rightfront = nextright; 810 while (true) { 811 if (rightfront == null) 812 if (tm1.hasNext()) { 813 rightfront = tm1.next(); 814 } 815 if (rightfront != null) { 816 num = 0; 817 while (num < size) { 818 if (num != size - 1) { 819 int res = DOMUtils.simpleCompareNodeValue(right.getPath((String ) rightstrings.get(num)), rightfront.getPath((String ) rightstrings.get(num))); 820 if (res == 0) 821 num++; 822 else { 823 nextright = rightfront; 824 rightfront = null; 825 break; 826 } 827 } else { 828 int res = DOMUtils.simpleCompareNodeValue(left.getPath((String ) leftstrings.get(num)), rightfront.getPath((String ) rightstrings.get(num))); 829 if ((res == 0 && (operatorNEQ == Constants.GEQ_COMPOP || operatorNEQ == Constants.LEQ_COMPOP)) || (res < 0 && (operatorNEQ == Constants.LT_COMPOP || operatorNEQ == Constants.LEQ_COMPOP)) || (res > 0 && (operatorNEQ == Constants.GEQ_COMPOP || operatorNEQ == Constants.GT_COMPOP))) 830 num++; 831 else { 832 nextright = rightfront; 833 rightfront = null; 834 break; 835 } 836 } 837 } 838 if (num == size) { 839 rightbuffer.add(rightfront); 840 right = rightfront; 841 rightfront = null; 842 } else { 843 break; 844 } 845 } else 846 break; 847 } 848 right = rightfront; 849 } 850 for (int j = 0; j < rightbuffer.size(); j++) { 852 if (outsideRestrictions != null) { 854 ArrayList tmpList = new ArrayList (); 855 tmpList.addAll(context.getCurrentTuples()); 856 tmpList.add(left); 857 tmpList.add(rightbuffer.get(j)); 858 try { 859 EvaluationVisitor visitor = new EvaluationVisitor(operator.getPlan().getSchemaManager(), tmpList); 860 outsideRestrictions.accept(visitor); 861 if (!visitor.getVerdict()) 862 continue; 863 } catch (XQueryException e) { 864 throw new MediatorException(e.getMessage(), e); 865 } 866 } 867 Integer tmpint = (Integer ) pivotindex.get(left); 868 ArrayList tmplist = (ArrayList ) tmpmap.get(tmpint); 869 if (tmplist == null) { 870 tmplist = new ArrayList (); 871 tmpmap.put(tmpint, tmplist); 872 } 873 tmplist.add(rightbuffer.get(j)); 874 } 876 } 877 } 878 if (tmpmap.isEmpty()) 880 allTuples.add(null); 881 else 882 allTuples.add(tmpmap); 883 indexes[index] = 0; 885 } 886 if (indexes[index] == 0) { HashMap map = (HashMap ) allTuples.get(index); 888 if (map != null) { 889 ArrayList tmplist = (ArrayList ) map.get(new Integer (indexes[0])); 890 if (tmplist != null) { 891 for (int i = 0; i < tmplist.size(); i++) { 892 Tuple newtuple = new Tuple(operator); 893 newtuple.appendTuple(tuplepivot); 894 newtuple.appendTupleAtIndex(locations[index - 1], (Tuple) tmplist.get(i)); 895 newtuple.fillIdentifiers(0, tuplepivot); 896 newtuple.fillIdentifiers(idlocations[index - 1], (Tuple) tmplist.get(i)); 897 if (newtuple != null) { 898 buftuples.add(newtuple); 899 if (!added && non_blocking) 900 added = true; 901 is_used = true; 902 } 903 } 904 } 905 } 906 if (index == size - 1) 907 endindex = true; 908 else 909 index++; 910 } 911 continue; 912 } else { Tuple tuple = null; 914 if (indexes[index] == -1) { ResultSet subresultset = children[index].getResultSet(); 916 if (subresultset.hasNext()) { tuple = subresultset.next(); 918 if (currentTuples == null) 919 currentTuples = new ArrayList (); 920 currentTuples.add(tuple); 921 } else { subresultset.close(); 923 allTuples.add(currentTuples); 924 currentTuples = null; 925 indexes[index] = 0; 926 if (index == size - 1) 927 endindex = true; 928 else 929 index++; 930 continue; 931 } 932 } else { if (indexes[index] == 0) 934 currentTuples = (ArrayList ) allTuples.get(index); 935 if (indexes[index] == currentTuples.size()) { 936 indexes[index] = 0; 937 if (index == size - 1) 938 endindex = true; 939 else 940 index++; 941 continue; 942 } 943 tuple = (Tuple) currentTuples.get(indexes[index]); 944 indexes[index]++; 945 } 946 Tuple newtuple = new Tuple(operator); 947 newtuple.appendTuple(tuplepivot); 948 newtuple.appendTupleAtIndex(locations[index - 1], tuple); 949 newtuple.fillIdentifiers(0, tuplepivot); 950 newtuple.fillIdentifiers(idlocations[index - 1], tuple); 951 if (newtuple != null) { 952 buftuples.add(newtuple); 953 if (!added && non_blocking) 954 added = true; 955 is_used = true; 956 } 957 } 958 } 959 960 } 961 } else { while (index < children.length && !children[index].getResultSet().hasNext()) 963 index++; 964 while (index < children.length) { 965 if (children[index].getResultSet().hasNext()) { 966 Tuple tuple = children[index].getResultSet().next(); 967 Tuple newtuple = new Tuple(operator); 968 if (index == 0) 969 newtuple.appendTupleAtIndex(0, tuple); 970 else 971 newtuple.appendTupleAtIndex(locations[index - 1], tuple); 972 if (index == 0) 973 newtuple.fillIdentifiers(0, tuple); 974 else 975 newtuple.fillIdentifiers(idlocations[index - 1], tuple); 976 buftuples.add(newtuple); 977 978 if (non_blocking) { 979 if ((buftuples != null) && (!buftuples.isEmpty())) 980 break; 981 } 982 } else { 983 children[index].getResultSet().close(); 984 index++; 985 } 986 } 987 if (index == children.length) 988 setFinishedWhenEmpty(); 989 } 990 } 991 } 992 993 | Popular Tags |