// PD_TRACE_DECLARE_FUNCTION ( SDB_CLSCATAMATCHER_PARSEANOBJ, "clsCatalogMatcher::parseAnObj" ) INT32 clsCatalogMatcher::parseAnObj( const BSONObj &matcher, clsCatalogPredicateTree &predicateSet ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_CLSCATAMATCHER_PARSEANOBJ ) ; clsCatalogPredicateTree *pPredicateSet = NULL; BOOLEAN isNew = FALSE ; try { BSONObjIterator i( matcher ) ; while ( i.more() ) { BSONElement beTmp = i.next(); const CHAR *pFieldName = beTmp.fieldName() ; if ( predicateSet.getLogicType() == CLS_CATA_LOGIC_OR ) { pPredicateSet = SDB_OSS_NEW clsCatalogPredicateTree( _shardingKey ) ; PD_CHECK( pPredicateSet != NULL, SDB_OOM, error, PDERROR, "malloc failed" ) ; isNew = TRUE ; } else { pPredicateSet = &predicateSet ; } if ( MTH_OPERATOR_EYECATCHER == pFieldName[0] ) { rc = parseLogicOp( beTmp, *pPredicateSet ); } else { rc = parseCmpOp( beTmp, *pPredicateSet ); } PD_RC_CHECK( rc, PDERROR, "Failed to parse the field(rc=%d)", rc ) ; if ( isNew ) { predicateSet.addChild( pPredicateSet ) ; } if ( predicateSet.getLogicType() == CLS_CATA_LOGIC_OR && predicateSet.isUniverse() ) { goto done ; } } } catch ( std::exception &e ) { rc = SDB_INVALIDARG ; PD_RC_CHECK( rc, PDERROR, "Failed to parse the matcher(%s), " "occured unexpected error:%s", matcher.toString( false, false ).c_str(), e.what() ) ; } done: PD_TRACE_EXITRC ( SDB_CLSCATAMATCHER_PARSEANOBJ, rc ) ; return rc; error: if ( isNew ) { SDB_OSS_DEL( pPredicateSet ); pPredicateSet = NULL; } goto done; }
// PD_TRACE_DECLARE_FUNCTION ( SDB_CLSCATAMATCHER_PARSELOGICOP, "clsCatalogMatcher::parseLogicOp" ) INT32 clsCatalogMatcher::parseLogicOp( const BSONElement & beField, clsCatalogPredicateTree & predicateSet ) { INT32 rc = SDB_OK; PD_TRACE_ENTRY ( SDB_CLSCATAMATCHER_PARSELOGICOP ) ; clsCatalogPredicateTree *pPredicateSet = NULL ; BOOLEAN isNew = FALSE ; CLS_CATA_LOGIC_TYPE logicType = CLS_CATA_LOGIC_INVALID ; try { const CHAR *pFieldName = beField.fieldName() ; if ( beField.type() == Array ) { if ( 'a' == pFieldName[1] && 'n' == pFieldName[2] && 'd' == pFieldName[3] && 0 == pFieldName[4] ) { logicType = CLS_CATA_LOGIC_AND ; predicateSet.setLogicType( CLS_CATA_LOGIC_AND ) ; pPredicateSet = &predicateSet; } else if( 'o' == pFieldName[1] && 'r' == pFieldName[2] && 0 == pFieldName[3] ) { if ( predicateSet.getLogicType() != CLS_CATA_LOGIC_INVALID ) { pPredicateSet = SDB_OSS_NEW clsCatalogPredicateTree( _shardingKey ); PD_CHECK( pPredicateSet != NULL, SDB_OOM, error, PDERROR, "malloc failed" ) ; pPredicateSet->setLogicType( CLS_CATA_LOGIC_OR ) ; isNew = TRUE ; } else { predicateSet.setLogicType( CLS_CATA_LOGIC_OR ) ; pPredicateSet = &predicateSet ; } logicType = CLS_CATA_LOGIC_OR ; } else // parse "$not" { } if ( logicType != CLS_CATA_LOGIC_INVALID ) { BSONObjIterator iter( beField.embeddedObject() ); while ( iter.more() ) { BSONElement beTmp = iter.next(); BSONObj boTmp = beTmp.embeddedObject(); rc = parseAnObj( boTmp, *pPredicateSet ); PD_RC_CHECK( rc, PDERROR, "Failed to parse the field(rc=%d)", rc ) ; } if ( isNew ) { predicateSet.addChild( pPredicateSet ) ; } goto done ; } } if ( predicateSet.getLogicType() == CLS_CATA_LOGIC_OR ) { predicateSet.upgradeToUniverse(); } } catch ( std::exception &e ) { rc = SDB_INVALIDARG; PD_RC_CHECK( rc, PDERROR, "Failed to parse the field occured " "unexpected error:%s", e.what() ); } done: PD_TRACE_EXITRC ( SDB_CLSCATAMATCHER_PARSELOGICOP, rc ) ; return rc; error: if ( isNew ) { SDB_OSS_DEL( pPredicateSet ); pPredicateSet = NULL; } goto done; }