62
63
@param deps output parameter
63
64
@param path path to self if all ancestors are ExpressionObjects.
64
65
Top-level ExpressionObject gets pointer to empty vector.
65
If any other Expression is an ancestor {a:1} object
66
aren't allowed, so they get NULL
66
If any other Expression is an ancestor, or in other cases
67
where {a:1} inclusion objects aren't allowed, they get
70
70
virtual void addDependencies(set<string>& deps, vector<string>* path=NULL) const = 0;
78
78
@returns the computed value
80
virtual intrusive_ptr<const Value> evaluate(
81
const intrusive_ptr<Document> &pDocument) const = 0;
80
virtual Value evaluate(const Document& pDocument) const = 0;
84
83
Add the Expression (and any descendant Expressions) into a BSON
95
94
$project which distinguish between field inclusion and virtual
96
95
field specification; See ExpressionConstant.
98
virtual void addToBsonObj(
99
BSONObjBuilder *pBuilder, string fieldName,
100
bool requireExpression) const = 0;
97
virtual void addToBsonObj(BSONObjBuilder *pBuilder,
99
bool requireExpression) const = 0;
103
102
Add the Expression (and any descendant Expressions) into a BSON
225
224
// virtuals from Expression
226
225
virtual intrusive_ptr<Expression> optimize();
227
virtual void addToBsonObj(
228
BSONObjBuilder *pBuilder, string fieldName,
229
bool requireExpression) const;
226
virtual void addToBsonObj(BSONObjBuilder *pBuilder,
227
StringData fieldName,
228
bool requireExpression) const;
230
229
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
231
230
virtual void addDependencies(set<string>& deps, vector<string>* path=NULL) const;
315
314
// virtuals from Expression
316
315
virtual ~ExpressionAdd();
317
virtual intrusive_ptr<const Value> evaluate(const intrusive_ptr<Document> &pDocument) const;
316
virtual Value evaluate(const Document& pDocument) const;
318
317
virtual const char *getOpName() const;
320
319
// virtuals from ExpressionNary
335
334
// virtuals from Expression
336
335
virtual ~ExpressionAnd();
337
336
virtual intrusive_ptr<Expression> optimize();
338
virtual intrusive_ptr<const Value> evaluate(
339
const intrusive_ptr<Document> &pDocument) const;
337
virtual Value evaluate(const Document& pDocument) const;
340
338
virtual const char *getOpName() const;
341
339
virtual void toMatcherBson(BSONObjBuilder *pBuilder) const;
366
364
virtual ~ExpressionCoerceToBool();
367
365
virtual intrusive_ptr<Expression> optimize();
368
366
virtual void addDependencies(set<string>& deps, vector<string>* path=NULL) const;
369
virtual intrusive_ptr<const Value> evaluate(
370
const intrusive_ptr<Document> &pDocument) const;
371
virtual void addToBsonObj(
372
BSONObjBuilder *pBuilder, string fieldName,
373
bool requireExpression) const;
367
virtual Value evaluate(const Document& pDocument) const;
368
virtual void addToBsonObj(BSONObjBuilder *pBuilder,
369
StringData fieldName,
370
bool requireExpression) const;
374
371
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
376
373
static intrusive_ptr<ExpressionCoerceToBool> create(
389
386
// virtuals from ExpressionNary
390
387
virtual ~ExpressionCompare();
391
388
virtual intrusive_ptr<Expression> optimize();
392
virtual intrusive_ptr<const Value> evaluate(
393
const intrusive_ptr<Document> &pDocument) const;
389
virtual Value evaluate(const Document& pDocument) const;
394
390
virtual const char *getOpName() const;
395
391
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
399
395
Provide for conformance with the uniform function pointer signature
400
396
required for parsing.
402
These create a particular comparision operand, without any
398
These create a particular comparison operand, without any
403
399
operands. Those must be added via ExpressionNary::addOperand().
405
401
static intrusive_ptr<ExpressionNary> createCmp();
421
class ExpressionCond :
422
public ExpressionNary {
417
class ExpressionConcat : public ExpressionNary {
419
// virtuals from ExpressionNary
420
virtual ~ExpressionConcat();
421
virtual Value evaluate(const Document& input) const;
422
virtual const char *getOpName() const;
424
static intrusive_ptr<ExpressionNary> create();
428
class ExpressionCond : public ExpressionNary {
424
430
// virtuals from ExpressionNary
425
431
virtual ~ExpressionCond();
426
virtual intrusive_ptr<const Value> evaluate(
427
const intrusive_ptr<Document> &pDocument) const;
432
virtual Value evaluate(const Document& pDocument) const;
428
433
virtual const char *getOpName() const;
429
434
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
442
447
virtual ~ExpressionConstant();
443
448
virtual intrusive_ptr<Expression> optimize();
444
449
virtual void addDependencies(set<string>& deps, vector<string>* path=NULL) const;
445
virtual intrusive_ptr<const Value> evaluate(
446
const intrusive_ptr<Document> &pDocument) const;
450
virtual Value evaluate(const Document& pDocument) const;
447
451
virtual const char *getOpName() const;
448
virtual void addToBsonObj(
449
BSONObjBuilder *pBuilder, string fieldName,
450
bool requireExpression) const;
452
virtual void addToBsonObj(BSONObjBuilder *pBuilder,
453
StringData fieldName,
454
bool requireExpression) const;
451
455
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
453
457
static intrusive_ptr<ExpressionConstant> createFromBsonElement(
454
458
BSONElement *pBsonElement);
455
static intrusive_ptr<ExpressionConstant> create(
456
const intrusive_ptr<const Value> &pValue);
459
static intrusive_ptr<ExpressionConstant> create(const Value& pValue);
459
462
Get the constant value represented by this Expression.
461
464
@returns the value
463
intrusive_ptr<const Value> getValue() const;
466
Value getValue() const;
466
469
ExpressionConstant(BSONElement *pBsonElement);
467
ExpressionConstant(const intrusive_ptr<const Value> &pValue);
470
ExpressionConstant(const Value& pValue);
469
intrusive_ptr<const Value> pValue;
476
479
// virtuals from ExpressionNary
477
480
virtual ~ExpressionDayOfMonth();
478
virtual intrusive_ptr<const Value> evaluate(
479
const intrusive_ptr<Document> &pDocument) const;
481
virtual Value evaluate(const Document& pDocument) const;
480
482
virtual const char *getOpName() const;
481
483
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
493
495
// virtuals from ExpressionNary
494
496
virtual ~ExpressionDayOfWeek();
495
virtual intrusive_ptr<const Value> evaluate(
496
const intrusive_ptr<Document> &pDocument) const;
497
virtual Value evaluate(const Document& pDocument) const;
497
498
virtual const char *getOpName() const;
498
499
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
510
511
// virtuals from ExpressionNary
511
512
virtual ~ExpressionDayOfYear();
512
virtual intrusive_ptr<const Value> evaluate(
513
const intrusive_ptr<Document> &pDocument) const;
513
virtual Value evaluate(const Document& pDocument) const;
514
514
virtual const char *getOpName() const;
515
515
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
527
527
// virtuals from ExpressionNary
528
528
virtual ~ExpressionDivide();
529
virtual intrusive_ptr<const Value> evaluate(
530
const intrusive_ptr<Document> &pDocument) const;
529
virtual Value evaluate(const Document& pDocument) const;
531
530
virtual const char *getOpName() const;
532
531
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
545
544
virtual ~ExpressionFieldPath();
546
545
virtual intrusive_ptr<Expression> optimize();
547
546
virtual void addDependencies(set<string>& deps, vector<string>* path=NULL) const;
548
virtual intrusive_ptr<const Value> evaluate(
549
const intrusive_ptr<Document> &pDocument) const;
550
virtual void addToBsonObj(
551
BSONObjBuilder *pBuilder, string fieldName,
552
bool requireExpression) const;
547
virtual Value evaluate(const Document& pDocument) const;
548
virtual void addToBsonObj(BSONObjBuilder *pBuilder,
549
StringData fieldName,
550
bool requireExpression) const;
553
551
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
596
594
a be an array of objects in order to navigate more deeply.
598
596
@param index current path field index to extract
599
@param pathLength maximum number of fields on field path
600
@param pDocument current document traversed to (not the top-level one)
597
@param input current document traversed to (not the top-level one)
601
598
@returns the field found; could be an array
603
intrusive_ptr<const Value> evaluatePath(
604
size_t index, const size_t pathLength,
605
intrusive_ptr<Document> pDocument) const;
600
Value evaluatePath(size_t index, const Document& input) const;
602
// Helper for evaluatePath to handle Array case
603
Value evaluatePathArray(size_t index, const Value& input) const;
607
605
FieldPath fieldPath;
615
613
virtual ~ExpressionFieldRange();
616
614
virtual intrusive_ptr<Expression> optimize();
617
615
virtual void addDependencies(set<string>& deps, vector<string>* path=NULL) const;
618
virtual intrusive_ptr<const Value> evaluate(
619
const intrusive_ptr<Document> &pDocument) const;
620
virtual void addToBsonObj(
621
BSONObjBuilder *pBuilder, string fieldName,
622
bool requireExpression) const;
616
virtual Value evaluate(const Document& pDocument) const;
617
virtual void addToBsonObj(BSONObjBuilder *pBuilder,
618
StringData fieldName,
619
bool requireExpression) const;
623
620
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
624
621
virtual void toMatcherBson(BSONObjBuilder *pBuilder) const;
646
643
static intrusive_ptr<ExpressionFieldRange> create(
647
644
const intrusive_ptr<ExpressionFieldPath> &pFieldPath,
648
CmpOp cmpOp, const intrusive_ptr<const Value> &pValue);
645
CmpOp cmpOp, const Value& pValue);
651
648
Add an intersecting range.
660
657
@param cmpOp the comparison operator
661
658
@param pValue the value to compare against
663
void intersect(CmpOp cmpOp, const intrusive_ptr<const Value> &pValue);
660
void intersect(CmpOp cmpOp, const Value& pValue);
666
663
ExpressionFieldRange(const intrusive_ptr<ExpressionFieldPath> &pFieldPath,
668
const intrusive_ptr<const Value> &pValue);
665
const Value& pValue);
670
667
intrusive_ptr<ExpressionFieldPath> pFieldPath;
674
Range(CmpOp cmpOp, const intrusive_ptr<const Value> &pValue);
671
Range(CmpOp cmpOp, const Value& pValue);
675
672
Range(const Range &rRange);
677
674
Range *intersect(const Range *pRange) const;
678
bool contains(const intrusive_ptr<const Value> &pValue) const;
675
bool contains(const Value& pValue) const;
680
Range(const intrusive_ptr<const Value> &pBottom, bool bottomOpen,
681
const intrusive_ptr<const Value> &pTop, bool topOpen);
677
Range(const Value& pBottom, bool bottomOpen,
678
const Value& pTop, bool topOpen);
685
intrusive_ptr<const Value> pBottom;
686
intrusive_ptr<const Value> pTop;
689
686
scoped_ptr<Range> pRange;
707
704
// virtuals from ExpressionNary
708
705
virtual ~ExpressionHour();
709
virtual intrusive_ptr<const Value> evaluate(
710
const intrusive_ptr<Document> &pDocument) const;
706
virtual Value evaluate(const Document& pDocument) const;
711
707
virtual const char *getOpName() const;
712
708
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
724
720
// virtuals from ExpressionNary
725
721
virtual ~ExpressionIfNull();
726
virtual intrusive_ptr<const Value> evaluate(
727
const intrusive_ptr<Document> &pDocument) const;
722
virtual Value evaluate(const Document& pDocument) const;
728
723
virtual const char *getOpName() const;
729
724
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
733
class ExpressionMillisecond :
734
public ExpressionNary {
736
// virtuals from ExpressionNary
737
virtual ~ExpressionMillisecond();
738
virtual Value evaluate(const Document& document) const;
739
virtual const char* getOpName() const;
740
virtual void addOperand(const intrusive_ptr<Expression>& pExpression);
742
static intrusive_ptr<ExpressionNary> create();
745
ExpressionMillisecond();
738
749
class ExpressionMinute :
739
750
public ExpressionNary {
741
752
// virtuals from ExpressionNary
742
753
virtual ~ExpressionMinute();
743
virtual intrusive_ptr<const Value> evaluate(
744
const intrusive_ptr<Document> &pDocument) const;
754
virtual Value evaluate(const Document& pDocument) const;
745
755
virtual const char *getOpName() const;
746
756
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
758
768
// virtuals from ExpressionNary
759
769
virtual ~ExpressionMod();
760
virtual intrusive_ptr<const Value> evaluate(
761
const intrusive_ptr<Document> &pDocument) const;
770
virtual Value evaluate(const Document& pDocument) const;
762
771
virtual const char *getOpName() const;
763
772
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
775
784
// virtuals from Expression
776
785
virtual ~ExpressionMultiply();
777
virtual intrusive_ptr<const Value> evaluate(
778
const intrusive_ptr<Document> &pDocument) const;
786
virtual Value evaluate(const Document& pDocument) const;
779
787
virtual const char *getOpName() const;
781
789
// virtuals from ExpressionNary
799
807
// virtuals from ExpressionNary
800
808
virtual ~ExpressionMonth();
801
virtual intrusive_ptr<const Value> evaluate(
802
const intrusive_ptr<Document> &pDocument) const;
809
virtual Value evaluate(const Document& pDocument) const;
803
810
virtual const char *getOpName() const;
804
811
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
816
823
// virtuals from ExpressionNary
817
824
virtual ~ExpressionNot();
818
virtual intrusive_ptr<const Value> evaluate(
819
const intrusive_ptr<Document> &pDocument) const;
825
virtual Value evaluate(const Document& pDocument) const;
820
826
virtual const char *getOpName() const;
821
827
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
835
841
virtual intrusive_ptr<Expression> optimize();
836
842
virtual bool isSimple();
837
843
virtual void addDependencies(set<string>& deps, vector<string>* path=NULL) const;
838
virtual intrusive_ptr<const Value> evaluate(
839
const intrusive_ptr<Document> &pDocument) const;
840
virtual void addToBsonObj(
841
BSONObjBuilder *pBuilder, string fieldName,
842
bool requireExpression) const;
844
/** Only evaluates non inclusion expressions. For inclusions, use addToDocument(). */
845
virtual Value evaluate(const Document& pDocument) const;
846
virtual void addToBsonObj(BSONObjBuilder *pBuilder,
847
StringData fieldName,
848
bool requireExpression) const;
843
849
virtual void addToBsonArray(BSONArrayBuilder *pBuilder) const;
849
855
@param pDocument the input Document
850
856
@returns the result document
852
intrusive_ptr<Document> evaluateDocument(
853
const intrusive_ptr<Document> &pDocument) const;
858
Document evaluateDocument(const Document& pDocument) const;
856
861
evaluate(), but add the evaluated fields to a given document
860
865
@param pDocument the input Document for this level
861
866
@param rootDoc the root of the whole input document
863
void addToDocument(const intrusive_ptr<Document>& pResult,
864
const intrusive_ptr<Document>& pDocument,
865
const intrusive_ptr<Document>& rootDoc
868
void addToDocument(MutableDocument& pResult,
869
const Document& pDocument,
870
const Document& rootDoc
868
873
// estimated number of fields that will be output
945
950
vector<string> _order;
950
Utility object for collecting emitPaths() results in a BSON
953
class BuilderPathSink :
956
// virtuals from PathSink
957
virtual void path(const string &path, bool include);
960
Create a PathSink that writes paths to a BSONObjBuilder,
961
to create an object in the form of { path:is_included,...}
963
This object uses a builder pointer that won't guarantee the
964
lifetime of the builder, so make sure it outlasts the use of
965
this for an emitPaths() call.
967
@param pBuilder to the builder to write paths to
969
BuilderPathSink(BSONObjBuilder *pBuilder);
972
BSONObjBuilder *pBuilder;
975
/* utility class used by emitPaths() */
979
PathPusher(vector<string> *pvPath, const string &s);
983
vector<string> *pvPath;
991
959
// virtuals from Expression
992
960
virtual ~ExpressionOr();
993
961
virtual intrusive_ptr<Expression> optimize();
994
virtual intrusive_ptr<const Value> evaluate(
995
const intrusive_ptr<Document> &pDocument) const;
962
virtual Value evaluate(const Document& pDocument) const;
996
963
virtual const char *getOpName() const;
997
964
virtual void toMatcherBson(BSONObjBuilder *pBuilder) const;
1021
988
// virtuals from ExpressionNary
1022
989
virtual ~ExpressionSecond();
1023
virtual intrusive_ptr<const Value> evaluate(
1024
const intrusive_ptr<Document> &pDocument) const;
990
virtual Value evaluate(const Document& pDocument) const;
1025
991
virtual const char *getOpName() const;
1026
992
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
1038
1004
// virtuals from ExpressionNary
1039
1005
virtual ~ExpressionStrcasecmp();
1040
virtual intrusive_ptr<const Value> evaluate(
1041
const intrusive_ptr<Document> &pDocument) const;
1006
virtual Value evaluate(const Document& pDocument) const;
1042
1007
virtual const char *getOpName() const;
1043
1008
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
1055
1020
// virtuals from ExpressionNary
1056
1021
virtual ~ExpressionSubstr();
1057
virtual intrusive_ptr<const Value> evaluate(
1058
const intrusive_ptr<Document> &pDocument) const;
1022
virtual Value evaluate(const Document& pDocument) const;
1059
1023
virtual const char *getOpName() const;
1060
1024
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
1072
1036
// virtuals from ExpressionNary
1073
1037
virtual ~ExpressionSubtract();
1074
virtual intrusive_ptr<const Value> evaluate(
1075
const intrusive_ptr<Document> &pDocument) const;
1038
virtual Value evaluate(const Document& pDocument) const;
1076
1039
virtual const char *getOpName() const;
1077
1040
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
1089
1052
// virtuals from ExpressionNary
1090
1053
virtual ~ExpressionToLower();
1091
virtual intrusive_ptr<const Value> evaluate(
1092
const intrusive_ptr<Document> &pDocument) const;
1054
virtual Value evaluate(const Document& pDocument) const;
1093
1055
virtual const char *getOpName() const;
1094
1056
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
1106
1068
// virtuals from ExpressionNary
1107
1069
virtual ~ExpressionToUpper();
1108
virtual intrusive_ptr<const Value> evaluate(
1109
const intrusive_ptr<Document> &pDocument) const;
1070
virtual Value evaluate(const Document& pDocument) const;
1110
1071
virtual const char *getOpName() const;
1111
1072
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
1123
1084
// virtuals from ExpressionNary
1124
1085
virtual ~ExpressionWeek();
1125
virtual intrusive_ptr<const Value> evaluate(
1126
const intrusive_ptr<Document> &pDocument) const;
1086
virtual Value evaluate(const Document& pDocument) const;
1127
1087
virtual const char *getOpName() const;
1128
1088
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
1140
1100
// virtuals from ExpressionNary
1141
1101
virtual ~ExpressionYear();
1142
virtual intrusive_ptr<const Value> evaluate(
1143
const intrusive_ptr<Document> &pDocument) const;
1102
virtual Value evaluate(const Document& pDocument) const;
1144
1103
virtual const char *getOpName() const;
1145
1104
virtual void addOperand(const intrusive_ptr<Expression> &pExpression);
1180
1139
inline size_t ExpressionObject::getFieldCount() const {
1181
1140
return _expressions.size();
1184
inline ExpressionObject::BuilderPathSink::BuilderPathSink(
1185
BSONObjBuilder *pB):
1189
inline ExpressionObject::PathPusher::PathPusher(
1190
vector<string> *pTheVPath, const string &s):
1192
pvPath->push_back(s);
1195
inline ExpressionObject::PathPusher::~PathPusher() {