JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
GroupAggregator.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 21/05/2019.
3 //
4 
5 #ifndef JODA_GROUPAGGREGATOR_H
6 #define JODA_GROUPAGGREGATOR_H
7 
8 #include <unordered_map>
9 
10 #include "IAggregator.h"
11 
12 namespace joda::query {
13 class GroupAggregator : public IAggregator {
14  public:
15  GroupAggregator(const std::string &toPointer,
16  std::unique_ptr<IValueProvider> &&groupBy,
17  std::unique_ptr<IAggregator> &&agg, std::string groupAs = "");
18  ~GroupAggregator() override = default;
19 
20  void merge(IAggregator *other) override;
21 
22  std::unique_ptr<IAggregator> duplicate() const override;
23 
24  static constexpr auto getName_() { return "GROUP"; }
25 
26  const std::string getName() const override;
27  std::string toString() const override;
28 
29  RJValue terminate(RJMemoryPoolAlloc &alloc) override;
30 
31  void accumulate(const RapidJsonDocument &json,
32  RJMemoryPoolAlloc &alloc) override;
33  std::vector<std::string> getAttributes() const override;
34  void setGroupAs(const std::string &groupAs);
35 
36  protected:
37  const std::unique_ptr<IValueProvider> groupBy;
38  const std::unique_ptr<IAggregator> protoAgg;
39 
40  /*
41  * Groups
42  */
43  typedef std::unordered_map<std::string, std::unique_ptr<IAggregator>>
46  typedef std::unordered_map<double, std::unique_ptr<IAggregator>>
49  std::unique_ptr<IAggregator> trueAgg = nullptr;
50  std::unique_ptr<IAggregator> falseAgg = nullptr;
51 
52  const std::string getGroupName() const;
53  const std::string getValueName() const;
54  std::string groupAs;
55 };
56 } // namespace joda::query
57 
58 #endif // JODA_GROUPAGGREGATOR_H
rapidjson::MemoryPoolAllocator< RJBaseAlloc > RJMemoryPoolAlloc
Definition: RJFwd.h:26
rapidjson::GenericValue< RJChar, RJMemoryPoolAlloc > RJValue
Definition: RJFwd.h:29
Definition: RapidJsonDocument.h:22
Definition: GroupAggregator.h:13
const std::unique_ptr< IAggregator > protoAgg
Definition: GroupAggregator.h:38
StringAggregators stringGroups
Definition: GroupAggregator.h:45
std::string groupAs
Definition: GroupAggregator.h:54
const std::unique_ptr< IValueProvider > groupBy
Definition: GroupAggregator.h:37
const std::string getName() const override
Definition: GroupAggregator.cpp:62
~GroupAggregator() override=default
GroupAggregator(const std::string &toPointer, std::unique_ptr< IValueProvider > &&groupBy, std::unique_ptr< IAggregator > &&agg, std::string groupAs="")
Definition: GroupAggregator.cpp:9
static constexpr auto getName_()
Definition: GroupAggregator.h:24
void merge(IAggregator *other) override
Definition: GroupAggregator.cpp:17
std::unique_ptr< IAggregator > trueAgg
Definition: GroupAggregator.h:49
std::unique_ptr< IAggregator > duplicate() const override
Definition: GroupAggregator.cpp:57
std::string toString() const override
Definition: GroupAggregator.cpp:66
const std::string getGroupName() const
Definition: GroupAggregator.cpp:76
RJValue terminate(RJMemoryPoolAlloc &alloc) override
Definition: GroupAggregator.cpp:88
std::unique_ptr< IAggregator > falseAgg
Definition: GroupAggregator.h:50
void accumulate(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) override
Definition: GroupAggregator.cpp:123
void setGroupAs(const std::string &groupAs)
Definition: GroupAggregator.cpp:175
std::vector< std::string > getAttributes() const override
Definition: GroupAggregator.cpp:179
const std::string getValueName() const
Definition: GroupAggregator.cpp:84
std::unordered_map< double, std::unique_ptr< IAggregator > > NumAggregators
Definition: GroupAggregator.h:47
NumAggregators numGroups
Definition: GroupAggregator.h:48
std::unordered_map< std::string, std::unique_ptr< IAggregator > > StringAggregators
Definition: GroupAggregator.h:44
Definition: IAggregator.h:25
std::string toPointer
Definition: IAggregator.h:120
Definition: AttributeStatAggregator.h:12