diff options
author | randomdan <randomdan@localhost> | 2012-01-31 00:30:49 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2012-01-31 00:30:49 +0000 |
commit | 69a7f64dbfe9335b40193d20c452a416d3c00064 (patch) | |
tree | b1fc1e6f522cf82f81eadd09d2a6b3068787440d /project2/common/aggregates | |
parent | Add some configurability to the Html2Text transform (diff) | |
download | project2-69a7f64dbfe9335b40193d20c452a416d3c00064.tar.bz2 project2-69a7f64dbfe9335b40193d20c452a416d3c00064.tar.xz project2-69a7f64dbfe9335b40193d20c452a416d3c00064.zip |
Add support for aggregates in row views
Add a few aggregates implementations (min, max, distinct)
Use distinct to get the GB homepage in a single DB trip
Fix lessthan operation on variable types to be the right way round as it now matters
Diffstat (limited to 'project2/common/aggregates')
-rw-r--r-- | project2/common/aggregates/distinct.cpp | 28 | ||||
-rw-r--r-- | project2/common/aggregates/max.cpp | 27 | ||||
-rw-r--r-- | project2/common/aggregates/min.cpp | 32 |
3 files changed, 87 insertions, 0 deletions
diff --git a/project2/common/aggregates/distinct.cpp b/project2/common/aggregates/distinct.cpp new file mode 100644 index 0000000..85e69c2 --- /dev/null +++ b/project2/common/aggregates/distinct.cpp @@ -0,0 +1,28 @@ +#include "../aggregate.h" +#include <boost/foreach.hpp> + +class Distinct : public SetAggregate { + public: + Distinct(ScriptNodePtr s) : + SetAggregate(s) + { + } + void reset() const + { + result.clear(); + } + void pushValue(const VariableType & v) const + { + result.insert(v); + } + void onResultValues(const SetAggregate::UseAgg & u) const + { + BOOST_FOREACH(const VariableType & v, result) { + u(v); + } + } + private: + mutable std::set<VariableType> result; +}; + +DECLARE_LOADER("distinct", Distinct); diff --git a/project2/common/aggregates/max.cpp b/project2/common/aggregates/max.cpp new file mode 100644 index 0000000..a6e528a --- /dev/null +++ b/project2/common/aggregates/max.cpp @@ -0,0 +1,27 @@ +#include "../aggregate.h" + +class Max : public ValueAggregate { + public: + Max(ScriptNodePtr s) : ValueAggregate(s) { } + + void reset() const + { + result = VariableType(); + } + void pushValue(const VariableType & v) const + { + if (result < v) { + result = v; + } + } + VariableType resultValue() const + { + return result; + } + private: + mutable VariableType result; +}; + +DECLARE_LOADER("max", Max); + + diff --git a/project2/common/aggregates/min.cpp b/project2/common/aggregates/min.cpp new file mode 100644 index 0000000..14c63ae --- /dev/null +++ b/project2/common/aggregates/min.cpp @@ -0,0 +1,32 @@ +#include "../aggregate.h" + +class Min : public ValueAggregate { + public: + Min(ScriptNodePtr s) : + ValueAggregate(s), + first(true) + { + } + void reset() const + { + result = VariableType(); + first = true; + } + void pushValue(const VariableType & v) const + { + if (first || v < result) { + result = v; + } + first = false; + } + VariableType resultValue() const + { + return result; + } + private: + mutable VariableType result; + mutable bool first; +}; + +DECLARE_LOADER("min", Min); + |