~ubuntu-branches/ubuntu/utopic/mongodb/utopic

« back to all changes in this revision

Viewing changes to src/mongo/db/pipeline/document_source_filter.cpp

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-07-03 09:23:46 UTC
  • mfrom: (1.3.10) (44.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20140703092346-c5bvt46wnzougyly
Tags: 1:2.6.3-0ubuntu1
* New upstream stable release:
  - Dropped patches, included upstream:
    + 0003-All-platforms-but-Windows-find-hash-in-std-tr1.patch
    + 0008-Use-system-libstemmer.patch
    + 0011-Use-a-signed-char-to-store-BSONType-enumerations.patch
    + 0001-SERVER-12064-Atomic-operations-for-gcc-non-Intel-arc.patch
    + 0002-SERVER-12065-Support-ARM-and-AArch64-builds.patch
  - d/p/*: Refreshed/rebased remaining patches.
  - Use system provided libyaml-cpp:
    + d/control: Add libyaml-cpp-dev to BD's.
    + d/rules: Enable --with-system-yaml option.
    + d/p/fix-yaml-detection.patch: Fix detection of libyaml-cpp library.
  - d/mongodb-server.mongodb.upstart: Sync changes from upstream.
  - d/control,mongodb-dev.*: Drop mongodb-dev package; it has no reverse
    dependencies and upstream no longer install header files.
  - d/NEWS: Point users to upstream upgrade documentation for upgrades
    from 2.4 to 2.6.
* Merge from Debian unstable.
* d/control: BD on libv8-3.14-dev to ensure that transitioning to new v8
  versions is a explicit action due to changes in behaviour in >= 3.25
  (LP: #1295723).
* d/mongodb-server.prerm: Dropped debug echo call from maintainer script
  (LP: #1294455).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
*    Copyright (C) 2011 10gen Inc.
3
 
*
4
 
*    This program is free software: you can redistribute it and/or  modify
5
 
*    it under the terms of the GNU Affero General Public License, version 3,
6
 
*    as published by the Free Software Foundation.
7
 
*
8
 
*    This program is distributed in the hope that it will be useful,
9
 
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
*    GNU Affero General Public License for more details.
12
 
*
13
 
*    You should have received a copy of the GNU Affero General Public License
14
 
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
*/
16
 
 
17
 
#include "pch.h"
18
 
 
19
 
#include "db/pipeline/document_source.h"
20
 
 
21
 
#include "db/jsobj.h"
22
 
#include "db/pipeline/expression.h"
23
 
#include "db/pipeline/value.h"
24
 
 
25
 
namespace mongo {
26
 
 
27
 
    const char DocumentSourceFilter::filterName[] = "$filter";
28
 
 
29
 
    DocumentSourceFilter::~DocumentSourceFilter() {
30
 
    }
31
 
 
32
 
    const char *DocumentSourceFilter::getSourceName() const {
33
 
        return filterName;
34
 
    }
35
 
 
36
 
    bool DocumentSourceFilter::coalesce(
37
 
        const intrusive_ptr<DocumentSource> &pNextSource) {
38
 
 
39
 
        /* we only know how to coalesce other filters */
40
 
        DocumentSourceFilter *pDocFilter =
41
 
            dynamic_cast<DocumentSourceFilter *>(pNextSource.get());
42
 
        if (!pDocFilter)
43
 
            return false;
44
 
 
45
 
        /*
46
 
          Two adjacent filters can be combined by creating a conjunction of
47
 
          their predicates.
48
 
         */
49
 
        intrusive_ptr<ExpressionNary> pAnd(ExpressionAnd::create());
50
 
        pAnd->addOperand(pFilter);
51
 
        pAnd->addOperand(pDocFilter->pFilter);
52
 
        pFilter = pAnd;
53
 
 
54
 
        return true;
55
 
    }
56
 
 
57
 
    void DocumentSourceFilter::optimize() {
58
 
        pFilter = pFilter->optimize();
59
 
    }
60
 
 
61
 
    void DocumentSourceFilter::sourceToBson(
62
 
        BSONObjBuilder *pBuilder, bool explain) const {
63
 
        pFilter->addToBsonObj(pBuilder, filterName, false);
64
 
    }
65
 
 
66
 
    bool DocumentSourceFilter::accept(const Document& pDocument) const {
67
 
        Value pValue(pFilter->evaluate(pDocument));
68
 
        return pValue.coerceToBool();
69
 
    }
70
 
 
71
 
    intrusive_ptr<DocumentSource> DocumentSourceFilter::createFromBson(
72
 
        BSONElement *pBsonElement,
73
 
        const intrusive_ptr<ExpressionContext> &pCtx) {
74
 
        uassert(15946, "a document filter expression must be an object",
75
 
                pBsonElement->type() == Object);
76
 
 
77
 
        Expression::ObjectCtx oCtx(0);
78
 
        intrusive_ptr<Expression> pExpression(
79
 
            Expression::parseObject(pBsonElement, &oCtx));
80
 
        intrusive_ptr<DocumentSourceFilter> pFilter(
81
 
            DocumentSourceFilter::create(pExpression, pCtx));
82
 
 
83
 
        return pFilter;
84
 
    }
85
 
 
86
 
    intrusive_ptr<DocumentSourceFilter> DocumentSourceFilter::create(
87
 
        const intrusive_ptr<Expression> &pFilter,
88
 
        const intrusive_ptr<ExpressionContext> &pExpCtx) {
89
 
        intrusive_ptr<DocumentSourceFilter> pSource(
90
 
            new DocumentSourceFilter(pFilter, pExpCtx));
91
 
        return pSource;
92
 
    }
93
 
 
94
 
    DocumentSourceFilter::DocumentSourceFilter(
95
 
        const intrusive_ptr<Expression> &pTheFilter,
96
 
        const intrusive_ptr<ExpressionContext> &pExpCtx):
97
 
        DocumentSourceFilterBase(pExpCtx),
98
 
        pFilter(pTheFilter) {
99
 
    }
100
 
 
101
 
    void DocumentSourceFilter::toMatcherBson(BSONObjBuilder *pBuilder) const {
102
 
        pFilter->toMatcherBson(pBuilder);
103
 
    }
104
 
}