summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/expression.h
diff options
context:
space:
mode:
authorDerick Rethans <github@derickrethans.nl>2017-06-19 15:26:07 +0100
committerDerick Rethans <github@derickrethans.nl>2017-06-29 19:31:23 +0200
commit5811a6ac496c6368e4fc4d9a5c8ed51a8b37833a (patch)
tree3f5b3e0e65d7e94888fb29fcfa470a9f5b701c02 /src/mongo/db/pipeline/expression.h
parent5dda752d6cc8ed1f75a564b03b7357592f488d93 (diff)
downloadmongo-5811a6ac496c6368e4fc4d9a5c8ed51a8b37833a.tar.gz
SERVER-28613: Add $dateToParts and $dateFromParts aggregation framework operators
Diffstat (limited to 'src/mongo/db/pipeline/expression.h')
-rw-r--r--src/mongo/db/pipeline/expression.h82
1 files changed, 80 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h
index 14a05d9e6b0..85451aeefcf 100644
--- a/src/mongo/db/pipeline/expression.h
+++ b/src/mongo/db/pipeline/expression.h
@@ -42,6 +42,7 @@
#include "mongo/db/pipeline/field_path.h"
#include "mongo/db/pipeline/value.h"
#include "mongo/db/pipeline/variables.h"
+#include "mongo/db/query/datetime/date_time_support.h"
#include "mongo/stdx/functional.h"
#include "mongo/util/intrusive_counter.h"
#include "mongo/util/mongoutils/str.h"
@@ -661,6 +662,85 @@ private:
Value pValue;
};
+class ExpressionDateFromParts final : public Expression {
+public:
+ boost::intrusive_ptr<Expression> optimize() final;
+ Value serialize(bool explain) const final;
+ Value evaluate(const Document& root) const final;
+ void addDependencies(DepsTracker* deps) const final;
+
+ static boost::intrusive_ptr<Expression> parse(
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ BSONElement expr,
+ const VariablesParseState& vps);
+
+private:
+ ExpressionDateFromParts(const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ boost::intrusive_ptr<Expression> year,
+ boost::intrusive_ptr<Expression> month,
+ boost::intrusive_ptr<Expression> day,
+ boost::intrusive_ptr<Expression> hour,
+ boost::intrusive_ptr<Expression> minute,
+ boost::intrusive_ptr<Expression> second,
+ boost::intrusive_ptr<Expression> milliseconds,
+ boost::intrusive_ptr<Expression> isoYear,
+ boost::intrusive_ptr<Expression> isoWeekYear,
+ boost::intrusive_ptr<Expression> isoDayOfWeek,
+ boost::intrusive_ptr<Expression> timeZone);
+
+ /**
+ * Evaluates the value in field as number, and makes sure it fits in the minValue..maxValue
+ * range. If the field is missing or empty, the function returns the defaultValue.
+ */
+ bool evaluateNumberWithinRange(const Document& root,
+ boost::intrusive_ptr<Expression> field,
+ StringData fieldName,
+ int defaultValue,
+ int minValue,
+ int maxValue,
+ int* returnValue) const;
+
+ boost::intrusive_ptr<Expression> _year;
+ boost::intrusive_ptr<Expression> _month;
+ boost::intrusive_ptr<Expression> _day;
+ boost::intrusive_ptr<Expression> _hour;
+ boost::intrusive_ptr<Expression> _minute;
+ boost::intrusive_ptr<Expression> _second;
+ boost::intrusive_ptr<Expression> _milliseconds;
+ boost::intrusive_ptr<Expression> _isoYear;
+ boost::intrusive_ptr<Expression> _isoWeekYear;
+ boost::intrusive_ptr<Expression> _isoDayOfWeek;
+ boost::intrusive_ptr<Expression> _timeZone;
+};
+
+class ExpressionDateToParts final : public Expression {
+public:
+ boost::intrusive_ptr<Expression> optimize() final;
+ Value serialize(bool explain) const final;
+ Value evaluate(const Document& root) const final;
+ void addDependencies(DepsTracker* deps) const final;
+
+ static boost::intrusive_ptr<Expression> parse(
+ const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ BSONElement expr,
+ const VariablesParseState& vps);
+
+private:
+ /**
+ * The iso8601 argument controls whether to output ISO8601 elements or natural calendar.
+ */
+ ExpressionDateToParts(const boost::intrusive_ptr<ExpressionContext>& expCtx,
+ boost::intrusive_ptr<Expression> date,
+ boost::intrusive_ptr<Expression> timeZone,
+ boost::intrusive_ptr<Expression> iso8601);
+
+ boost::optional<int> evaluateIso8601Flag(const Document& root) const;
+
+ boost::intrusive_ptr<Expression> _date;
+ boost::intrusive_ptr<Expression> _timeZone;
+ boost::intrusive_ptr<Expression> _iso8601;
+};
+
class ExpressionDateToString final : public Expression {
public:
boost::intrusive_ptr<Expression> optimize() final;
@@ -678,8 +758,6 @@ private:
const std::string& format, // the format string
boost::intrusive_ptr<Expression> date); // the date to format
- static void insertPadded(StringBuilder& sb, int number, int spaces);
-
const std::string _format;
boost::intrusive_ptr<Expression> _date;
};