Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : /* 7 : * This file has the interface for handling StatsOracle select processing 8 : * 9 : */ 10 : 11 : #ifndef STATS_SELECT_H_ 12 : #define STATS_SELECT_H_ 13 : 14 : #include <vector> 15 : #include <string> 16 : #include <map> 17 : #include <set> 18 : #include <utility> 19 : #include <memory> 20 : #include <boost/variant.hpp> 21 : #include <boost/uuid/uuid.hpp> 22 : #include "QEOpServerProxy.h" 23 : #include "query.h" 24 : 25 : class AnalyticsQuery; 26 : 27 : class StatsSelect { 28 : public: 29 : typedef QEOpServerProxy::SubVal StatVal; 30 : typedef QEOpServerProxy::VarType StatType; 31 : typedef QEOpServerProxy::AggOper StatOper; 32 : typedef QEOpServerProxy::OutRowMultimapT MapBufT; 33 : typedef std::map<std::pair<QEOpServerProxy::AggOper,std::string>, size_t> AggSortT; 34 : 35 : typedef std::map<std::string, StatVal> StatMap; 36 : struct StatEntry { 37 : std::string name; 38 : StatVal value; 39 : }; 40 : 41 : StatsSelect(AnalyticsQuery * main_query, const std::vector<std::string> & select_fields); 42 : 43 : // This should be called after the post processing is over 44 : void SetSortOrder(const std::vector<sort_field_t>& sort_fields); 45 : 46 : // The client call this function once with every row from the where result. 47 : // cols that are not in the SELECT will be silently dropped. 48 : bool LoadRow(boost::uuids::uuid u, uint64_t timestamp, 49 : const std::vector<StatEntry>& row, MapBufT& output); 50 : 51 1592 : bool Status() { return status_; } 52 : 53 70 : bool IsMergeNeeded() { return !isT_; } 54 : 55 : static void Merge(const std::string& count_distinct_field_, const MapBufT& input, MapBufT& output); 56 : void MergeFinal(const std::vector<boost::shared_ptr<MapBufT> >& inputs, 57 : MapBufT& output); 58 : 59 : static bool Jsonify(const std::string &table, 60 : const std::map<std::string, StatVal>&, 61 : const QEOpServerProxy::AggRowT&, std::string& jstr); 62 : 63 : private: 64 : static void DeleteTDigest(TDigest *); 65 : static void DeleteCentroid(Centroid *); 66 : static void MergeAggRow(QEOpServerProxy::AggRowT &arows, 67 : const QEOpServerProxy::AggRowT &narows); 68 : static void MergeFullRow( 69 : const std::vector<StatVal>& ukey, 70 : const StatMap& uniks, 71 : const QEOpServerProxy::AggRowT& narows, 72 : MapBufT& output); 73 : 74 : bool isStatic_; 75 : bool status_; 76 : 77 : AnalyticsQuery * const main_query; 78 : const std::vector<std::string> select_fields_; 79 : 80 : // If T= is in the SELECT, this gives the timeperiod 81 : uint64_t ts_period_; 82 : bool isT_; 83 : 84 : // Is CLASS(T) or CLASS(T=) in the SELECT Clause 85 : bool isTC_; 86 : bool isTBC_; 87 : 88 : // This is the column name corresponding to the COUNT select field. 89 : // It will be empty if the SELECT did not have COUNT. 90 : std::string count_field_; 91 : std::string count_distinct_field_; 92 : 93 : // This is the set of columns names to be used for sorting 94 : // The value is a sequence number - this is the position to use for this column 95 : // in the sort vector 96 : std::map<std::string, size_t> sort_cols_; 97 : AggSortT agg_sort_cols_; 98 : 99 : // This is the set of columns that define uniqueness of rows 100 : // They will correspond to the unique-map used to generate the row hash 101 : std::set<std::string> unik_cols_; 102 : 103 : // This is the set of columns that require aggregation. 104 : std::set<std::string> sum_cols_; 105 : std::set<std::string> class_cols_; 106 : 107 : std::set<std::string> max_field_; 108 : std::set<std::string> min_field_; 109 : std::set<std::string> avg_field_; 110 : 111 : std::set<std::string> percentile_cols_; 112 : 113 : }; 114 : #endif