| 1 package com.daffodilwoods.daffodildb.server.sql99.expression. 2 booleanvalueexpression.predicates; 3 4 import java.util.*; 5 6 import com.daffodilwoods.daffodildb.client.*; 7 import com.daffodilwoods.daffodildb.server.serversystem.*; 8 import com.daffodilwoods.daffodildb.server.sql99.common.*; 9 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*; 10 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*; 11 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*; 12 import com.daffodilwoods.daffodildb.server.sql99.expression. 13 booleanvalueexpression.*; 14 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.*; 15 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*; 16 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 17 import com.daffodilwoods.daffodildb.utils.field.*; 18 import com.daffodilwoods.database.resource.*; 19 import com.daffodilwoods.database.utility.P; 20 import com.daffodilwoods.database.resource.DException; 21 import com.daffodilwoods.daffodildb.utils.FieldUtility; 22 import com.daffodilwoods.daffodildb.utils.comparator.*; 23 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility; 24 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression. 25 queryexpression; 26 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression. 27 queryspecification.queryspecification; 28 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary. 29 subquery; 30 import com.daffodilwoods.daffodildb.server.sql99.expression. 31 AbstractValueExpression; 32 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression. 33 AbstractRowValueExpression; 34 35 40 public class comparisonpredicate 41 extends PredicateAbstract 42 implements predicate, Datatypes, TypeConstants, OperatorConstants, 43 ExecutionPlanConstants, SimpleConstants, JoinConditionTableGetter, 44 _ComparisonPredicate { 45 46 49 public valueexpressionwithoutboolean _valueexpressionwithoutboolean0; 50 51 55 public compop _compop1; 56 57 60 public rowvalueexpressionwithoutboolean _rowvalueexpressionwithoutboolean2; 61 62 65 protected int Operator = -1; 66 67 70 ColumnDetails[] columnDetails; 71 72 75 private Boolean subQueryFlag = Boolean.FALSE; 76 77 80 81 public comparisonpredicate() { 82 } 83 84 91 92 public comparisonpredicate(rowvalueexpressionwithoutboolean object1, 93 int Operator0, 94 valueexpressionwithoutboolean object2, 95 ColumnDetails[] columns) { 96 _rowvalueexpressionwithoutboolean2 = object1; 97 Operator = Operator0; 98 _valueexpressionwithoutboolean0 = object2; 99 columnDetails = columns; 100 } 101 102 115 116 public double getCost(long rowCount, boolean index) throws DException { 117 double result = 0; 118 switch (Operator) { 119 case EQUALTO: 120 result = checkForJoinPredicate() ? Math.sqrt(rowCount) : 121 rowCount * CostFactorConstants.EQUALTO / 100; 122 break; 123 case GREATERTHAN: 124 case LESSTHAN: 125 result = rowCount * CostFactorConstants.GREATERTHAN / 100; 126 break; 127 case GREATERTHANEQUALTO: 128 case LESSTHANEQUALTO: 129 result = rowCount * CostFactorConstants.GREATERTHANEQUALTO / 100; 130 } 131 result = index ? 132 rowCount * CostFactorConstants.INDEXPREDICATE / 100 : rowCount + result; 133 return result; 134 } 135 136 141 142 private boolean checkForJoinPredicate() throws DException { 143 return columnDetails.length == 2 && columnDetails[0].getType() == REFERENCE && 144 columnDetails[1].getType() == REFERENCE; 145 } 146 147 179 180 public _QualifiedBVE getQualifiedBVE(TableDetails[] tableDetails) throws 181 DException { 182 ArrayList uniqueTableList = getUniqueTableDetails(new ArrayList(), 183 columnDetails); 184 if (uniqueTableList.size() != 1) { 185 return new QualifiedBVE(null, BVEPlanMerger.getBooleanFactor(this)); 186 } 187 QualifiedBVE qualifiedBVE = getQualifiedBVEifBelongsToSingleTablePlan( 188 tableDetails, uniqueTableList); 189 if (qualifiedBVE == null) { 190 qualifiedBVE = new QualifiedBVE(null, BVEPlanMerger.getBooleanFactor(this)); 191 } 192 return qualifiedBVE; 193 } 194 195 208 209 private QualifiedBVE getQualifiedBVEifBelongsToSingleTablePlan(TableDetails[] 210 planTableDetails, ArrayList uniqueTableList) throws DException { 211 int length = planTableDetails.length; 212 TableDetails conditionTableDetails = (TableDetails) uniqueTableList.get(0); 213 QualifiedBVE qualifiedBVE = null; 214 for (int j = 0; j < length; j++) { 215 if (planTableDetails[j] == conditionTableDetails) { 216 BVESingleTablePlan bveSingleTablePlan = new BVESingleTablePlan( ( 217 booleanvalueexpression) BVEPlanMerger.getBooleanFactor(this), 218 conditionTableDetails); 219 BVESingleTablePlan[] bveSTPArray = new BVESingleTablePlan[] { 220 bveSingleTablePlan}; 221 qualifiedBVE = new QualifiedBVE(bveSTPArray, null); 222 return qualifiedBVE; 223 } 224 } 225 return null; 226 } 227 228 250 251 259 public int canUseForSeek() throws DException { 260 if (Operator == -1) { 261 Operator = getRespectiveOperator( (String ) _compop1.run(null)); 262 } 263 ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2. 264 getColumnDetails(); 265 ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0. 266 getColumnDetails(); 267 if (columnDetails1.length == 1 && columnDetails2.length == 1 && 268 Operator == EQUALTO) { 269 int type1 = columnDetails1[0].getType(); 270 int type2 = columnDetails2[0].getType(); 271 switch (type1) { 272 case TypeConstants.REFERENCE: 273 switch (type2) { 274 case TypeConstants.REFERENCE: 275 return TypeConstants.BOTHSIDESEEKABLE; 276 case TypeConstants.SCALARFUNCTION: 277 case TypeConstants.FUNCTIONAL: 278 case TypeConstants.CONSTANT: 279 case TypeConstants.CASEEXPRESSION: 280 case TypeConstants.USERFUNCTION: 281 return TypeConstants.LEFTSIDESEEKABLE; 282 case TypeConstants.GROUPING: 283 return TypeConstants.NOSEEK; 284 default: 285 throw new DException("DSE0", 286 new Object [] {"Invalid Case type1 [" + type1 + 287 "] type2 [" + type2 + "]"}); 288 289 } 290 case TypeConstants.SCALARFUNCTION: 291 case TypeConstants.FUNCTIONAL: 292 case TypeConstants.CONSTANT: 293 case TypeConstants.CASEEXPRESSION: 294 case TypeConstants.USERFUNCTION: 295 switch (type2) { 296 case TypeConstants.REFERENCE: 297 return TypeConstants.RIGHTSIDESEEKABLE; 298 case TypeConstants.SCALARFUNCTION: 299 case TypeConstants.FUNCTIONAL: 300 case TypeConstants.GROUPING: 301 case TypeConstants.CONSTANT: 302 case TypeConstants.USERFUNCTION: 303 return TypeConstants.NOSEEK; 304 default: 305 throw new DException("DSE0", 306 new Object [] {"Invalid Case type1 [" + type1 + 307 "] type2 [" + type2 + "]"}); 308 } 309 } 310 } 311 return TypeConstants.NOSEEK; 312 } 313 314 319 320 public int getPredicateType() throws DException { 321 if (Operator == -1) { 322 Operator = getRespectiveOperator( (String ) _compop1.run(null)); 323 } 324 if (Operator == NOTEQUALTO) { 325 return Operator; 326 } 327 if (columnDetails.length != 2) { 328 throw new DException("DSE3558", null); 329 } 330 ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2. 331 getColumnDetails(); 332 ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0. 333 getColumnDetails(); 334 if (columnDetails1[0].getType() == REFERENCE && 335 columnDetails2[0].getType() == CONSTANT) { 336 return Operator; 337 } 338 if (columnDetails1[0].getType() == REFERENCE && 339 columnDetails2[0].getType() == REFERENCE) { 340 return JOINCOMPARISONPREDICATE; 341 } 342 switch (Operator) { 343 case GREATERTHAN: 344 return LESSTHAN; 345 case LESSTHAN: 346 return GREATERTHAN; 347 case GREATERTHANEQUALTO: 348 return LESSTHANEQUALTO; 349 case LESSTHANEQUALTO: 350 return GREATERTHANEQUALTO; 351 } 352 return Operator; 353 } 354 355 365 366 public Object getValue() throws DException { 367 if (columnDetails == null) { 368 throw new DException("DSE3559", null); 369 } 370 ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2. 371 getColumnDetails(); 372 ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0. 373 getColumnDetails(); 374 375 376 if (columnDetails2[0].getType() == CONSTANT && 377 !columnDetails2[0].getUnderLyingReference() 378 && !_valueexpressionwithoutboolean0.checkForSubQuery()) { 379 FieldBase fieldBase1 = null; 380 try { 381 fieldBase1 = (FieldBase) _valueexpressionwithoutboolean0.run(null); 382 } 383 catch (NullPointerException ex1) { 384 if (columnDetails2[0].getType() == CONSTANT && 385 !columnDetails2[0].getUnderLyingReference() || 386 columnDetails2[0].getType() == FUNCTIONAL || 387 columnDetails2[0].getType() == SCALARFUNCTION || 388 columnDetails2[0].getType() == CASEEXPRESSION 389 ) { 390 throw new DException("DSE3804", null); 391 } 392 throw ex1; 393 } 394 fieldBase1.setDatatype(columnDetails1[0].getDatatype()); return fieldBase1; 396 } 397 398 if (columnDetails1[0].getType() == CONSTANT && 399 !columnDetails1[0].getUnderLyingReference() 400 && !_rowvalueexpressionwithoutboolean2.checkForSubQuery()) { 401 FieldBase fieldBase1 = null; 402 try { 403 fieldBase1 = (FieldBase) _rowvalueexpressionwithoutboolean2.run(null); 404 } 405 catch (NullPointerException ex) { 406 407 if (columnDetails1[0].getType() == CONSTANT && 408 !columnDetails1[0].getUnderLyingReference() || 409 columnDetails1[0].getType() == FUNCTIONAL || 410 columnDetails1[0].getType() == SCALARFUNCTION || 411 columnDetails1[0].getType() == CASEEXPRESSION 412 ) { 413 throw new DException("DSE3804", null); 414 } 415 throw ex; 416 } 417 fieldBase1.setDatatype(columnDetails2[0].getDatatype()); 418 return fieldBase1; 419 } 420 throw new DException("DSE3804", null); 421 } 422 423 430 431 private boolean checkForMultipleReference() throws DException { 432 453 return checkForMultipleReference2(columnDetails, new HashSet()); 454 } 455 456 472 public void setColumnPredicates(_AllColumnPredicates allColumnPredicates) throws 473 DException { 474 if (Operator == -1) { 475 Operator = getRespectiveOperator( (String ) _compop1.run(null)); 476 } 477 478 if (checkingForNotEqualTo() || subQueryFlag.booleanValue() || 479 checkForMultipleReference() || checkForOtherCases()) { 480 allColumnPredicates.addToNonIndex(BVEPlanMerger.getBooleanFactor(this)); 481 return; 482 } 483 SingleColumnPredicate singleColumnPredicate = new SingleColumnPredicate(); 484 int index = checkForJoinPredicate(allColumnPredicates.getTableName()); 485 if (index != -1) { 486 JoinPredicate joinPredicate = (index == 1) 487 ? 488 new JoinPredicate(BVEPlanMerger.getBooleanFactor(new RightIndexed(this, 489 Operator))) 490 : new JoinPredicate(BVEPlanMerger.getBooleanFactor(this)); 491 String colName = columnDetails[index].getColumn(); singleColumnPredicate.setPredicate(joinPredicate); 493 singleColumnPredicate.setColumnName(colName); 494 allColumnPredicates.addSinglePredicate(new SingleColumnPredicate[] { 495 singleColumnPredicate}); 496 return; 497 } 498 ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2. 499 getColumnDetails(); 500 ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0. 501 getColumnDetails(); 502 if (columnDetails1[0].getType() == REFERENCE) { singleColumnPredicate.setPredicate(this); 504 singleColumnPredicate.setColumnName(columnDetails1[0].getColumn()); 505 } 506 else { singleColumnPredicate.setPredicate(new RightIndexed(this, Operator)); 508 singleColumnPredicate.setColumnName(columnDetails2[0].getColumn()); 509 } 510 allColumnPredicates.addSinglePredicate(new SingleColumnPredicate[] { 511 singleColumnPredicate}); 512 } 513 514 521 522 private int checkForJoinPredicate(String tableName) throws DException { 523 for (int i = 0; i < columnDetails.length; i++) { 524 int type = columnDetails[i].getType(); 525 if (type != REFERENCE) { 526 return -1; 527 } 528 } 529 for (int i = 0; i < columnDetails.length; i++) { 530 531 TableDetails td = columnDetails[i].getTable(); 532 if (td != null && 533 td.getAppropriateOnlyTableName().equalsIgnoreCase(tableName)) { 534 return i; 535 } 536 } 537 return -1; 538 } 539 540 private boolean checkingForNotEqualTo() throws DException { 541 if (Operator == -1) { 542 Operator = getRespectiveOperator( (String ) _compop1.run(null)); 543 } 544 if (Operator == NOTEQUALTO) { 545 return true; 546 } 547 return false; 548 } 549 550 567 private int getBVEPlanType(ArrayList tableList) throws DException { 568 int countForFunctionalcolumn = 0; 569 return checkType(columnDetails, tableList, countForFunctionalcolumn); 570 } 571 572 private int checkType(ColumnDetails[] cd, ArrayList tableList, 573 int countForFunctionalcolumn) throws DException { 574 575 subQueryFlag = Utility.getBooleanValue(checkForSubQuery()); 576 for (int i = 0; i < cd.length; i++) { 577 int type = cd[i].getType(); 578 if (type == SCALARFUNCTION || type == FUNCTIONAL) { countForFunctionalcolumn++; 580 int ctype = checkType(cd[i].getChildColumnDetails(), tableList, 581 countForFunctionalcolumn); 582 if (ctype == BVEConstants.BVEAGGREGATEPLAN || 583 ctype == BVEConstants.BVEALLTABLEPLAN) 584 return ctype; 585 } 586 if (type == GROUPING) { 587 return BVEConstants.BVEAGGREGATEPLAN; 588 } 589 if (type == CASEEXPRESSION) 590 return BVEConstants.BVEALLTABLEPLAN; 591 if (type != CONSTANT) { 592 TableDetails tableDetail = cd[i].getTableDetails(); 593 if (tableDetail != null && !tableList.contains(tableDetail)) { 594 tableList.add(tableDetail); 595 } 596 } 597 } 598 if (subQueryFlag.booleanValue() && checkForComplexInnerQuery()) { 599 return BVEConstants.BVEALLTABLEPLAN; 600 } 601 int len = tableList.size(); 602 if (len == 1) { 603 return BVEConstants.BVESINGLETABLEPLAN; 604 } 605 if (len == 2) { 606 if (countForFunctionalcolumn < 2) 607 return BVEConstants.BVEJOINRELATION; 608 } 609 return BVEConstants.BVEALLTABLEPLAN; 610 611 } 612 613 630 public _BVEPlan getExecutionPlan() throws DException { 631 ArrayList tableList = new ArrayList(); 632 switch (getBVEPlanType(tableList)) { 633 case BVEConstants.BVESINGLETABLEPLAN: 634 return new BVESingleTablePlan(BVEPlanMerger.getBooleanFactor(this), 635 (TableDetails) tableList.get(0)); 636 case BVEConstants.BVEAGGREGATEPLAN: 637 return new BVEAggregatePlan(BVEPlanMerger.getBooleanFactor(this)); 638 case BVEConstants.BVEJOINRELATION: 639 _JoinRelation simpleRelation = new SimpleRelation( (TableDetails[]) 640 tableList.toArray(new TableDetails[tableList.size()]), 641 BVEPlanMerger.getBooleanFactor(this)); 642 AllTablesJoinRelation allTablesJoinRelation = new AllTablesJoinRelation(new 643 _JoinRelation[] {simpleRelation}); 644 BVEAllTablePlan bveAllTablePlan = new BVEAllTablePlan(null, 645 allTablesJoinRelation, null); 646 return bveAllTablePlan; 647 case BVEConstants.BVEALLTABLEPLAN: 648 return new BVEAllTablePlan(null, null, BVEPlanMerger.getBooleanFactor(this)); 649 } 650 throw new DException("DSE3547", new Object [] {this.toString()}); 651 } 652 653 659 660 private boolean checkForComplexInnerQuery() throws DException { 661 _Reference[] references = getReferences(null); 662 int length = references.length; 663 for (int i = 0; i < length; i++) { 664 if (references[i].getReferenceType() == SUBQUERY) { 665 if ( ( (subquery) references[i]).getUnderlyingReferences() != null) { 666 return true; 667 } 668 } 669 } 670 return false; 671 } 672 673 685 686 private void performingCardinalityChecking() throws DException { 687 int cardinality1 = _rowvalueexpressionwithoutboolean2.getCardinality(); 688 int card2 = _valueexpressionwithoutboolean0.getCardinality(); 689 if (cardinality1 != -1 && card2 != -1 && cardinality1 != card2) { 690 throw new DException("DSE214", null); 691 } 692 if (Operator != -1) { 693 Operator = getRespectiveOperator( (String ) _compop1.run(null)); 694 } 695 } 696 697 724 public Object run(Object object) throws com.daffodilwoods.database.resource. 725 DException { 726 727 Object fieldBase1 = _rowvalueexpressionwithoutboolean2.run(object); 728 Object fieldBase2 = _valueexpressionwithoutboolean0.run(object); 729 730 int cmp = -1; 731 try { 732 cmp = comparator.compare(fieldBase1, fieldBase2); 733 } 734 catch (NullPointerException ex) { 735 ByteComparison bc1 = _rowvalueexpressionwithoutboolean2.getByteComparison( 736 object); 737 ByteComparison bc2 = _valueexpressionwithoutboolean0.getByteComparison( 738 object); 739 synchronized (this) { 740 try { 741 742 comparator = getAppropriateComparator(bc1, bc2, fieldBase1, 743 fieldBase2, null); 744 745 cmp = comparator.compare(fieldBase1, fieldBase2); 747 } 748 catch (NullPointerException npe) { 749 throw npe; 750 } 751 } 752 } 753 catch (DException ex1) { 754 throw ex1; 755 } 756 return booleanResult[Operator - 1][cmp + 2]; 757 } 758 759 private int getRespectiveOperator(String oper) throws DException { 760 if (oper.equals(EQUALTOSTRING) || oper.equals(DOUBLEEQUALTOSTRING)) { 761 return EQUALTO; 762 } 763 else if (oper.equals(GREATERTHANSTRING)) { 764 return GREATERTHAN; 765 } 766 else if (oper.equals(GREATERTHANEQUALTOSTRING)) { 767 return GREATERTHANEQUALTO; 768 } 769 else if (oper.equals(LESSTHANSTRING)) { 770 return LESSTHAN; 771 } 772 else if (oper.equals(LESSTHANEQUALTOSTRING)) { 773 return LESSTHANEQUALTO; 774 } 775 else if (oper.equals(NOTEQUALTOSTRING) || oper.equals(NOTEQUALTOSTRING1)) { 776 return NOTEQUALTO; 777 } 778 return 0; 779 } 780 781 private boolean checkForSubQuery(ParameterInfo[] pi) throws DException { 782 for (int i = 0; i < pi.length; i++) { 783 if (pi[i].getSubQuery()) { 784 return true; 785 } 786 } 787 return false; 788 } 789 790 801 802 public ParameterInfo[] getParameterInfo() throws DException { 803 boolean subQueryFlag = false; 804 boolean flag = false; 805 ParameterInfo[] parameterInfo1 = _rowvalueexpressionwithoutboolean2. 806 getParameterInfo(); 807 ParameterInfo[] parameterInfo2 = _valueexpressionwithoutboolean0. 808 getParameterInfo(); 809 ParameterInfo[] result = null; 810 result = new ParameterInfo[parameterInfo1.length + parameterInfo2.length]; 811 System.arraycopy(parameterInfo1, 0, result, 0, parameterInfo1.length); 812 System.arraycopy(parameterInfo2, 0, result, parameterInfo1.length, 813 parameterInfo2.length); 814 815 816 817 if (_rowvalueexpressionwithoutboolean2 instanceof rowsubquery) { 818 ColumnDetails[] cd1 = ( (rowsubquery) _rowvalueexpressionwithoutboolean2). 819 _rowsubquery0.getSelectedColumnDetails(); 820 for (int i = 0; i < cd1.length; i++) { 821 for (int j = 0; j < result.length; j++) { 822 if (result[j].getQuestionMark()) { 823 result[j].setDataType(cd1[i].getDatatype()); 824 } 825 } 826 } 827 } 828 829 if (_valueexpressionwithoutboolean0 instanceof rowsubquery) { 830 ColumnDetails[] cd1 = ( (rowsubquery) _valueexpressionwithoutboolean0). 831 _rowsubquery0.getSelectedColumnDetails(); 832 for (int i = 0; i < cd1.length; i++) { 833 for (int j = 0; j < result.length; j++) { 834 if (result[j].getQuestionMark()) { 835 result[j].setDataType(cd1[i].getDatatype()); 836 837 } 838 } 839 840 } 841 } 842 843 flag = checkForSubQuery(result); 844 if (flag) { 845 ArrayList temp = new ArrayList(5); 846 for (int i = 0; i < result.length; i++) { 847 if (result[i].getSubQuery()) { 848 ParameterInfo[] tempPI = result[i].getParameterInfoArray(); 849 if (tempPI != null) { 850 temp.addAll(Arrays.asList(tempPI)); 851 } 852 } 853 else if (result[i].getQuestionMark()) { 854 temp.add(result[i]); 855 } 856 } 857 return (ParameterInfo[]) temp.toArray(new ParameterInfo[0]); 858 } 859 ArrayList aList = new ArrayList(); 860 int columnCount1 = parameterInfo1.length; 861 int columnCount2 = parameterInfo2.length; 862 if (columnCount1 == columnCount2) { 863 for (int i = 0; i < columnCount1; i++) { 864 if (parameterInfo1[i].getQuestionMark()) { 865 if (!parameterInfo2[i].getQuestionMark()) { 866 parameterInfo1[i].setName(parameterInfo2[i].getName()); 867 if (parameterInfo1[i].getDataType() == -1) 868 parameterInfo1[i].setDataType(parameterInfo2[i].getDataType()); 869 } 870 else { 871 if (parameterInfo1[i].getDataType() == -1) 872 parameterInfo1[i].setDataType(VARCHAR); 873 } 874 aList.add(parameterInfo1[i]); 875 } 876 } 877 for (int i = 0; i < columnCount2; i++) { 878 if (parameterInfo2[i].getQuestionMark()) { 879 if (!parameterInfo1[i].getQuestionMark()) { 880 parameterInfo2[i].setName(parameterInfo1[i].getName()); 881 882 if (parameterInfo2[i].getDataType() == -1) 883 parameterInfo2[i].setDataType(parameterInfo1[i].getDataType()); 884 } 885 886 else { 887 if (parameterInfo2[i].getDataType() == -1) 888 parameterInfo2[i].setDataType(VARCHAR); 889 } 890 aList.add(parameterInfo2[i]); 891 } 892 } 893 } 894 else { 895 int maxDataType = -1; 896 for (int i = 0; i < columnCount1; i++) { 897 int type = parameterInfo1[i].getDataType(); 898 if (maxDataType < type) { 899 maxDataType = type; 900 } 901 } 902 for (int i = 0; i < columnCount2; i++) { 903 int type = parameterInfo2[i].getDataType(); 904 if (maxDataType < type) { 905 maxDataType = type; 906 } 907 } 908 for (int i = 0; i < columnCount1; i++) { 909 if (parameterInfo1[i].getQuestionMark()) { 910 aList.add(parameterInfo1[i]); 911 parameterInfo1[i].setDataType(maxDataType); 912 } 913 } 914 for (int i = 0; i < columnCount2; i++) { 915 if (parameterInfo2[i].getQuestionMark()) { 916 aList.add(parameterInfo2[i]); 917 918 if (parameterInfo2[i].getDataType() == -1) 919 parameterInfo2[i].setDataType(maxDataType); 920 } 921 } 922 923 } 924 925 return (ParameterInfo[]) aList.toArray(new ParameterInfo[0]); 926 } 927 928 public void setOperator(int Type) throws DException { 929 Operator = Type; 930 } 931 932 942 943 private boolean checkForOtherCases() throws DException { 944 if (columnDetails.length != 2) { 945 return true; 946 } 947 return columnDetails[0].getType() == CONSTANT && 948 columnDetails[1].getType() == CONSTANT 949 || 950 (columnDetails[0].getUnderLyingReference() && 951 columnDetails[1].getUnderLyingReference()) 952 || columnDetails[0].checkNegativeValueFlag() || 953 columnDetails[1].checkNegativeValueFlag(); 954 955 } 956 957 964 965 public TableDetails[] getCorrespondingTablesInvolved(TableDetails[] td) throws 966 com.daffodilwoods.database.resource.DException { 967 ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2. 968 getColumnDetails(); 969 ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0. 970 getColumnDetails(); 971 if (columnDetails1.length > 1 || columnDetails2.length > 1) { 972 return null; 973 } 974 TableDetails toRet1 = null, toRet2 = null; 975 if (Operator == -1) { 976 Operator = getRespectiveOperator( (String ) _compop1.run(null)); 977 } 978 if (Operator == EQUALTO || Operator == LESSTHANEQUALTO || 979 Operator == GREATERTHANEQUALTO) { 980 toRet1 = getCorrespondingTableDetail(false, td); 981 toRet2 = getCorrespondingTableDetail(true, td); 982 if ( (toRet1 != null ^ toRet2 != null) == false) { 983 return null; 984 } 985 return toRet1 != null ? new TableDetails[] { 986 toRet1} 987 : new TableDetails[] { 988 toRet2}; 989 } 990 return null; 991 } 992 993 private TableDetails getCorrespondingTableDetail(boolean flag, 994 TableDetails[] td) throws DException { 995 TableDetails tolook = null, toRet = null; 996 ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2. 997 getColumnDetails(); 998 ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0. 999 getColumnDetails(); 1000 if (flag) { 1001 tolook = columnDetails1[0].getTableDetails(); 1002 toRet = columnDetails2[0].getTableDetails(); 1003 } 1004 else { 1005 tolook = columnDetails2[0].getTableDetails(); 1006 toRet = columnDetails1[0].getTableDetails(); 1007 } 1008 int len = td.length; 1009 for (int i = 0; i < len; i++) { 1010 if (td[i] == tolook) { 1011 return toRet; 1012 } 1013 } 1014 return null; 1015 } 1016 1017 1025 public void verifyValues(_VariableValueOperations vv) throws DException { 1026 } 1027 1028 public AbstractRowValueExpression[] getChilds() { 1029 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 1030 (AbstractRowValueExpression) (_rowvalueexpressionwithoutboolean2), 1031 (AbstractRowValueExpression) (_valueexpressionwithoutboolean0)}; 1032 return childs; 1033 } 1034 1035 1041 1042 public void setDefaultValues(_VariableValueOperations variableValueOperation) throws 1043 DException { 1044 if (Operator == -1) { 1045 Operator = getRespectiveOperator( (String ) _compop1.run(null)); 1046 } 1047 if (Operator != EQUALTO || checkForFunctionalOrGroupingColumn() || 1048 ! (columnDetails.length == 2)) { 1049 return; 1050 } 1051 Object leftValue = _rowvalueexpressionwithoutboolean2.run( 1052 variableValueOperation); 1053 Object rightValue = _valueexpressionwithoutboolean0.run( 1054 variableValueOperation); 1055 ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2. 1056 getColumnDetails(); 1057 ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0. 1058 getColumnDetails(); 1059 if (leftValue == null && rightValue != null && 1060 ! (rightValue instanceof IgnoreValue)) { 1061 putInMapping(variableValueOperation, columnDetails1[0], rightValue); 1062 } 1063 ( (VariableValueOperations) variableValueOperation).show(); 1064 if (leftValue != null && rightValue == null && 1065 ! (leftValue instanceof IgnoreValue)) { 1066 putInMapping(variableValueOperation, columnDetails2[0], leftValue); 1067 } 1068 } 1069 1070 1078 1079 public com.daffodilwoods.daffodildb.server.sql99.utils._Reference[] 1080 checkSemantic(com.daffodilwoods.daffodildb.server.serversystem. 1081 _ServerSession parent) throws DException { 1082 _Reference[] reference1 = GeneralPurposeStaticClass.getJointReferences( 1083 _rowvalueexpressionwithoutboolean2.checkSemantic(parent), 1084 _valueexpressionwithoutboolean0.checkSemantic(parent)); 1085 performingCardinalityChecking(); 1086 setDatatypeforNull(_valueexpressionwithoutboolean0, 1087 _rowvalueexpressionwithoutboolean2); 1088 if (reference1 == null ) 1089 checkDataTypes(parent); 1090 return reference1; 1091 } 1092 1093 private void checkDataTypes(_ServerSession session) throws DException { 1094 try { 1095 int[] dt1 = _rowvalueexpressionwithoutboolean2.getByteComparison(session). 1096 getDataTypes(); 1097 int[] dt2 = _valueexpressionwithoutboolean0.getByteComparison(session). 1098 getDataTypes(); 1099 Check.checkForDataTypes(dt1, dt2); 1100 } 1101 catch (DException ex) { 1102 throw ex; 1103 } 1104 } 1105 1106 1113 1114 public long getEstimatedRows(long noOfRows) throws DException { 1115 if (Operator == -1) { 1116 Operator = getRespectiveOperator( (String ) _compop1.run(null)); 1117 } 1118 switch (Operator) { 1119 case EQUALTO: 1120 return checkForJoinPredicate() ? (long) Math.sqrt(noOfRows) : 1121 noOfRows * CostFactorConstants.EQUALTO / 100; 1122 case GREATERTHAN: 1123 case LESSTHAN: 1124 return noOfRows * CostFactorConstants.GREATERTHAN / 100; 1125 case GREATERTHANEQUALTO: 1126 case LESSTHANEQUALTO: 1127 return noOfRows * CostFactorConstants.GREATERTHANEQUALTO / 100; 1128 } 1129 return noOfRows; 1130 } 1131 1132 public ColumnDetails[] getColumnDetails() throws DException { 1133 if (columnDetails == null) { 1134 ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2. 1135 getColumnDetails(); 1136 ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0. 1137 getColumnDetails(); 1138 ColumnDetails[] result = new ColumnDetails[columnDetails1.length + 1139 columnDetails2.length]; 1140 int i; 1141 for (i = 0; i < columnDetails1.length; i++) { 1142 result[i] = columnDetails1[i]; 1143 } 1144 for (int j = 0; j < columnDetails2.length; j++, i++) { 1145 result[i] = columnDetails2[j]; 1146 } 1147 this.columnDetails = result; 1148 } 1149 1150 1151 subQueryFlag = Utility.getBooleanValue(checkForSubQuery()); 1152 1153 if (Operator == -1) { 1154 Operator = getRespectiveOperator( (String ) _compop1.run(null)); 1155 1156 } 1157 return columnDetails; 1158 } 1159 1160 1165 private void putInMapping(_VariableValueOperations variableValueOperation, 1166 ColumnDetails columnDetails, Object value) throws 1167 DException { 1168 ( (VariableValueOperations) variableValueOperation).addColumnValues(new 1169 _Reference[] {columnDetails} 1170 , new Object [] {value} 1171 , 1); 1172 } 1173 1174 private boolean checkForFunctionalOrGroupingColumn() throws DException { 1175 int length = columnDetails.length; 1176 for (int i = 0; i < length; i++) { 1177 if (columnDetails[i].getType() == FUNCTIONAL || 1178 columnDetails[i].getType() == GROUPING) { 1179 return true; 1180 } 1181 } 1182 return false; 1183 } 1184 1185 public String toString() { 1186 StringBuffer sb = new StringBuffer (); 1187 sb.append(" "); 1188 sb.append(_rowvalueexpressionwithoutboolean2.toString().trim()); 1189 sb.append(_compop1 == null ? getRespectiveOperatorString(Operator) : 1190 _compop1 + ""); 1191 sb.append(_valueexpressionwithoutboolean0.toString().trim()); 1192 return sb.toString(); 1193 } 1194 1195 private String getRespectiveOperatorString(int oper) { 1196 if (oper == EQUALTO) { 1197 return EQUALTOSTRING; 1198 } 1199 else if (oper == GREATERTHAN) { 1200 return GREATERTHANSTRING; 1201 } 1202 else if (oper == GREATERTHANEQUALTO) { 1203 return GREATERTHANEQUALTOSTRING; 1204 } 1205 else if (oper == LESSTHAN) { 1206 return LESSTHANSTRING; 1207 } 1208 else if (oper == LESSTHANEQUALTO) { 1209 return LESSTHANEQUALTOSTRING; 1210 } 1211 else if (oper == NOTEQUALTO) { 1212 return NOTEQUALTOSTRING; 1213 } 1214 return 0 + ""; 1215 } 1216 1217 public Object clone() throws CloneNotSupportedException { 1218 comparisonpredicate tempClass = new comparisonpredicate(); 1219 tempClass._valueexpressionwithoutboolean0 = (valueexpressionwithoutboolean) 1220 _valueexpressionwithoutboolean0.clone(); 1221 tempClass._compop1 = (compop) _compop1.clone(); 1222 tempClass.Operator = Operator; 1223 tempClass._rowvalueexpressionwithoutboolean2 = ( 1224 rowvalueexpressionwithoutboolean) _rowvalueexpressionwithoutboolean2. 1225 clone(); 1226 try { 1227 tempClass.getColumnDetails(); 1228 } 1229 catch (DException ex) { 1230 throw new RuntimeException (ex.getMessage()); 1231 } 1232 return tempClass; 1233 } 1234 1235 1236 private boolean checkForMultipleReference2(ColumnDetails[] cd, Set set) throws 1237 DException { 1238 for (int i = 0; i < cd.length; i++) { 1239 if (cd[i].getType() == REFERENCE) { 1240 if (!set.add(cd[i].getAppropriateTableName())) { 1241 return true; 1242 } 1243 } 1244 if (cd[i].getType() == FUNCTIONAL) { 1245 return checkForMultipleReference2(cd[i].getChildColumnDetails(), set); 1246 } 1247 } 1248 return false; 1249 } 1250 1251 1254 1255 public SuperComparator getAppropriateComparator(ByteComparison 1256 byteComparison1, 1257 ByteComparison 1258 byteComparison2, 1259 Object value1, Object value2, 1260 _ServerSession serverSession) throws 1261 DException { 1262 if (!byteComparison1.canUseByteComparison() || 1263 !byteComparison2.canUseByteComparison()) { 1264 initializeDatatypes((FieldBase)value1,(FieldBase)value2); 1265 return new CPckfduDpnqbsbups(); 1266 } 1267 int cardinality = _rowvalueexpressionwithoutboolean2.getCardinality(); 1268 if (cardinality > 1) { 1269 return getJoinComparator( (Object []) value1, (Object []) value2, 1270 serverSession); 1271 } 1272 return getComparator( (FieldBase) value1, (FieldBase) value2, serverSession); 1273 } 1274 1275 1278 1279 protected SuperComparator getJoinComparator(Object [] fieldBase1, 1280 Object [] fieldBase2, 1281 _ServerSession serverSession) throws 1282 DException { 1283 int length = fieldBase1.length; 1284 SuperComparator[] comparators = new SuperComparator[length]; 1285 for (int i = 0; i < length; i++) { 1286 try { 1287 comparators[i] = getComparator( (FieldBase) fieldBase1[i], 1288 (FieldBase) fieldBase2[i], serverSession); 1289 } 1290 catch (ClassCastException ex) { 1291 throw ex; 1292 } 1293 } 1294 return new ComparisionPredicateJoinComparator(comparators, Operator); 1295 } 1296 1297 private void setDatatypeforNull(valueexpressionwithoutboolean 1298 _valueexpressionwithoutboolean0, 1299 rowvalueexpressionwithoutboolean 1300 _rowvalueexpressionwithoutboolean2) throws 1301 DException { 1302 ColumnDetails cd1[] = _valueexpressionwithoutboolean0.getColumnDetails(); 1303 ColumnDetails cd2[] = _rowvalueexpressionwithoutboolean2.getColumnDetails(); 1304 if (cd1.length == cd2.length) { 1305 for (int i = 0; i < cd1.length; i++) { 1306 if (cd1[i].getColumnName()[0].equalsIgnoreCase("null")) { 1307 cd1[i].setDatatype(cd2[i].getDatatype()); 1308 } 1309 if (cd2[i].getColumnName()[0].equalsIgnoreCase("null")) { 1310 cd2[i].setDatatype(cd1[i].getDatatype()); 1311 } 1312 } 1313 } 1314 } 1315} 1316 | Popular Tags |