1 package com.daffodilwoods.daffodildb.server.sql99.expression. 2 booleanvalueexpression.predicates; 3 4 import java.util.*; 5 6 import com.daffodilwoods.daffodildb.server.serversystem.*; 7 import com.daffodilwoods.daffodildb.server.sql99.common.*; 8 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*; 9 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*; 10 import com.daffodilwoods.daffodildb.server.sql99.expression. 11 booleanvalueexpression.*; 12 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.*; 13 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*; 14 import com.daffodilwoods.daffodildb.server.sql99.token.*; 15 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 16 import com.daffodilwoods.daffodildb.utils.comparator.*; 17 import com.daffodilwoods.database.resource.*; 18 import com.daffodilwoods.database.utility.*; 19 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility; 20 21 30 31 public class betweenpredicate 32 extends PredicateAbstract 33 implements predicate, OperatorConstants, Datatypes, 34 35 ExecutionPlanConstants, SimpleConstants { 36 37 40 public valueexpressionwithoutboolean _valueexpressionwithoutboolean0; 41 42 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439221; 43 44 47 public valueexpressionwithoutboolean _valueexpressionwithoutboolean2; 48 49 55 56 public symmetricoption _Optsymmetricoption3; 57 58 public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442554; 59 60 public SRESERVEDWORD1206543922 _OptSRESERVEDWORD12065439225; 61 62 65 public rowvalueexpressionwithoutboolean _rowvalueexpressionwithoutboolean6; 66 67 70 private Boolean subQueryFlag = Boolean.FALSE; 71 72 boolean asymmetric = true; 73 74 private int[] appropriateDataTypes; 75 76 82 private SuperComparator comparator1; 83 84 90 private SuperComparator comparator2; 91 92 99 100 public double getCost(long rowCount, boolean index) throws DException { 101 rowCount *= rowCount * (CostFactorConstants.GREATERTHANEQUALTO / 100) * 102 (CostFactorConstants.GREATERTHANEQUALTO / 100); 103 if (index) { 104 rowCount *= CostFactorConstants.INDEXPREDICATE / 100; 105 } 106 return rowCount; 107 } 108 109 129 130 public _QualifiedBVE getQualifiedBVE(TableDetails[] tableDetails) throws 131 DException { 132 ArrayList uniqueTableList = getUniqueTableDetails(new ArrayList(), 133 columnDetails); 134 if (uniqueTableList.size() != 1) { 135 return new QualifiedBVE(null, BVEPlanMerger.getBooleanFactor(this)); 136 } 137 QualifiedBVE qualifiedBVE = getQualifiedBVEifBelongsToSingleTablePlan( 138 tableDetails, uniqueTableList); 139 if (qualifiedBVE == null) { 140 qualifiedBVE = new QualifiedBVE(null, BVEPlanMerger.getBooleanFactor(this)); 141 } 142 return qualifiedBVE; 143 } 144 145 private QualifiedBVE getQualifiedBVEifBelongsToSingleTablePlan(TableDetails[] 146 planTableDetails, ArrayList uniqueTableDetails) throws DException { 147 int length = planTableDetails.length; 148 TableDetails conditionTableDetails = (TableDetails) uniqueTableDetails.get( 149 0); 150 QualifiedBVE qualifiedBVE = null; 151 for (int j = 0; j < length; j++) { 152 if (planTableDetails[j] == conditionTableDetails) { 153 BVESingleTablePlan bveSingleTablePlan = new BVESingleTablePlan( ( 154 booleanvalueexpression) BVEPlanMerger.getBooleanFactor(this), 155 conditionTableDetails); 156 BVESingleTablePlan[] bveSTPArray = new BVESingleTablePlan[] { 157 bveSingleTablePlan}; 158 qualifiedBVE = new QualifiedBVE(bveSTPArray, null); 159 return qualifiedBVE; 160 } 161 } 162 return null; 163 } 164 165 185 186 187 194 195 public int getPredicateType() throws DException { 196 if (_OptSRESERVEDWORD12065439225 != null) { 197 return OperatorConstants.NOTBETWEEN; 198 } 199 return OperatorConstants.RANGE_PREDICATE; 200 } 201 202 212 213 public void setColumnPredicates(_AllColumnPredicates allColumnPredicates) throws 214 DException { 215 if (_OptSRESERVEDWORD12065439225 != null || checkForSubQuery()) { allColumnPredicates.addToNonIndex(BVEPlanMerger.getBooleanFactor(this)); 217 return; 218 } 219 if (_Optsymmetricoption3 != null) { 220 String option = (String ) _Optsymmetricoption3.run(null); 221 if (option.trim().equalsIgnoreCase("SYMMETRIC")) { setColumnPredicates(OperatorConstants.GREATERTHAN, 223 OperatorConstants.LESSTHAN, allColumnPredicates); 224 return; 225 } 226 } 227 setColumnPredicates(OperatorConstants.GREATERTHANEQUALTO, 228 OperatorConstants.LESSTHANEQUALTO, allColumnPredicates); 229 } 230 231 private void setColumnPredicates(int operator1, int operator2, 232 _AllColumnPredicates allColumnPredicates) throws 233 DException { 234 comparisonpredicate leftPredicate = new comparisonpredicate( 235 _rowvalueexpressionwithoutboolean6, operator1, 236 _valueexpressionwithoutboolean2, 237 getColumns(_rowvalueexpressionwithoutboolean6.getColumnDetails(), 238 _valueexpressionwithoutboolean2.getColumnDetails())); 239 comparisonpredicate rightPredicate = new comparisonpredicate( 240 _rowvalueexpressionwithoutboolean6, operator2, 241 _valueexpressionwithoutboolean0, 242 getColumns(_rowvalueexpressionwithoutboolean6.getColumnDetails(), 243 _valueexpressionwithoutboolean0.getColumnDetails())); 244 leftPredicate.setColumnPredicates(allColumnPredicates); 245 rightPredicate.setColumnPredicates(allColumnPredicates); 246 } 247 248 265 266 private int getBVEPlanType(ArrayList tableList) throws DException { 267 268 subQueryFlag = Utility.getBooleanValue(checkForSubQuery()); 269 for (int i = 0; i < columnDetails.length; i++) { 270 271 int type = columnDetails[i].getType(); 272 if (type == GROUPING) { 273 return BVEConstants.BVEAGGREGATEPLAN; 274 } 275 if (type == SCALARFUNCTION || type == CASEEXPRESSION || 276 type == FUNCTIONAL) { 277 return BVEConstants.BVEALLTABLEPLAN; 278 } 279 if (type != CONSTANT) { 280 TableDetails tableDetail = columnDetails[i].getTableDetails(); 281 if (tableDetail != null && !tableList.contains(tableDetail)) { 282 tableList.add(tableDetail); 283 } 284 } 285 } 286 if (checkForSubQuery() && checkForComplexInnerQuery()) { 287 return BVEConstants.BVEALLTABLEPLAN; 288 } 289 int size = tableList.size(); 290 if (size == 1) { 291 return BVEConstants.BVESINGLETABLEPLAN; 292 } 293 else if (size == 2) { 294 return BVEConstants.BVEJOINRELATION; 295 } 296 else { 297 return BVEConstants.BVEALLTABLEPLAN; 298 } 299 } 300 301 318 319 public _BVEPlan getExecutionPlan() throws DException { 320 ArrayList tableList = new ArrayList(); 321 int type = getBVEPlanType(tableList); 322 switch (type) { 323 case BVEConstants.BVEAGGREGATEPLAN: 324 return new BVEAggregatePlan(BVEPlanMerger.getBooleanFactor(this)); 325 case BVEConstants.BVEALLTABLEPLAN: 326 return new BVEAllTablePlan(null, null, BVEPlanMerger.getBooleanFactor(this)); 327 case BVEConstants.BVESINGLETABLEPLAN: 328 return new BVESingleTablePlan(BVEPlanMerger.getBooleanFactor(this), 329 (TableDetails) tableList.get(0)); 330 case BVEConstants.BVEJOINRELATION: 331 TableDetails[] tableDetails = (TableDetails[]) tableList.toArray(new 332 TableDetails[2]); 333 _JoinRelation sr = new SimpleRelation(tableDetails, 334 BVEPlanMerger.getBooleanFactor(this)); 335 AllTablesJoinRelation atjr = new AllTablesJoinRelation(new 336 _JoinRelation[] {sr}); 337 return new BVEAllTablePlan(null, atjr, null); 338 } 339 throw new DException("DSE3547", new Object [] {this.toString()}); 340 } 341 342 348 349 private boolean checkForComplexInnerQuery() throws DException { 350 _Reference[] references = getReferences(null); 351 int length = references.length; 352 for (int i = 0; i < length; i++) { 353 if (references[i].getReferenceType() == SUBQUERY) { 354 if ( ( (subquery) references[i]).getUnderlyingReferences() != null) { 355 return true; 356 } 357 } 358 } 359 return false; 360 } 361 362 370 371 public com.daffodilwoods.daffodildb.server.sql99.utils._Reference[] 372 checkSemantic(com.daffodilwoods.daffodildb.server.serversystem. 373 _ServerSession parent) throws DException { 374 _Reference[] reference = GeneralPurposeStaticClass.getJointReferences( 375 _rowvalueexpressionwithoutboolean6.checkSemantic(parent), 376 _valueexpressionwithoutboolean2.checkSemantic(parent)); 377 reference = GeneralPurposeStaticClass.getJointReferences(reference, 378 _valueexpressionwithoutboolean0.checkSemantic(parent)); 379 checkCardinalityChecking(); 380 checkDataTypes(parent); 381 return reference; 382 383 } 384 385 private void checkDataTypes(_ServerSession session) throws DException { 386 int[] dt1 = _rowvalueexpressionwithoutboolean6.getByteComparison(session). 387 getDataTypes(); 388 int[] dt2 = _valueexpressionwithoutboolean2.getByteComparison(session). 389 getDataTypes(); 390 int[] dt3 = _valueexpressionwithoutboolean0.getByteComparison(session). 391 getDataTypes(); 392 Check.checkForDataTypes(dt1, dt2); 393 Check.checkForDataTypes(dt1, dt3); 394 appropriateDataTypes = getAppropriateDataTypes(getAppropriateDataTypes(dt1, 395 dt2), dt3); 396 setDataTypeforParameterMarker(); 397 } 398 399 412 413 private void checkCardinalityChecking() throws DException { 414 int c1 = _rowvalueexpressionwithoutboolean6.getCardinality(); 415 int c2 = _valueexpressionwithoutboolean2.getCardinality(); 416 int c3 = _valueexpressionwithoutboolean0.getCardinality(); 417 if (c1 != -1 && c2 != -1 && c3 != -1 && (c1 != c2 || c2 != c3 || c1 != c3)) { 418 throw new DException("DSE214", null); 419 } 420 } 421 422 429 430 public ParameterInfo[] getParameterInfo() throws DException { 431 boolean isSubQuery = false; 432 ParameterInfo[] p1 = _rowvalueexpressionwithoutboolean6.getParameterInfo(); 433 ParameterInfo[] p2 = _valueexpressionwithoutboolean2.getParameterInfo(); 434 ParameterInfo[] p3 = _valueexpressionwithoutboolean0.getParameterInfo(); 435 ArrayList aList = new ArrayList(5); 436 437 int count = 0, maxDataType = -1; 438 for (int i = 0; i < p1.length; i++) { 439 if (p1[i].getSubQuery()) { 440 if (p1[i].getParameterInfoArray() != null) 441 aList.addAll(Arrays.asList(p1[i].getParameterInfoArray())); 442 } 443 else if (p1[i].getQuestionMark()) { 444 if (i< appropriateDataTypes.length && p1[i].getDataType() == -1) 445 p1[i].setDataType(appropriateDataTypes[i]); 446 aList.add(p1[i]); 447 } 448 449 } 450 451 for (int i = 0; i < p2.length; i++) { 452 if (p2[i].getSubQuery()) { ParameterInfo[] array = p2[i].getParameterInfoArray(); 454 if (array != null) { 455 aList.addAll(Arrays.asList(array)); 456 } 457 isSubQuery = true; 458 } 459 else if (p2[i].getQuestionMark()) { if (i< appropriateDataTypes.length && p2[i].getDataType() == -1 ) { 461 p2[i].setDataType(appropriateDataTypes[i]); 462 } 463 aList.add(p2[i]); 464 } 465 } 466 for (int i = 0; i < p3.length; i++) { 467 if (p3[i].getSubQuery()) { 468 ParameterInfo[] array = p3[i].getParameterInfoArray(); 469 if (array != null) { 470 aList.addAll(Arrays.asList(array)); 471 } 472 isSubQuery = true; 473 } 474 else if (p3[i].getQuestionMark()) { 475 if (i< appropriateDataTypes.length && p3[i].getDataType() == -1 ) { 476 p3[i].setDataType(appropriateDataTypes[i]); 477 } 478 aList.add(p3[i]); 479 } 480 } 481 482 return (ParameterInfo[]) aList.toArray(new ParameterInfo[0]); 483 } 484 485 486 529 530 public AbstractRowValueExpression[] getChilds() { 531 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 532 (AbstractRowValueExpression) (_rowvalueexpressionwithoutboolean6), 533 (AbstractRowValueExpression) (_valueexpressionwithoutboolean2), 534 (AbstractRowValueExpression) (_valueexpressionwithoutboolean0)}; 535 return childs; 536 } 537 538 public void setDefaultValues(_VariableValueOperations variableValueOperation) throws 539 DException { 540 } 541 542 549 550 public long getEstimatedRows(long noOfRows) throws DException { 551 return noOfRows * (CostFactorConstants.GREATERTHANEQUALTO / 100) * 552 (CostFactorConstants.GREATERTHANEQUALTO / 100); 553 } 554 555 583 public Object run(Object object) throws com.daffodilwoods.database.resource. 584 DException { 585 Object result1 = _rowvalueexpressionwithoutboolean6.run(object); 586 Object result2 = _valueexpressionwithoutboolean2.run(object); 587 Object result3 = _valueexpressionwithoutboolean0.run(object); 588 Object finalResult = null; 589 try { 590 if (comparator1 == null) { 591 throw new NullPointerException (); 592 } 593 } 594 catch (NullPointerException npe) { 595 asymmetric = _Optsymmetricoption3 == null ? true 596 : 597 ( (String ) _Optsymmetricoption3.run(null)).equalsIgnoreCase( 598 "ASYMMETRIC"); 599 ByteComparison bc1 = _rowvalueexpressionwithoutboolean6.getByteComparison( 600 object); 601 ByteComparison bc2 = _valueexpressionwithoutboolean2.getByteComparison( 602 object); 603 ByteComparison bc3 = _valueexpressionwithoutboolean0.getByteComparison( 604 object); 605 comparator1 = getAppropriateComparator(bc1, bc2, result1, result2, null); 606 comparator2 = getAppropriateComparator(bc1, bc3, result1, result3, null); 607 } 608 if (asymmetric) { 609 finalResult = handlingOfAsymmetric(result1, result2, result3, false); 610 } 611 else { 612 finalResult = handlingOfSymmetric(result1, result2, result3, false); 613 } 614 if (_OptSRESERVEDWORD12065439225 != null) { 615 return finalResult.hashCode() == 0 ? IntegerPool.Integer1 616 : finalResult.hashCode() == -2 617 ? finalResult 618 : finalResult.hashCode() == 2 619 ? finalResult 620 : IntegerPool.Integer0; 621 622 } 623 return finalResult; 624 } 625 626 637 private Object handlingOfAsymmetric(Object result1, Object result2, 638 Object result3, boolean nullSortedHigh) throws 639 DException { 640 int cmp; 641 cmp = comparator1.compare(result1, result2); 642 Object obj1 = booleanResult[GREATERTHANEQUALTO - 1][cmp + 2]; 643 if (obj1.hashCode() != 0) { 644 return obj1; 645 } 646 cmp = comparator2.compare(result1, result3); 647 return booleanResult[LESSTHANEQUALTO - 1][cmp + 2]; 648 } 649 650 661 private Object handlingOfSymmetric(Object result1, Object result2, 662 Object result3, boolean nullSortedHigh) throws 663 DException { 664 int cmp; 665 cmp = comparator1.compare(result1, result2); 666 Object obj1 = booleanResult[GREATERTHAN - 1][cmp + 2]; 667 if (obj1.hashCode() != 0) { 668 return obj1; 669 } 670 cmp = comparator2.compare(result1, result3); 671 return booleanResult[LESSTHAN - 1][cmp + 2]; 672 } 673 674 680 681 public void releaseResource() throws DException { 682 super.releaseResource(); 683 comparator1 = comparator2 = null; 684 } 685 686 private ColumnDetails[] getColumns(ColumnDetails[] columns1, 687 ColumnDetails[] columns2) throws 688 DException { 689 int length1 = columns1.length; 690 int length2 = columns2.length; 691 ColumnDetails[] result = new ColumnDetails[columns1.length + 692 columns2.length]; 693 int i = 0; 694 for (; i < length1; i++) { 695 result[i] = columns1[i]; 696 } 697 for (int j = 0; j < length2; j++, i++) { 698 result[i] = columns2[j]; 699 } 700 return result; 701 } 702 703 public Object clone() throws CloneNotSupportedException { 704 betweenpredicate tempClass = new betweenpredicate(); 705 tempClass._valueexpressionwithoutboolean0 = (valueexpressionwithoutboolean) 706 _valueexpressionwithoutboolean0.clone(); 707 tempClass._SRESERVEDWORD12065439221 = (SRESERVEDWORD1206543922) 708 _SRESERVEDWORD12065439221.clone(); 709 tempClass._valueexpressionwithoutboolean2 = (valueexpressionwithoutboolean) 710 _valueexpressionwithoutboolean2.clone(); 711 if (_Optsymmetricoption3 != null) { 712 tempClass._Optsymmetricoption3 = (symmetricoption) _Optsymmetricoption3. 713 clone(); 714 } 715 tempClass._SNONRESERVEDWORD1364442554 = (SNONRESERVEDWORD136444255) 716 _SNONRESERVEDWORD1364442554.clone(); 717 if (_OptSRESERVEDWORD12065439225 != null) { 718 tempClass._OptSRESERVEDWORD12065439225 = (SRESERVEDWORD1206543922) 719 _OptSRESERVEDWORD12065439225.clone(); 720 } 721 tempClass._rowvalueexpressionwithoutboolean6 = ( 722 rowvalueexpressionwithoutboolean) _rowvalueexpressionwithoutboolean6. 723 clone(); 724 try { 725 tempClass.getColumnDetails(); 726 } 727 catch (DException ex) { 728 throw new RuntimeException (ex.getMessage()); 729 } 730 return tempClass; 731 } 732 733 public String toString() { 734 StringBuffer sb = new StringBuffer (); 735 sb.append(" "); 736 sb.append(_rowvalueexpressionwithoutboolean6); 737 sb.append(" "); 738 if (_OptSRESERVEDWORD12065439225 != null) { 739 sb.append(_OptSRESERVEDWORD12065439225); 740 } 741 sb.append(" "); 742 sb.append(_SNONRESERVEDWORD1364442554); 743 sb.append(" "); 744 if (_Optsymmetricoption3 != null) { 745 sb.append(_Optsymmetricoption3); 746 } 747 sb.append(" "); 748 sb.append(_valueexpressionwithoutboolean2); 749 sb.append(" "); 750 sb.append(_SRESERVEDWORD12065439221); 751 sb.append(" "); 752 sb.append(_valueexpressionwithoutboolean0); 753 return sb.toString(); 754 } 755 756 private int[] getAppropriateDataTypes(int[] dt1, int[] dt2) throws DException { 757 int[] maxdataType = new int[dt1.length]; 758 for (int i = 0; i < dt1.length; i++) { 759 maxdataType[i] = dt1[i] > dt2[i] ? dt1[i] : dt2[i]; 760 } 761 return maxdataType; 762 } 763 764 private void setDataTypeforParameterMarker() throws DException { 765 for (int i = 0; i < appropriateDataTypes.length; i++) { 766 if (appropriateDataTypes[i] == -1) 767 appropriateDataTypes[i] = BIGDECIMAL; 768 } 769 } 770 771 772 } 773 | Popular Tags |