Akumuli
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
queryprocessor.h
1 
17 #pragma once
18 #include <chrono>
19 #include <memory>
20 
21 #include "akumuli.h"
22 #include "queryprocessor_framework.h"
23 #include "seriesparser.h"
24 #include "stringpool.h"
25 
26 #include <boost/property_tree/ptree_fwd.hpp>
27 
28 namespace Akumuli {
29 namespace QP {
30 
31 
32 struct Builder {
33 
39  static std::shared_ptr<QP::IQueryProcessor>
40  build_query_processor(const char* query, std::shared_ptr<QP::Node> terminal_node,
41  const SeriesMatcher& matcher, aku_logger_cb_t logger);
42 };
43 
44 
46 struct GroupByTime {
47  aku_Timestamp step_;
48  bool first_hit_;
49  aku_Timestamp lowerbound_;
50  aku_Timestamp upperbound_;
51 
52  GroupByTime();
53 
54  GroupByTime(aku_Timestamp step);
55 
56  GroupByTime(const GroupByTime& other);
57 
58  GroupByTime& operator=(const GroupByTime& other);
59 
60  bool put(aku_Sample const& sample, Node& next);
61 
62  bool empty() const;
63 };
64 
65 
67 struct GroupByTag {
68  std::string regex_;
70  std::unordered_map<aku_ParamId, aku_ParamId> ids_;
76  size_t prev_size_;
78  std::vector<std::string> tags_;
82  StringTools::SetT snames_;
83 
85  GroupByTag(StringPool const* spool, std::string metric, std::vector<std::string> const& tags);
86 
87  void refresh_();
88 
89  bool apply(aku_Sample* sample);
90 };
91 
92 
97 
98  typedef StringTools::StringT StringT;
99  typedef StringTools::TableT TableT;
100 
104  const std::string metric_;
110  std::shared_ptr<IQueryFilter> filter_;
112  std::shared_ptr<Node> root_node_;
114  std::shared_ptr<Node> last_node_;
116  std::unique_ptr<GroupByTag> groupby_tag_;
117 
125  ScanQueryProcessor(std::vector<std::shared_ptr<Node>> nodes, std::string metric,
126  aku_Timestamp begin, aku_Timestamp end, QueryRange::QueryRangeType type,
127  std::shared_ptr<IQueryFilter> filter, GroupByTime groupby,
128  std::unique_ptr<GroupByTag> groupbytag);
129 
130  QueryRange range() const;
131 
132  IQueryFilter& filter();
133 
135 
136  bool start();
137 
139  bool put(const aku_Sample& sample);
140 
142  void stop();
143 
145  void set_error(aku_Status error);
146 };
147 
148 
150 
151  std::shared_ptr<IQueryFilter> filter_;
152  std::shared_ptr<Node> root_;
153 
154  MetadataQueryProcessor(std::shared_ptr<IQueryFilter> flt, std::shared_ptr<Node> node);
155 
156  QueryRange range() const;
157  IQueryFilter& filter();
159  bool start();
160  bool put(const aku_Sample& sample);
161  void stop();
162  void set_error(aku_Status error);
163 };
164 }
165 } // namespaces
const std::string metric_
Name of the metrics of interest.
Definition: queryprocessor.h:104
StringTools::SetT snames_
List of string already added string pool.
Definition: queryprocessor.h:82
bool start()
Definition: queryprocessor.cpp:359
StringPoolOffset offset_
Previous string pool offset.
Definition: queryprocessor.h:74
size_t prev_size_
Previous string pool size.
Definition: queryprocessor.h:76
bool put(const aku_Sample &sample)
Get new value.
Definition: queryprocessor.cpp:374
QueryRange range() const
Lowerbound.
Definition: queryprocessor.cpp:337
void set_error(aku_Status error)
Set execution error.
Definition: queryprocessor.cpp:333
SeriesMatcher * matcher()
Definition: queryprocessor.cpp:303
std::pair< const char *, int > StringT
Pooled string.
Definition: stringpool.h:68
GroupByTime groupby_
Group-by-time statement.
Definition: queryprocessor.h:108
SeriesMatcher local_matcher_
Local string pool. All transient series names lives here.
Definition: queryprocessor.h:80
IQueryFilter & filter()
Return query filter.
Definition: queryprocessor.cpp:299
std::shared_ptr< IQueryFilter > filter_
Filter.
Definition: queryprocessor.h:110
QueryRange range() const
Lowerbound.
Definition: queryprocessor.cpp:351
Definition: queryprocessor.h:46
Definition: queryprocessor_framework.h:87
Definition: queryprocessor.h:32
Definition: queryprocessor.h:96
void stop()
Will be called when processing completed without errors.
Definition: queryprocessor.cpp:379
QueryRange range_
Query range clause data (upperbound, lowerbound, direction, query type)
Definition: queryprocessor.h:102
std::unique_ptr< GroupByTag > groupby_tag_
Group-by-tag.
Definition: queryprocessor.h:116
void stop()
Should be called when processing completed.
Definition: queryprocessor.cpp:329
std::unordered_map< aku_ParamId, aku_ParamId > ids_
Mapping from global parameter ids to local parameter ids.
Definition: queryprocessor.h:70
std::shared_ptr< Node > last_node_
Final of the processing topology.
Definition: queryprocessor.h:114
StringPool const * spool_
Shared string pool.
Definition: queryprocessor.h:72
Definition: queryprocessor.h:67
ScanQueryProcessor(std::vector< std::shared_ptr< Node >> nodes, std::string metric, aku_Timestamp begin, aku_Timestamp end, QueryRange::QueryRangeType type, std::shared_ptr< IQueryFilter > filter, GroupByTime groupby, std::unique_ptr< GroupByTag > groupbytag)
Definition: queryprocessor.cpp:248
std::shared_ptr< Node > root_node_
Root of the processing topology.
Definition: queryprocessor.h:112
static std::shared_ptr< QP::IQueryProcessor > build_query_processor(const char *query, std::shared_ptr< QP::Node > terminal_node, const SeriesMatcher &matcher, aku_logger_cb_t logger)
Definition: queryprocessor.cpp:531
Definition: queryprocessor_framework.h:62
Definition: queryprocessor.h:149
Definition: queryprocessor_framework.h:28
bool start()
Definition: queryprocessor.cpp:310
void set_error(aku_Status error)
Will be called on error.
Definition: queryprocessor.cpp:383
TableT namesofinterest_
Name to id mapping.
Definition: queryprocessor.h:106
Query processor interface.
Definition: queryprocessor_framework.h:118
std::vector< std::string > tags_
List of tags of interest.
Definition: queryprocessor.h:78
bool put(const aku_Sample &sample)
Process value.
Definition: queryprocessor.cpp:314
Definition: seriesparser.h:38
GroupByTag(StringPool const *spool, std::string metric, std::vector< std::string > const &tags)
Main c-tor.
Definition: queryprocessor.cpp:177
SeriesMatcher * matcher()
Definition: queryprocessor.cpp:347
Definition: stringpool.h:39
Offset inside string-pool.
Definition: stringpool.h:32
IQueryFilter & filter()
Return query filter.
Definition: queryprocessor.cpp:355