// PD_TRACE_DECLARE_FUNCTION ( SDB_CLSCATAMATCHER_PARSECMPOP, "clsCatalogMatcher::parseCmpOp" )
 INT32 clsCatalogMatcher::parseCmpOp( const  BSONElement & beField,
                                      clsCatalogPredicateTree & predicateSet )
 {
    INT32 rc = SDB_OK;
    PD_TRACE_ENTRY ( SDB_CLSCATAMATCHER_PARSECMPOP ) ;
    const CHAR *pFieldName = NULL ;
    predicateSet.setLogicType( CLS_CATA_LOGIC_AND ) ;
    BSONObj boValue;
    try
    {
       pFieldName = beField.fieldName() ;
       BSONElement beTmp = _shardingKey.getField( pFieldName );
       if ( beTmp.eoo() )
       {
          // ignore the field which is not sharding-key
          goto done ;
       }
       if ( beField.type() == Object )
       {
          boValue = beField.embeddedObject() ;
          if ( isOpObj( boValue ))
          {
             BSONObjIterator i( boValue );
             while( i.more() )
             {
                BSONElement beTmp = i.next();
                rc = predicateSet.addPredicate( pFieldName, beTmp );
                PD_RC_CHECK( rc, PDERROR,
                            "failed to add predicate(rc=%d)", rc );
             }
             goto done;
          }
       }
       rc = predicateSet.addPredicate( pFieldName, beField );
       PD_RC_CHECK( rc, PDERROR,
                   "failed to add predicate(rc=%d)", rc );
    }
    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_PARSECMPOP, rc ) ;
    return rc;
 error:
    goto done;
 }
示例#2
0
   // 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;
   }