diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-06 17:52:52 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-06 17:52:52 +0200 |
commit | 87695f52d5ac627cdd710f37c275fccdf920af0b (patch) | |
tree | 733a7e66fafd3a0ae747b050427f2d7762bde793 /common/query.h | |
parent | f1e496f7c12ebc787ed47a4c048015f2098e65d9 (diff) | |
download | sink-87695f52d5ac627cdd710f37c275fccdf920af0b.tar.gz sink-87695f52d5ac627cdd710f37c275fccdf920af0b.zip |
count as a first aggregation function
Diffstat (limited to 'common/query.h')
-rw-r--r-- | common/query.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/common/query.h b/common/query.h index 00ae086..3ab5acf 100644 --- a/common/query.h +++ b/common/query.h | |||
@@ -255,15 +255,48 @@ public: | |||
255 | Comparator comparator; | 255 | Comparator comparator; |
256 | }; | 256 | }; |
257 | 257 | ||
258 | class Aggregator { | ||
259 | public: | ||
260 | enum Operation { | ||
261 | Count, | ||
262 | Collect | ||
263 | }; | ||
264 | |||
265 | Aggregator(const QByteArray &p, Operation o, const QByteArray &c = QByteArray()) | ||
266 | : resultProperty(p), | ||
267 | operation(o), | ||
268 | propertyToCollect(c) | ||
269 | { | ||
270 | } | ||
271 | |||
272 | QByteArray resultProperty; | ||
273 | Operation operation; | ||
274 | QByteArray propertyToCollect; | ||
275 | }; | ||
276 | |||
258 | Reduce(const QByteArray &p, const Selector &s) | 277 | Reduce(const QByteArray &p, const Selector &s) |
259 | : property(p), | 278 | : property(p), |
260 | selector(s) | 279 | selector(s) |
261 | { | 280 | { |
262 | } | 281 | } |
263 | 282 | ||
283 | Reduce &count(const QByteArray &propertyName = "count") | ||
284 | { | ||
285 | aggregators << Aggregator(propertyName, Aggregator::Count); | ||
286 | return *this; | ||
287 | } | ||
288 | |||
289 | template <typename T> | ||
290 | Reduce &collect(const QByteArray &propertyName) | ||
291 | { | ||
292 | aggregators << Aggregator(propertyName, Aggregator::Collect, T::name); | ||
293 | return *this; | ||
294 | } | ||
295 | |||
264 | //Reduce on property | 296 | //Reduce on property |
265 | QByteArray property; | 297 | QByteArray property; |
266 | Selector selector; | 298 | Selector selector; |
299 | QList<Aggregator> aggregators; | ||
267 | 300 | ||
268 | //TODO add aggregate functions like: | 301 | //TODO add aggregate functions like: |
269 | //.count() | 302 | //.count() |