Пример #1
0
 INT32 aggrSortParser::buildNode( const BSONElement &elem, const CHAR *pCLName,
                            qgmOptiTreeNode *&pNode, _qgmPtrTable *pTable,
                            _qgmParamTable *pParamTable )
 {
    INT32 rc = SDB_OK;
    qgmOptiSelect *pSelect = SDB_OSS_NEW qgmOptiSelect( pTable, pParamTable );
    PD_CHECK( pSelect!=NULL, SDB_OOM, error, PDERROR,
             "malloc failed!" );
    PD_CHECK( elem.type()==Object, SDB_INVALIDARG, error, PDERROR,
             "failed to parse the parameter(%s),type must be number!",
             elem.fieldName() );
    try
    {
       qgmOpField selectAll;
       rc = buildOrderBy( elem, pSelect->_orderby, pTable, pCLName );
       PD_RC_CHECK( rc, PDERROR,
                   "failed to build \"sort\" field(rc=%d)", rc );
       selectAll.type = SQL_GRAMMAR::WILDCARD;
       pSelect->_selector.push_back( selectAll );
       pSelect->_limit = -1;
       pSelect->_skip = 0;
       pSelect->_type = QGM_OPTI_TYPE_SELECT;
       pSelect->_hasFunc = FALSE;
       rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, pSelect->_alias );
       PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", AGGR_CL_DEFAULT_ALIAS );
       if ( pCLName != NULL )
       {
          qgmField clValAttr;
          qgmField clValRelegation;
          rc = pTable->getOwnField( pCLName, clValAttr );
          PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", pCLName );
          rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, pSelect->_collection.alias );
          PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", AGGR_CL_DEFAULT_ALIAS );
          pSelect->_collection.value = qgmDbAttr( clValRelegation, clValAttr );
          pSelect->_collection.type = SQL_GRAMMAR::DBATTR;
       }
    }
    catch ( std::exception &e )
    {
       PD_CHECK( SDB_INVALIDARG, SDB_INVALIDARG, error, PDERROR,
                "failed to parse the \"sort\", received unexpected error:%s",
                e.what() );
    }
    pNode = pSelect;
 done:
    return rc;
 error:
    SAFE_OSS_DELETE( pSelect );
    goto done;
 }
Пример #2
0
   INT32 aggrProjectParser::buildNode( const BSONElement &elem,
                                       const CHAR *pCLName,
                                       qgmOptiTreeNode *&pNode,
                                       _qgmPtrTable *pTable,
                                       _qgmParamTable *pParamTable )
   {
      INT32 rc = SDB_OK;
      BOOLEAN hasFunc = FALSE;
      BSONObj obj;

      qgmOptiSelect *pSelect = SDB_OSS_NEW qgmOptiSelect( pTable, pParamTable );
      PD_CHECK( pSelect!=NULL, SDB_OOM, error, PDERROR,
               "malloc failed" );

      PD_CHECK( elem.type() == Object, SDB_INVALIDARG, error, PDERROR,
               "failed to parse the parameter:%s(type=%d, expectType=%d)",
               elem.fieldName(), elem.type(), Object );

      try
      {
         obj = elem.embeddedObject();
         {
            PD_CHECK( !obj.isEmpty(), SDB_INVALIDARG, error, PDERROR,
                     "Parameter-object can't be empty!" );
         }
         BSONObjIterator iter( obj );
         while ( iter.more() )
         {
            BSONElement beField = iter.next();
            const CHAR *pFieldName = beField.fieldName();
            PD_CHECK( pFieldName[0] != AGGR_KEYWORD_PREFIX, SDB_INVALIDARG, error, PDERROR,
                     "failed to parse \"project\", field name can't begin with\"$\"!" );

            rc = parseSelectorField( beField, pCLName, pSelect->_selector,
                                    pTable, hasFunc );
            PD_RC_CHECK( rc, PDERROR, "failed to parse the field:%s", pFieldName );
         }
         if ( pSelect->_selector.empty() )
         {
            qgmOpField selectAll;
            selectAll.type = SQL_GRAMMAR::WILDCARD;
            pSelect->_selector.push_back( selectAll );
         }
      }
      catch ( std::exception &e )
      {
         PD_CHECK( SDB_INVALIDARG, SDB_INVALIDARG, error, PDERROR,
                  "failed to parse the Parameter-object, received unexpected error:%s",
                  e.what() );
      }

      pSelect->_limit = -1;
      pSelect->_skip = 0;
      pSelect->_type = QGM_OPTI_TYPE_SELECT;
      pSelect->_hasFunc = hasFunc;
      rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, pSelect->_alias );
      PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", AGGR_CL_DEFAULT_ALIAS );
      if ( pCLName != NULL )
      {
         qgmField clValAttr;
         qgmField clValRelegation;
         rc = pTable->getOwnField( pCLName, clValAttr );
         PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", pCLName );
         rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, pSelect->_collection.alias );
         PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", AGGR_CL_DEFAULT_ALIAS );
         pSelect->_collection.value = qgmDbAttr( clValRelegation, clValAttr );
         pSelect->_collection.type = SQL_GRAMMAR::DBATTR;
      }
      
      pNode = pSelect;
   done:
      return rc;
   error:
      SAFE_OSS_DELETE( pSelect );
      goto done;
   }
