diff options
author | randomdan <randomdan@localhost> | 2012-02-09 12:46:05 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2012-02-09 12:46:05 +0000 |
commit | da74608e6877e494b4126e0df6dfac6d40f6fea7 (patch) | |
tree | 8b0052cc0829b7f1e03965be42cbc97424f46f49 | |
parent | Add support for aggregates in row views (diff) | |
download | project2-da74608e6877e494b4126e0df6dfac6d40f6fea7.tar.bz2 project2-da74608e6877e494b4126e0df6dfac6d40f6fea7.tar.xz project2-da74608e6877e494b4126e0df6dfac6d40f6fea7.zip |
Add some more aggregates
-rw-r--r-- | project2/common/aggregates/count.cpp | 28 | ||||
-rw-r--r-- | project2/common/aggregates/countDistinct.cpp | 26 |
2 files changed, 54 insertions, 0 deletions
diff --git a/project2/common/aggregates/count.cpp b/project2/common/aggregates/count.cpp new file mode 100644 index 0000000..9bdb47c --- /dev/null +++ b/project2/common/aggregates/count.cpp @@ -0,0 +1,28 @@ +#include "../aggregate.h" + +class Count : public ValueAggregate { + public: + Count(ScriptNodePtr s) : + ValueAggregate(s), + c(0) + { + } + void reset() const + { + c = 0; + } + void pushValue(const VariableType &) const + { + c += 1; + } + VariableType resultValue() const + { + return c; + } + private: + mutable int c; +}; + +DECLARE_LOADER("count", Count); + + diff --git a/project2/common/aggregates/countDistinct.cpp b/project2/common/aggregates/countDistinct.cpp new file mode 100644 index 0000000..4a2c540 --- /dev/null +++ b/project2/common/aggregates/countDistinct.cpp @@ -0,0 +1,26 @@ +#include "../aggregate.h" + +class CountDistinct : public ValueAggregate { + public: + CountDistinct(ScriptNodePtr s) : + ValueAggregate(s) + { + } + void reset() const + { + result.clear(); + } + void pushValue(const VariableType & v) const + { + result.insert(v); + } + VariableType resultValue() const + { + return result.size(); + } + private: + mutable std::set<VariableType> result; +}; + +DECLARE_LOADER("countdistinct", CountDistinct); + |