Exemple #1
0
bson::BSONObj getCondObj( const bson::BSONObj& all )
{
    bson::BSONObj cond ;
    const char* cmdStr = all.firstElementFieldName() ;
    if ( all.hasField( "$query" ) )
    {
        cond = all.getObjectField( "$query" ) ;
    }
    else if ( all.hasField( "query" ) )
    {
        cond = all.getObjectField( "query" ) ;
    }
    else
    {
        cond = all ;
    }

    return cond ;
}
Exemple #2
0
   INT32 aggrProjectParser::addFunc( const CHAR *pAlias, const bson::BSONObj &funcObj,
                                    const CHAR *pCLName, qgmOPFieldVec &selectorVec,
                                    _qgmPtrTable *pTable )
   {
      INT32 rc = SDB_OK;
      CHAR *pFuncBuf = NULL;
      try
      {
         const CHAR *pFuncName = funcObj.firstElementFieldName();
         PD_CHECK( AGGR_KEYWORD_PREFIX == pFuncName[0], SDB_INVALIDARG, error, PDERROR,
                  "failed to parse selector field(%s), function name must begin with \"$\"",
                  pFuncName );
         const CHAR *pFuncParam = funcObj.firstElement().valuestr();
         PD_CHECK( AGGR_KEYWORD_PREFIX == pFuncParam[0], SDB_INVALIDARG, error, PDERROR,
                  "failed to parse selector field(%s), parameter must begin with \"$\"",
                  pFuncParam );

         qgmField slValAttr;
         qgmField slValRelegation;

         UINT32 nameLen = ossStrlen(&(pFuncName[1]));
         UINT32 paramLen = ossStrlen(AGGR_CL_DEFAULT_ALIAS) + 1 + ossStrlen(&(pFuncParam[1]));
         UINT32 curPos = 0;
         pFuncBuf = ( CHAR * )SDB_OSS_MALLOC( nameLen + 3 + paramLen );
         PD_CHECK( pFuncBuf != NULL, SDB_OOM, error, PDERROR,
                  "malloc failed(size=%d)", (nameLen + 3 + paramLen) );
         ossStrcpy( pFuncBuf, &(pFuncName[1]) );
         pFuncBuf[ nameLen ]='(';
         curPos = nameLen + 1;

         ossStrcpy( ( pFuncBuf + curPos), AGGR_CL_DEFAULT_ALIAS );
         curPos += ossStrlen(AGGR_CL_DEFAULT_ALIAS);
         pFuncBuf[ curPos ] = '.';
         curPos += 1;

         ossStrcpy( ( pFuncBuf + curPos ), &(pFuncParam[1]) );
         curPos += ossStrlen(&(pFuncParam[1]));
         pFuncBuf[ curPos ] = ')';
          curPos += 1;
         pFuncBuf[ curPos ] = 0;
         rc = pTable->getOwnField( pFuncBuf, slValAttr );
         PD_RC_CHECK( rc, PDERROR,
                     "failed to get the field(%s)",
                     pFuncBuf );
         qgmDbAttr slVal( slValRelegation, slValAttr );
         qgmField slAlias;
         rc = pTable->getOwnField( pAlias, slAlias );
         qgmOpField selector;
         selector.alias = slAlias;
         selector.value = slVal;
         selector.type = SQL_GRAMMAR::FUNC;
         selectorVec.push_back( selector );
      }
      catch ( std::exception &e )
      {
         PD_CHECK( SDB_INVALIDARG, SDB_INVALIDARG, error, PDERROR,
                  "failed to add function-field, received unexpected error:%s",
                  e.what() );
      }
   done:
      if ( pFuncBuf != NULL )
      {
         SDB_OSS_FREE( pFuncBuf );
      }
      return rc;
   error:
      goto done;
   }