Пример #3
0
   /*
      aggrLimitParser implement
   */
   INT32 aggrLimitParser::buildNode( const BSONElement &elem,
                                     const CHAR *pCLName,
                                     qgmOptiTreeNode *&pNode,
                                     _qgmPtrTable *pTable,
                                     _qgmParamTable *pParamTable )
   {
      INT32 rc = SDB_OK ;
      qgmOptiSelect *pSelect = NULL ;

      pSelect = SDB_OSS_NEW qgmOptiSelect( pTable, pParamTable ) ;
      PD_CHECK( pSelect != NULL, SDB_OOM, error, PDERROR,
               "Malloc failed!" ) ;

      PD_CHECK( elem.isNumber(), SDB_INVALIDARG, error, PDERROR,
                "Failed to parse the parameter(%s),type must be number!",
                elem.toString( TRUE, TRUE ).c_str() ) ;

      try
      {
         qgmOpField selectAll ;
         selectAll.type = SQL_GRAMMAR::WILDCARD;
         pSelect->_selector.push_back( selectAll ) ;
         pSelect->_limit = elem.numberLong() ;
         pSelect->_skip = 0 ;
         pSelect->_type = QGM_OPTI_TYPE_SELECT ;
         pSelect->_hasFunc = FALSE ;

         rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS, pSelect->_alias ) ;
         PD_RC_CHECK( rc, PDERROR, "Failed to get the field[%s], rc: %d",
                      AGGR_CL_DEFAULT_ALIAS, rc ) ;

         if ( pCLName != NULL )
         {
            qgmField clValAttr ;
            qgmField clValRelegation ;
            rc = pTable->getOwnField( pCLName, clValAttr ) ;
            PD_RC_CHECK( rc, PDERROR, "Failed to get the field[%s], rc: %d",
                         pCLName, rc ) ;
            rc = pTable->getOwnField( AGGR_CL_DEFAULT_ALIAS,
                                      pSelect->_collection.alias ) ;
            PD_RC_CHECK( rc, PDERROR, "Failed to get the field[%s], rc: %d",
                         AGGR_CL_DEFAULT_ALIAS, rc ) ;

            pSelect->_collection.value = qgmDbAttr( clValRelegation,
                                                    clValAttr ) ;
            pSelect->_collection.type = SQL_GRAMMAR::DBATTR ;
         }
      }
      catch ( std::exception &e )
      {
         PD_CHECK( FALSE, SDB_INVALIDARG, error, PDERROR,
                   "Failed to parse the \"limit\", occur unexpection: %s",
                   e.what() ) ;
      }

      pNode = pSelect ;

   done:
      return rc ;
   error:
      SAFE_OSS_DELETE( pSelect ) ;
      goto done ;
   }