LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-analytics/contrail-query-engine - stats_query.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 97 98 99.0 %
Date: 2026-08-03 02:19:58 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : /*
       6             :  * This file has utility functions for handling StatsOracle queries
       7             :  *
       8             :  */
       9             : 
      10             : #include "stats_query.h"
      11             : 
      12             : using std::string;
      13             : 
      14             : bool
      15         710 : StatsQuery::is_stat_table_query(const std::string & tname) {
      16         710 :     if (tname.compare(0, g_viz_constants.STAT_VT_PREFIX.length(),
      17             :             g_viz_constants.STAT_VT_PREFIX)) {
      18           0 :         return false;
      19             :     }
      20         710 :     return true;
      21             : }
      22             : 
      23         710 : StatsQuery::StatsQuery(const std::string & tname) {
      24             : 
      25         710 :     QE_ASSERT(is_stat_table_query(tname));
      26             :     size_t tpos,apos;
      27         710 :     tpos = tname.find('.');
      28         710 :     apos = tname.find('.', tpos+1);
      29         710 :     type_ = tname.substr(tpos+1, apos-tpos-1);
      30         710 :     attr_ = tname.substr(apos+1, std::string::npos);        
      31             : 
      32         710 :     std::map<std::string,column_t>& s = schema_;
      33             : 
      34         710 :     is_static_ = false;
      35       55928 :     for (uint idx=0;
      36       55928 :          idx<g_viz_constants._STAT_TABLES.size() + g_viz_constants._STAT_TEST_TABLES.size();
      37             :          idx++) {
      38       55197 :         const stat_table& st = idx < g_viz_constants._STAT_TABLES.size() ? 
      39       53097 :              g_viz_constants._STAT_TABLES[idx] :
      40       55213 :              g_viz_constants._STAT_TEST_TABLES[idx-g_viz_constants._STAT_TABLES.size()];
      41       55734 :         if ((st.stat_type != type_)||
      42         508 :             (st.stat_attr != attr_)) {
      43       54746 :             continue;
      44             :         }
      45         476 :         is_static_ = true;
      46        3538 :         for (uint j=0; j<st.attributes.size(); j++) {
      47        3065 :             column_t c;
      48        3064 :             std::string dtype(st.attributes[j].datatype);
      49        3061 :             if (dtype=="string") {
      50        1756 :                 c.datatype = QEOpServerProxy::STRING;
      51        1314 :             } else if (dtype=="double") {
      52         439 :                 c.datatype = QEOpServerProxy::DOUBLE;
      53             :             } else {
      54         877 :                 c.datatype = QEOpServerProxy::UINT64;
      55             :             }
      56        3072 :             c.index = st.attributes[j].index;
      57        3069 :             c.output = true;
      58             :             std::set<std::string> sf(
      59        3065 :                 st.attributes[j].suffixes.begin(),
      60        6133 :                 st.attributes[j].suffixes.end());
      61        3061 :             c.suffixes = sf;
      62             : 
      63        3058 :             s[st.attributes[j].name] = c;
      64        3062 :         }
      65             :     }
      66         709 :     if (s.find(g_viz_constants.STAT_OBJECTID_FIELD)==s.end()) {
      67         307 :         column_t c;
      68         307 :         c.datatype = QEOpServerProxy::STRING;
      69         307 :         c.index = true;
      70         307 :         c.output = true;
      71         307 :         s[g_viz_constants.STAT_OBJECTID_FIELD] = c;
      72         307 :     }
      73             :     {
      74         709 :         column_t c;
      75         709 :         c.datatype = QEOpServerProxy::STRING;
      76         709 :         c.index = true;
      77         709 :         c.output = false;
      78         709 :         s[g_viz_constants.STAT_SOURCE_FIELD] = c;
      79         708 :     }
      80             :     {
      81         708 :         column_t c;
      82         708 :         c.datatype = QEOpServerProxy::UUID;
      83         708 :         c.index = false;
      84         708 :         c.output = true;
      85         708 :         s[g_viz_constants.STAT_UUID_FIELD] = c;
      86         710 :     }
      87         710 : }
      88             : 
      89        4019 : QEOpServerProxy::AggOper StatsQuery::ParseAgg(
      90             :         const std::string& vname,
      91             :         std::string& sfield) {
      92             : 
      93        4019 :     if (0 == vname.compare(0,14,string("COUNT_DISTINCT"))) {
      94          18 :         sfield = vname.substr(15);
      95          18 :         int len = sfield.size();
      96          18 :         sfield.erase(len-1);
      97          18 :         return QEOpServerProxy::COUNT_DISTINCT;
      98             :     }
      99             : 
     100        4001 :     if (0 == vname.compare(0,5,string("COUNT"))) {
     101          54 :         sfield = vname.substr(6);
     102          54 :         int len = sfield.size();
     103          54 :         sfield.erase(len-1);
     104          54 :         return QEOpServerProxy::COUNT;
     105             :     }
     106             : 
     107        3947 :     if (0 == vname.compare(0,3,string("SUM"))) {
     108         300 :         sfield = vname.substr(4);
     109         300 :         int len = sfield.size();
     110         300 :         sfield.erase(len-1);
     111         300 :         return QEOpServerProxy::SUM;
     112             :     }
     113             : 
     114        3647 :     if (0 == vname.compare(0,5,string("CLASS"))) {
     115          17 :         sfield = vname.substr(6);
     116          17 :         int len = sfield.size();
     117          17 :         sfield.erase(len-1);
     118          17 :         return QEOpServerProxy::CLASS;
     119             :     }
     120             : 
     121        3629 :     if (0 == vname.compare(0,3,string("MAX"))) {
     122          36 :         sfield = vname.substr(4);
     123          36 :         int len = sfield.size();
     124          36 :         sfield.erase(len-1);
     125          36 :         return QEOpServerProxy::MAX;
     126             :     }
     127             : 
     128        3594 :     if (0 == vname.compare(0,3,string("MIN"))) {
     129          18 :         sfield = vname.substr(4);
     130          18 :         int len = sfield.size();
     131          18 :         sfield.erase(len-1);
     132          18 :         return QEOpServerProxy::MIN;
     133             :     }
     134             : 
     135        3576 :     if (0 == vname.compare(0,3,string("AVG"))) {
     136          54 :         sfield = vname.substr(4);
     137          54 :         int len = sfield.size();
     138          54 :         sfield.erase(len-1);
     139          54 :         return QEOpServerProxy::AVG;
     140             :     }
     141             : 
     142        3522 :     if (0 == vname.compare(0,11,string("PERCENTILES"))) {
     143          36 :         sfield = vname.substr(12);
     144          36 :         int len = sfield.size();
     145          36 :         sfield.erase(len-1);
     146          36 :         return QEOpServerProxy::PERCENTILES;
     147             :     }
     148             : 
     149        3486 :     return QEOpServerProxy::INVALID;
     150             : }
     151             : 

Generated by: LCOV version 1.14