bool DBClientCursorShimArray::more() { bool r = false; if (!has_array) { if (cursor.rawMore()) { BSONObj val = cursor.rawNext(); if (val.hasField(array_field)) { BSONObj arr = val[array_field].Obj(); if (!arr.isEmpty()) { iter = BSONObjIterator(arr); r = true; } } } has_array = true; } else { r = iter.more(); } return r; }
StatusWith<std::vector<LogComponentSetting>> parseLogComponentSettings(const BSONObj& settings) { typedef std::vector<LogComponentSetting> Result; std::vector<LogComponentSetting> levelsToSet; std::vector<BSONObjIterator> iterators; LogComponent parentComponent = LogComponent::kDefault; BSONObjIterator iter(settings); while (iter.moreWithEOO()) { BSONElement elem = iter.next(); if (elem.eoo()) { if (!iterators.empty()) { iter = iterators.back(); iterators.pop_back(); parentComponent = parentComponent.parent(); } continue; } if (elem.fieldNameStringData() == "verbosity") { if (!elem.isNumber()) { return StatusWith<Result>(ErrorCodes::BadValue, str::stream() << "Expected " << parentComponent.getDottedName() << ".verbosity to be a number, but found " << typeName(elem.type())); } levelsToSet.push_back((LogComponentSetting(parentComponent, elem.numberInt()))); continue; } const StringData shortName = elem.fieldNameStringData(); const LogComponent curr = _getComponentForShortName(shortName); if (curr == LogComponent::kNumLogComponents || curr.parent() != parentComponent) { return StatusWith<Result>( ErrorCodes::BadValue, str::stream() << "Invalid component name " << parentComponent.getDottedName() << "." << shortName); } if (elem.isNumber()) { levelsToSet.push_back(LogComponentSetting(curr, elem.numberInt())); continue; } if (elem.type() != Object) { return StatusWith<Result>(ErrorCodes::BadValue, str::stream() << "Invalid type " << typeName(elem.type()) << "for component " << parentComponent.getDottedName() << "." << shortName); } iterators.push_back(iter); parentComponent = curr; iter = BSONObjIterator(elem.Obj()); } // Done walking settings return StatusWith<Result>(levelsToSet); }
void S2NearIndexCursor::seek(const BSONObj& query, const NearQuery& nearQuery, const vector<GeoQuery>& regions) { _indexedGeoFields = regions; _nearQuery = nearQuery; _returnedDistance = 0; _nearFieldIndex = 0; _stats = Stats(); _returned = unordered_set<DiskLoc, DiskLoc::Hasher>(); _results = priority_queue<Result>(); BSONObjBuilder geoFieldsToNuke; for (size_t i = 0; i < _indexedGeoFields.size(); ++i) { geoFieldsToNuke.append(_indexedGeoFields[i].getField(), ""); } // false means we want to filter OUT geoFieldsToNuke, not filter to include only that. _filteredQuery = query.filterFieldsUndotted(geoFieldsToNuke.obj(), false); // More indexing machinery. BSONObjBuilder specBuilder; BSONObjIterator specIt(_descriptor->keyPattern()); while (specIt.more()) { BSONElement e = specIt.next(); // Checked in AccessMethod already, so we know this spec has only numbers and 2dsphere if ( e.type() == String ) { specBuilder.append( e.fieldName(), 1 ); } else { specBuilder.append( e.fieldName(), e.numberInt() ); } } _specForFRV = specBuilder.obj(); specIt = BSONObjIterator(_descriptor->keyPattern()); while (specIt.more()) { if (specIt.next().fieldName() == _nearQuery.field) { break; } ++_nearFieldIndex; } _minDistance = max(0.0, _nearQuery.minDistance); // _outerRadius can't be greater than (pi * r) or we wrap around the opposite // side of the world. _maxDistance = min(M_PI * _params.radius, _nearQuery.maxDistance); uassert(16892, "$minDistance too large", _minDistance < _maxDistance); // Start with a conservative _radiusIncrement. _radiusIncrement = 5 * S2::kAvgEdge.GetValue(_params.finestIndexedLevel) * _params.radius; _innerRadius = _outerRadius = _minDistance; // We might want to adjust the sizes of our coverings if our search // isn't local to the start point. // Set up _outerRadius with proper checks (maybe maxDistance is really small?) nextAnnulus(); fillResults(); }
S2NearCursor::S2NearCursor(const BSONObj &keyPattern, const IndexDetails *details, const BSONObj &query, const NearQuery &nearQuery, const vector<GeoQuery> &indexedGeoFields, const S2IndexingParams ¶ms) : _details(details), _nearQuery(nearQuery), _indexedGeoFields(indexedGeoFields), _params(params), _keyPattern(keyPattern), _nearFieldIndex(0), _returnedDistance(0) { BSONObjBuilder geoFieldsToNuke; for (size_t i = 0; i < _indexedGeoFields.size(); ++i) { geoFieldsToNuke.append(_indexedGeoFields[i].getField(), ""); } // false means we want to filter OUT geoFieldsToNuke, not filter to include only that. _filteredQuery = query.filterFieldsUndotted(geoFieldsToNuke.obj(), false); _matcher.reset(new CoveredIndexMatcher(_filteredQuery, keyPattern)); // More indexing machinery. BSONObjBuilder specBuilder; BSONObjIterator specIt(_keyPattern); while (specIt.more()) { BSONElement e = specIt.next(); // Checked in AccessMethod already, so we know this spec has only numbers and 2dsphere if ( e.type() == String ) { specBuilder.append( e.fieldName(), 1 ); } else { specBuilder.append( e.fieldName(), e.numberInt() ); } } BSONObj spec = specBuilder.obj(); _specForFRV = IndexSpec(spec); specIt = BSONObjIterator(_keyPattern); while (specIt.more()) { if (specIt.next().fieldName() == _nearQuery.field) { break; } ++_nearFieldIndex; } // _outerRadius can't be greater than (pi * r) or we wrap around the opposite // side of the world. _maxDistance = min(M_PI * _params.radius, _nearQuery.maxDistance); // Start with a conservative _radiusIncrement. _radiusIncrement = 5 * S2::kAvgEdge.GetValue(_params.finestIndexedLevel) * _params.radius; _innerRadius = _outerRadius = 0; // We might want to adjust the sizes of our coverings if our search // isn't local to the start point. // Set up _outerRadius with proper checks (maybe maxDistance is really small?) nextAnnulus(); }
BSONObj DBClientCursorShimCursorID::get_cursor() { BSONObj b = cursor.rawNext(); BSONElement ele = b["cursor"]; if (!ele.eoo()) { cursor.cursorId = ele["id"].Long(); cursor.ns = ele["ns"].String(); if (!ele["firstBatch"].eoo()) { iter = BSONObjIterator(ele["firstBatch"].Obj()); in_first_batch = true; } } return b; }
INT32 aggrProjectParser::addObj( const CHAR *pAlias, const bson::BSONObj &Obj, const CHAR *pCLName, qgmOPFieldVec &selectorVec, _qgmPtrTable *pTable ) { INT32 rc = SDB_OK; CHAR *pFuncBuf = NULL; #define FUNC_NAME_BUILDOBJ "buildObj" try { UINT32 nameLen = ossStrlen( FUNC_NAME_BUILDOBJ ); UINT32 paramLen = 0; UINT32 fieldNum = 0; UINT32 curPos = 0; BSONObjIterator iter( Obj ); while ( iter.more() ) { BSONElement beField = iter.next(); PD_CHECK( beField.isNumber(), SDB_INVALIDARG, error, PDERROR, "field type must be number!" ); if ( beField.number() == 0 ) { continue; } ++fieldNum; paramLen += ossStrlen(AGGR_CL_DEFAULT_ALIAS) + 1 + ossStrlen( beField.fieldName() ); } PD_CHECK( fieldNum > 0, SDB_INVALIDARG, error, PDERROR, "Can't add empty obj!" ); paramLen += ( fieldNum - 1 ); 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, FUNC_NAME_BUILDOBJ ); pFuncBuf[ nameLen ] = '('; curPos = nameLen + 1; iter = BSONObjIterator( Obj ); while ( iter.more() ) { BSONElement beField = iter.next(); if ( beField.number() == 0 ) { continue; } ossStrcpy( ( pFuncBuf + curPos ), AGGR_CL_DEFAULT_ALIAS ); curPos += ossStrlen( AGGR_CL_DEFAULT_ALIAS ); pFuncBuf[ curPos ] = '.'; curPos += 1; ossStrcpy( ( pFuncBuf + curPos ), beField.fieldName() ); curPos += ossStrlen( beField.fieldName() ); if ( fieldNum > 1 ) { pFuncBuf[ curPos ] = ','; curPos += 1; } --fieldNum; } pFuncBuf[ curPos ] = ')'; curPos += 1; pFuncBuf[ curPos ] = 0; qgmField slValAttr; qgmField slValRelegation; 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 ); PD_RC_CHECK( rc, PDERROR, "failed to get the field(%s)", pAlias ); 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: SDB_OSS_FREE( pFuncBuf ); return rc; error: goto done; }
BSONObjIterator BSONObjBuilder::iterator() const { const char * s = _b.buf() + _offset; const char * e = _b.buf() + _b.len(); return BSONObjIterator( s , e ); }