#include <PredicateImpl.h>
Inheritance diagram for PredicateImpl:
Public Member Functions | |
PredicateImpl () | |
~PredicateImpl () | |
void | setTerm (const char *fName1, ComparisionOp op, const char *fName2) |
void | setTerm (const char *fName1, ComparisionOp op, void *opnd) |
void | setTerm (const char *fName1, ComparisionOp op, void **opnd) |
void | setTerm (Predicate *p1, LogicalOp op, Predicate *p2=NULL) |
void * | valPtrForIndexField (const char *name) |
DbRetVal | evaluate (bool &result) |
void | setTable (Table *tbl) |
void | setTuple (void *tpl) |
bool | isSingleTerm () |
bool | isNotOrInvolved () |
bool | pointLookupInvolved (const char *fName) |
void | print () |
Definition at line 23 of file PredicateImpl.h.
PredicateImpl::PredicateImpl | ( | ) | [inline] |
Definition at line 42 of file PredicateImpl.h.
00043 { 00044 strcpy(fldName1, ""); strcpy(fldName2, ""); 00045 operand = NULL; operandPtr = NULL; lhs = rhs = NULL; 00046 tuple = NULL; table = NULL; 00047 }
PredicateImpl::~PredicateImpl | ( | ) | [inline] |
DbRetVal PredicateImpl::evaluate | ( | bool & | result | ) |
Definition at line 133 of file PredicateImpl.cxx.
References AllDataType::compareVal(), DM_Predicate, ErrInvalidExpr, evaluate(), TableImpl::getFieldLength(), TableImpl::getFieldOffset(), TableImpl::getFieldType(), OK, OpAnd, OpNot, OpOr, and printDebug.
Referenced by evaluate(), and TupleIterator::next().
00134 { 00135 bool rhsResult = false, lhsResult=false; 00136 printDebug(DM_Predicate, "Evaluate start logical:%d compOp:%d", logicalOp, compOp); 00137 DbRetVal retCode =OK; 00138 result = false; 00139 if (NULL != lhs) 00140 { 00141 retCode = lhs->evaluate(lhsResult); 00142 printDebug(DM_Predicate, "LHS result %d retcode: %d", lhsResult, retCode); 00143 if (retCode != OK) return ErrInvalidExpr; 00144 } 00145 if (NULL != rhs) 00146 { 00147 retCode = rhs->evaluate(rhsResult); 00148 printDebug(DM_Predicate, "RHS result %d retcode:%d", rhsResult, retCode); 00149 if (retCode != OK) return ErrInvalidExpr; 00150 } 00151 if (NULL != lhs) 00152 { 00153 //Means it involves only Logical operator 00154 printDebug(DM_Predicate,"Evalute operator %d lhsResult %d : rhsResult %d", logicalOp, lhsResult, rhsResult ); 00155 switch(logicalOp) 00156 { 00157 case OpAnd: 00158 if (lhsResult && rhsResult) result = true; 00159 break; 00160 case OpOr: 00161 if (lhsResult || rhsResult) result = true; 00162 break; 00163 case OpNot: 00164 if (lhsResult) result = false; else result = true; 00165 break; 00166 default: 00167 return ErrInvalidExpr; 00168 00169 } 00170 printDebug(DM_Predicate, "result is %d", result); 00171 return OK; 00172 } 00173 printDebug(DM_Predicate, "Evaluating comparision predicate op:%d", compOp); 00174 //Means it is relational expression 00175 //first operand is always field identifier 00176 //get the value in the tuple 00177 int offset1, offset2; 00178 offset1 = table->getFieldOffset(fldName1); 00179 //TODO::do not call getFieldXXX many times, instead get it using getFieldInfo 00180 char *val1, *val2 ; 00181 //Assumes that fldName2 data type is also same for expr f1 <f2 00182 DataType srcType = table->getFieldType(fldName1); 00183 val1 = ((char*) tuple) + offset1; 00184 if (operand == NULL && operandPtr == NULL) 00185 { 00186 if (fldName2) { 00187 offset2 = table->getFieldOffset(fldName2); 00188 val2 = ((char*)tuple) + offset2; 00189 } 00190 } 00191 else if(operand != NULL && operandPtr == NULL) 00192 { 00193 val2 = (char*) operand; 00194 } 00195 else if(operand == NULL && operandPtr != NULL) 00196 { 00197 val2 = *(char**)operandPtr; 00198 } 00199 int ret = 0; 00200 printDebug(DM_Predicate, " fldname :%s ", fldName1); 00201 result = AllDataType::compareVal(val1, val2, compOp, srcType, 00202 table->getFieldLength(fldName1)); 00203 return OK; 00204 }
Here is the call graph for this function:
Here is the caller graph for this function:
bool PredicateImpl::isNotOrInvolved | ( | ) |
Definition at line 102 of file PredicateImpl.cxx.
References isNotOrInvolved(), OpAnd, OpNot, and OpOr.
Referenced by isNotOrInvolved().
00103 { 00104 bool lhsResult = true, rhsResult = true; 00105 if (NULL != lhs) 00106 { 00107 lhsResult = lhs->isNotOrInvolved(); 00108 } 00109 if (NULL != rhs) 00110 { 00111 rhsResult = rhs->isNotOrInvolved(); 00112 } 00113 if (NULL != lhs) 00114 { 00115 //Means it involves only Logical operator 00116 switch(logicalOp) 00117 { 00118 case OpAnd: 00119 if (lhsResult || rhsResult) return true; else return false; 00120 break; 00121 case OpOr: 00122 return true; 00123 break; 00124 case OpNot: 00125 default: 00126 return true; 00127 break; 00128 } 00129 } 00130 return false; 00131 }
Here is the call graph for this function:
Here is the caller graph for this function:
bool PredicateImpl::isSingleTerm | ( | ) |
bool PredicateImpl::pointLookupInvolved | ( | const char * | fName | ) |
Definition at line 206 of file PredicateImpl.cxx.
References OpAnd, OpEquals, OpNot, OpOr, and pointLookupInvolved().
Referenced by pointLookupInvolved().
00207 { 00208 bool rhsResult, lhsResult; 00209 if (NULL != lhs) 00210 { 00211 lhsResult = lhs->pointLookupInvolved(fname); 00212 } 00213 if (NULL != rhs) 00214 { 00215 rhsResult = rhs->pointLookupInvolved(fname); 00216 } 00217 if (NULL != lhs) 00218 { 00219 //Means it involves only Logical operator 00220 switch(logicalOp) 00221 { 00222 case OpAnd: 00223 //return lhsResult; 00224 if (lhsResult || rhsResult) return true; else return false; 00225 break; 00226 case OpOr: 00227 return false; 00228 break; 00229 case OpNot: 00230 default: 00231 return false; 00232 break; 00233 } 00234 } 00235 //Means it is relational expression 00236 //first operand is always field identifier 00237 if (OpEquals == compOp) 00238 { 00239 //for expressions f1 == f2 use full scan, so return false 00240 if(NULL == operand && NULL == operandPtr) return false; 00241 if(0 == strcmp(fldName1, fname)) 00242 { 00243 return true; 00244 } 00245 } 00246 return false; 00247 }
Here is the call graph for this function:
Here is the caller graph for this function:
void PredicateImpl::print | ( | ) | [virtual] |
Implements Predicate.
Definition at line 24 of file PredicateImpl.cxx.
00025 { 00026 printf("FieldName1 %s, FieldName2 %s", fldName1, fldName2); 00027 printf("CompOp %d, operand %x operandPtr%x", compOp, operand); 00028 printf("lhs %x, rhs %x", lhs, rhs); 00029 00030 }
void PredicateImpl::setTable | ( | Table * | tbl | ) |
Definition at line 79 of file PredicateImpl.cxx.
References setTable().
Referenced by TableImpl::execute(), and setTable().
00080 { 00081 if (NULL != lhs) 00082 lhs->setTable((TableImpl*)tbl); 00083 if (NULL != rhs) 00084 rhs->setTable((TableImpl*)tbl); 00085 table = (TableImpl*)tbl; 00086 }
Here is the call graph for this function:
Here is the caller graph for this function:
Implements Predicate.
Definition at line 66 of file PredicateImpl.cxx.
References OpInvalidComparisionOp, and OpNot.
00067 { 00068 if (p2 == NULL && op != OpNot || op == OpNot && p2 != NULL) 00069 { 00070 //TODO::printError 00071 return; 00072 } 00073 lhs = (PredicateImpl*)p1; 00074 rhs = (PredicateImpl*)p2; 00075 logicalOp = op; 00076 compOp = OpInvalidComparisionOp; 00077 }
void PredicateImpl::setTerm | ( | const char * | fName1, | |
ComparisionOp | op, | |||
void ** | opnd | |||
) | [virtual] |
Implements Predicate.
Definition at line 55 of file PredicateImpl.cxx.
References OpInvalidLogicalOp.
00056 { 00057 strcpy(fldName1, fName1); 00058 compOp = op; 00059 operand = NULL; 00060 operandPtr = opnd; 00061 lhs = rhs = NULL; 00062 logicalOp = OpInvalidLogicalOp; 00063 }
void PredicateImpl::setTerm | ( | const char * | fName1, | |
ComparisionOp | op, | |||
void * | opnd | |||
) | [virtual] |
Implements Predicate.
Definition at line 45 of file PredicateImpl.cxx.
References OpInvalidLogicalOp.
00046 { 00047 strcpy(fldName1, fName1); 00048 compOp = op; 00049 operand = opnd; 00050 operandPtr = NULL; 00051 lhs = rhs = NULL; 00052 logicalOp = OpInvalidLogicalOp; 00053 }
void PredicateImpl::setTerm | ( | const char * | fName1, | |
ComparisionOp | op, | |||
const char * | fName2 | |||
) | [virtual] |
Implements Predicate.
Definition at line 32 of file PredicateImpl.cxx.
References OpInvalidLogicalOp.
Referenced by ParsedData::insertPredicate().
00034 { 00035 strcpy(fldName1, fName1); 00036 strcpy(fldName2, fName2); 00037 compOp = op; 00038 operand = NULL; 00039 operandPtr = NULL; 00040 lhs = rhs = NULL; 00041 logicalOp = OpInvalidLogicalOp; 00042 }
Here is the caller graph for this function:
void PredicateImpl::setTuple | ( | void * | tpl | ) |
Definition at line 88 of file PredicateImpl.cxx.
References setTuple().
Referenced by TupleIterator::next(), and setTuple().
00089 { 00090 if (NULL != lhs) 00091 lhs->setTuple(tpl); 00092 if (NULL != rhs) 00093 rhs->setTuple(tpl); 00094 tuple = tpl; 00095 }
Here is the call graph for this function:
Here is the caller graph for this function:
void * PredicateImpl::valPtrForIndexField | ( | const char * | name | ) |
Definition at line 249 of file PredicateImpl.cxx.
References OpEquals, and valPtrForIndexField().
Referenced by TupleIterator::open(), and valPtrForIndexField().
00250 { 00251 void *lhsRet, *rhsRet; 00252 if (NULL != lhs) 00253 { 00254 lhsRet = lhs->valPtrForIndexField(fname); 00255 } 00256 if (NULL != rhs) 00257 { 00258 rhsRet = rhs->valPtrForIndexField(fname); 00259 } 00260 if (NULL != lhs) 00261 { 00262 //Means it involves only Logical operator 00263 if ( lhsRet != NULL) return lhsRet; 00264 if ( rhsRet != NULL) return rhsRet; 00265 } 00266 //Means it is relational expression 00267 //first operand is always field identifier 00268 if (OpEquals == compOp) 00269 { 00270 if(0 == strcmp(fldName1, fname)) 00271 { 00272 if (operand) return operand; else return *(void**)operandPtr; 00273 } 00274 } 00275 return NULL; 00276 }
Here is the call graph for this function:
Here is the caller graph for this function: