2222namespace mongo {
2323
2424 // static
25- Status CanonicalQuery::canonicalize (QueryMessage& qm, CanonicalQuery** out) {
25+ Status CanonicalQuery::canonicalize (const QueryMessage& qm, CanonicalQuery** out) {
2626 auto_ptr<CanonicalQuery> cq (new CanonicalQuery ());
2727
28- // TODO: LiteParsedQuery throws. Fix it to return error.
29- cq->_pq .reset (new LiteParsedQuery (qm));
30-
31- // TODO: If pq.hasOption(QueryOption_CursorTailable) make sure it's a capped collection and
32- // make sure the order(??) is $natural: 1.
33-
34- // TODO: Do we want to do this too?:
35- // if ( pq.getFields() != NULL )
36- // pq.getFields()->validateQuery( query );
28+ // Parse the query.
29+ LiteParsedQuery* lpq;
30+ Status parseStatus = LiteParsedQuery::make (qm, &lpq);
31+ if (!parseStatus.isOK ()) { return parseStatus; }
32+ cq->_pq .reset (lpq);
3733
34+ // Build a parse tree from the BSONObj in the parsed query.
3835 StatusWithMatchExpression swme = MatchExpressionParser::parse (cq->_pq ->getFilter ());
39- if (!swme.isOK ()) {
40- return swme.getStatus ();
41- }
36+ if (!swme.isOK ()) { return swme.getStatus (); }
4237
4338 cq->_root .reset (swme.getValue ());
4439 *out = cq.release ();
@@ -49,11 +44,10 @@ namespace mongo {
4944 CanonicalQuery** out) {
5045 auto_ptr<CanonicalQuery> cq (new CanonicalQuery ());
5146
52- // LiteParsedQuery saves the pointer to the NS that we provide it. It's not going to remain
53- // valid unless we cache it ourselves.
54- cq->_ns = ns;
55-
56- cq->_pq .reset (new LiteParsedQuery (cq->_ns .c_str (), 0 , 0 , 0 , query));
47+ LiteParsedQuery* lpq;
48+ Status parseStatus = LiteParsedQuery::make (ns, 0 , 0 , 0 , query, &lpq);
49+ if (!parseStatus.isOK ()) { return parseStatus; }
50+ cq->_pq .reset (lpq);
5751
5852 StatusWithMatchExpression swme = MatchExpressionParser::parse (cq->_pq ->getFilter ());
5953 if (!swme.isOK ()) { return swme.getStatus (); }
0 commit comments