1 package com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem.*; 6 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 7 import com.daffodilwoods.daffodildb.server.serversystem.*; 8 import com.daffodilwoods.daffodildb.server.sessionsystem.*; 9 import com.daffodilwoods.daffodildb.server.sql99.common.*; 10 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*; 11 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 12 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.condition.*; 13 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*; 14 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*; 15 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.predicates.*; 16 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 17 import com.daffodilwoods.daffodildb.utils.comparator.*; 18 import com.daffodilwoods.database.resource.*; 19 import com.daffodilwoods.database.utility.P; 20 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.booleantest; 21 import com.daffodilwoods.daffodildb.utils.FieldUtility; 22 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 23 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.table.MultiValueIndexedFilterIterator; 24 25 36 public class AllColumnPredicates implements _AllColumnPredicates { 37 38 41 42 private TableDetails tableDetails; 43 46 private _SingleColumnPredicate[] singleColumnPredicates; 47 50 private booleanvalueexpression nonIndexedCondition; 51 52 55 56 private int indexPosition; 57 63 private boolean isNoRecordIterator; 64 65 68 69 private SuperComparator objectComparator; 70 71 public AllColumnPredicates() { 72 objectComparator = new CPckfduDpnqbsbups(); 73 } 74 75 103 public void addSinglePredicate(_SingleColumnPredicate[] newSingleColumnPredicates) throws DException { 104 if (isNoRecordIterator) { 105 return; 106 } 107 if (singleColumnPredicates == null) { 108 try { 109 singleColumnPredicates = (_SingleColumnPredicate[]) newSingleColumnPredicates; 110 } catch (ClassCastException e) { 111 } 112 return; 113 } 114 ArrayList aList = new ArrayList(); 115 116 int len1 = singleColumnPredicates.length, len2 = newSingleColumnPredicates.length; 117 118 for (int j = 0; j < len2; j++) { 119 120 int i = 0; 121 for (; i < len1; i++) { 122 123 if (singleColumnPredicates[i].getColumnName().equalsIgnoreCase(newSingleColumnPredicates[j].getColumnName())) { 124 try { 125 126 131 int type = singleColumnPredicates[i].getPredicateType(); 132 int type2 = newSingleColumnPredicates[j].getPredicateType(); 133 predicate _predicate = null; 134 if(type == OperatorConstants.IN){ addToNonIndex(new booleanfactor(new booleantest(singleColumnPredicates[i].getPredicate()))); 136 _predicate = newSingleColumnPredicates[j].getPredicate(); 137 }else if(type2 == OperatorConstants.IN){ addToNonIndex(new booleanfactor(new booleantest(newSingleColumnPredicates[j].getPredicate()))); 139 _predicate = singleColumnPredicates[i].getPredicate(); 140 } 141 142 else{ 143 _predicate = TablePlanMerger.getMergedPredicate(singleColumnPredicates[i].getPredicate(), newSingleColumnPredicates[j].getPredicate(), objectComparator); 144 } 145 146 if (_predicate == null) { 147 isNoRecordIterator = true; 148 return; 149 } else { 150 singleColumnPredicates[i].setPredicate(_predicate); 151 } 152 break; 153 } catch (DException dException) { String code = dException.getDseCode(); 155 if (code.equalsIgnoreCase("DSE1251") || code.equalsIgnoreCase("DSE3804")) { 156 aList.add(newSingleColumnPredicates[j]); 157 } else { 158 throw dException; 159 } 160 } 161 break; 162 } 163 } 164 if (i == len1) { 165 aList.add(newSingleColumnPredicates[j]); 166 } 167 } 168 aList.addAll(Arrays.asList(singleColumnPredicates)); 169 SingleColumnPredicate[] scp = (SingleColumnPredicate[]) aList.toArray(new SingleColumnPredicate[aList.size()]); 170 singleColumnPredicates = scp; 171 } 172 173 189 public _IndexPredicateInterface splitForIndex(_IndexInformation indexInformation0, int indexPosition0) throws DException { 190 IndexPredicate indexPredicate = getIndexPredicatesForIndex(indexInformation0, indexPosition0); 191 indexPredicate.setNoRecordIteratorStatus(isNoRecordIterator); 192 return indexPredicate; 193 } 194 202 public void addToNonIndex(booleanvalueexpression newNonIndexedCondition) throws DException { 203 if (nonIndexedCondition != null) { 204 nonIndexedCondition = BVEPlanMerger.addAndConditions(nonIndexedCondition, newNonIndexedCondition); 205 } else { 206 nonIndexedCondition = newNonIndexedCondition; 207 } 208 } 209 210 217 public _Iterator execute(Object sessionObject) throws DException { 218 _IndexTable session = (_IndexTable) sessionObject; 219 _ServerSession serverSession = ( (_SessionGetter) session).getServerSession(); 220 _Iterator iter = session.getIterator(indexPosition); 222 223 if(singleColumnPredicates[0].getPredicate().getPredicateType()==OperatorConstants.IN){ 224 inpredicate in =(inpredicate)singleColumnPredicates[0].getPredicate(); 225 ArrayList values=new ArrayList(); 226 ColumnDetails cd=in.getChilds()[0].getColumnDetails()[0]; 228 MultiValueIndexedFilterIterator mviter = new MultiValueIndexedFilterIterator(iter, null, serverSession, cd,( (pareninvaluelist) in._inpredicatevalue0)._invaluelist0); 229 return mviter; 230 } 231 232 booleanvalueexpression indexedCondition = new BooleanValueExpressionArray(getBVEArray()); 233 _IndexPredicate[] indexPredicateArray = (_IndexPredicate[]) getBVEArrayCVV(iter, serverSession); 234 VariableValues variableValues = new VariableValues(indexedCondition.getReferences(new TableDetails[] {tableDetails}), serverSession); 235 variableValues.setIterator(iter); 236 ConditionVariableValue indexPredicates = new ConditionVariableValue(variableValues, indexedCondition); 237 iter = new IndexedFilterIterator(iter, indexPredicates, indexPredicateArray); 238 return iter; 239 } 240 241 247 private booleanvalueexpression[] getBVEArray() throws DException { 248 int length = singleColumnPredicates.length; 249 booleanvalueexpression[] array = new booleanvalueexpression[length]; 250 for (int i = 0; i < length; ++i) { 251 array[i] = BVEPlanMerger.getBooleanFactor(singleColumnPredicates[i].getPredicate()); 252 } 253 return array; 254 } 255 256 265 private ConditionVariableValue[] getBVEArrayCVV(_Iterator iter, _ServerSession serverSession) throws DException { 266 int length = singleColumnPredicates.length; 267 ConditionVariableValue[] cvv = new ConditionVariableValue[length]; 268 for (int i = 0; i < length; ++i) { 269 booleanvalueexpression bve = BVEPlanMerger.getBooleanFactor(singleColumnPredicates[i].getPredicate()); 270 VariableValues VV = new VariableValues(bve.getReferences(new TableDetails[] {tableDetails}), serverSession); 271 ConditionVariableValue cv = new ConditionVariableValue(VV, bve); 272 cvv[i] = cv; 273 } 274 return cvv; 275 } 276 277 284 private IndexPredicate getIndexPredicatesForIndex(_IndexInformation indexInformation, int indexPosition0) throws DException { 285 if (singleColumnPredicates == null) { 286 return initializeIndexPredicate(null, nonIndexedCondition, indexPosition0); 287 } 288 String indexColumns[] = indexInformation.getColumns(); 289 Object [] singleColumnPredicatesAndNonIndexedCondition = getIndexedPredicatesAndInitializeNonIndexedCondition(indexColumns, indexInformation.getOrderOfColumns(), singleColumnPredicates); 290 _SingleColumnPredicate[] indexedPredicates = (_SingleColumnPredicate[]) singleColumnPredicatesAndNonIndexedCondition[0]; 291 booleanvalueexpression nonIndexedCondition = (booleanvalueexpression) singleColumnPredicatesAndNonIndexedCondition[1]; 292 return initializeIndexPredicate(indexedPredicates, nonIndexedCondition, indexPosition0); 293 } 294 305 private IndexPredicate initializeIndexPredicate(_SingleColumnPredicate[] singleColumnPredicates0, booleanvalueexpression nonIndexedCondition0, int indexPosition0) throws DException { 306 AllColumnPredicates indexedPredicate = null; 307 AllColumnPredicates nonIndexedPredicate = null; 308 if (singleColumnPredicates0 != null) { 309 indexedPredicate = new AllColumnPredicates(); 310 indexedPredicate.setIndexPosition(indexPosition0); 311 indexedPredicate.addSinglePredicate(singleColumnPredicates0); 312 } 313 if (nonIndexedCondition0 != null) { 314 nonIndexedPredicate = new AllColumnPredicates(); 315 nonIndexedPredicate.addToNonIndex(nonIndexedCondition0); 316 } 317 return new IndexPredicate(indexedPredicate, nonIndexedPredicate); 318 } 319 320 334 private Object [] getIndexedPredicatesAndInitializeNonIndexedCondition(String [] indexColumns, boolean[] indexColumnsOrder, _SingleColumnPredicate[] predicateColumns) throws DException { 335 boolean[] indexNonIndex = new boolean[predicateColumns.length]; ArrayList listOfIndexedColumn = new ArrayList(); 337 extractIndexedPredicates(0, indexNonIndex, indexColumns, indexColumnsOrder, predicateColumns, listOfIndexedColumn, true); 338 booleanvalueexpression nonIndexedCondition0 = initializeNonIndexCondition(indexNonIndex); 339 if (listOfIndexedColumn.isEmpty()) { 340 return new Object [] {null, nonIndexedCondition0}; 341 } 342 return new Object [] { (_SingleColumnPredicate[]) listOfIndexedColumn.toArray(new SingleColumnPredicate[listOfIndexedColumn.size()]), nonIndexedCondition0}; 343 } 344 345 351 private booleanvalueexpression initializeNonIndexCondition(boolean[] indexNonIndex) throws DException { 352 booleanvalueexpression nonIndexedCondition0 = nonIndexedCondition; 353 for (int i = 0; i < indexNonIndex.length; ++i) { 354 if (!indexNonIndex[i]) { 355 if (!singleColumnPredicates[i].isLikePredicate()) { 356 nonIndexedCondition0 = BVEPlanMerger.addAndConditions(nonIndexedCondition0, getBooleanValueExpression(singleColumnPredicates[i].getPredicate())); 357 } 358 } 359 } 360 return nonIndexedCondition0; 361 } 362 363 383 private void extractIndexedPredicates(int indexToStartOn, boolean[] indexNonIndex, String [] indexColumns, boolean[] indexColumnsOrder, _SingleColumnPredicate[] predicateColumns, ArrayList listOfIndexedColumns, boolean flag) throws DException { 384 if (indexToStartOn >= indexColumns.length) { 385 return; 386 } 387 for (int j = 0; j < predicateColumns.length; ++j) { 388 int predicateType = predicateColumns[j].getPredicateType(); 389 if (predicateType == OperatorConstants.RANGE_PREDICATE) { 390 if (predicateColumns[j].getColumnName().equalsIgnoreCase(indexColumns[indexToStartOn])) { 391 listOfIndexedColumns.add(predicateColumns[j]); 392 ++indexToStartOn; 393 indexNonIndex[j] = true; flag = false; 395 } 396 continue; 397 } 398 399 400 if(predicateType == OperatorConstants.IN){ 401 if (predicateColumns[j].getColumnName().equalsIgnoreCase(indexColumns[indexToStartOn])) { 402 if(indexToStartOn==0){ 403 listOfIndexedColumns.add(predicateColumns[j]); 404 ++indexToStartOn; 405 indexNonIndex[j] = true; flag = false; 407 } 408 return; 409 } 410 } 411 412 if (indexColumns[indexToStartOn].equalsIgnoreCase(predicateColumns[j].getColumnName()) && (flag || predicateType == OperatorConstants.EQUALTO)) { 413 flag = predicateType != OperatorConstants.EQUALTO && predicateType != OperatorConstants.JOINCOMPARISONPREDICATE ? false : flag; 414 indexNonIndex[j] = true; listOfIndexedColumns.add(singleColumnPredicates[j]); 416 ++indexToStartOn; 417 if(flag) 418 extractIndexedPredicates(indexToStartOn, indexNonIndex, indexColumns, indexColumnsOrder, predicateColumns, listOfIndexedColumns, flag); 419 return; 420 } 421 } 422 } 423 428 public booleanvalueexpression getNonIndexedCondition() throws DException { 429 return nonIndexedCondition; 430 } 431 432 public _SingleColumnPredicate[] getSingleColumnPredicates() throws DException { 433 return singleColumnPredicates; 434 } 435 436 public void setNonIndexedCondition(booleanvalueexpression nonIndexedCondition0) { 437 nonIndexedCondition = nonIndexedCondition0; 438 } 439 440 public String getTableName() throws DException { 441 return tableDetails.getActualName(); 442 } 443 444 450 private booleanvalueexpression getBooleanValueExpression(predicate Predicate) throws DException { 451 return new booleanfactor(new booleantest(Predicate)); 452 } 453 460 private booleanvalueexpression generateBVE(SingleColumnPredicate[] singleColumnPredicates) throws DException { 461 booleanvalueexpression nonIndexedCondition = this.nonIndexedCondition; 462 for (int i = 0, length = singleColumnPredicates.length; i < length; ++i) { 463 nonIndexedCondition = BVEPlanMerger.addAndConditions(nonIndexedCondition, getBooleanValueExpression(singleColumnPredicates[i].getPredicate())); 464 } 465 return nonIndexedCondition; 466 } 467 public void setTableDetails(TableDetails tableDetails0) throws DException { 468 tableDetails = tableDetails0; 469 } 470 477 public void setIndexPosition(int indexPosition0) throws DException { 478 indexPosition = indexPosition0; 479 } 480 481 public String toString() { 482 String str = "ALLCOLUMNPREDICATE["; 483 str += "TABLEDETAIL = " + tableDetails + ""; 484 if (singleColumnPredicates != null) { 485 for (int i = 0; i < singleColumnPredicates.length; i++) { 486 str += "SINGLECOLPREDICATE[" + singleColumnPredicates[i] + "]"; 487 } 488 } 489 if (nonIndexedCondition != null) { 490 str += "NONINDEXEDCONDITION[" + nonIndexedCondition + "]"; 491 } 492 return str + "]"; 493 494 } 495 496 497 private boolean checkForFunctionalAndScalarColumn(ColumnDetails[] cd) throws DException{ 498 for (int i = 0; i < cd.length; i++) { 499 if(cd[i].getType()==TypeConstants.FUNCTIONAL || cd[i].getType()==TypeConstants.SCALARFUNCTION) 500 return true; 501 } 502 return false; 503 } 504 505 506 507 } 508 | Popular Tags |