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