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-10-19 02:12:28 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         674 : StatsQuery::is_stat_table_query(const std::string & tname) {
      16         674 :     if (tname.compare(0, g_viz_constants.STAT_VT_PREFIX.length(),
      17             :             g_viz_constants.STAT_VT_PREFIX)) {
      18           0 :         return false;
      19             :     }
      20         674 :     return true;
      21             : }
      22             : 
      23         674 : StatsQuery::StatsQuery(const std::string & tname) {
      24             : 
      25         674 :     QE_ASSERT(is_stat_table_query(tname));
      26             :     size_t tpos,apos;
      27         673 :     tpos = tname.find('.');
      28         674 :     apos = tname.find('.', tpos+1);
      29         674 :     type_ = tname.substr(tpos+1, apos-tpos-1);
      30         674 :     attr_ = tname.substr(apos+1, std::string::npos);        
      31             : 
      32         674 :     std::map<std::string,column_t>& s = schema_;
      33             : 
      34         674 :     is_static_ = false;
      35       52722 :     for (uint idx=0;
      36       52722 :          idx<g_viz_constants._STAT_TABLES.size() + g_viz_constants._STAT_TEST_TABLES.size();
      37             :          idx++) {
      38       52047 :         const stat_table& st = idx < g_viz_constants._STAT_TABLES.size() ? 
      39       50049 :              g_viz_constants._STAT_TABLES[idx] :
      40       52045 :              g_viz_constants._STAT_TEST_TABLES[idx-g_viz_constants._STAT_TABLES.size()];
      41       52565 :         if ((st.stat_type != type_)||
      42         484 :             (st.stat_attr != attr_)) {
      43       51594 :             continue;
      44             :         }
      45         458 :         is_static_ = true;
      46        3367 :         for (uint j=0; j<st.attributes.size(); j++) {
      47        2911 :             column_t c;
      48        2908 :             std::string dtype(st.attributes[j].datatype);
      49        2903 :             if (dtype=="string") {
      50        1682 :                 c.datatype = QEOpServerProxy::STRING;
      51        1263 :             } else if (dtype=="double") {
      52         421 :                 c.datatype = QEOpServerProxy::DOUBLE;
      53             :             } else {
      54         841 :                 c.datatype = QEOpServerProxy::UINT64;
      55             :             }
      56        2944 :             c.index = st.attributes[j].index;
      57        2942 :             c.output = true;
      58             :             std::set<std::string> sf(
      59        2932 :                 st.attributes[j].suffixes.begin(),
      60        5868 :                 st.attributes[j].suffixes.end());
      61        2916 :             c.suffixes = sf;
      62             : 
      63        2914 :             s[st.attributes[j].name] = c;
      64        2908 :         }
      65             :     }
      66         674 :     if (s.find(g_viz_constants.STAT_OBJECTID_FIELD)==s.end()) {
      67         289 :         column_t c;
      68         289 :         c.datatype = QEOpServerProxy::STRING;
      69         289 :         c.index = true;
      70         289 :         c.output = true;
      71         289 :         s[g_viz_constants.STAT_OBJECTID_FIELD] = c;
      72         289 :     }
      73             :     {
      74         674 :         column_t c;
      75         674 :         c.datatype = QEOpServerProxy::STRING;
      76         674 :         c.index = true;
      77         674 :         c.output = false;
      78         674 :         s[g_viz_constants.STAT_SOURCE_FIELD] = c;
      79         673 :     }
      80             :     {
      81         673 :         column_t c;
      82         673 :         c.datatype = QEOpServerProxy::UUID;
      83         673 :         c.index = false;
      84         673 :         c.output = true;
      85         673 :         s[g_viz_constants.STAT_UUID_FIELD] = c;
      86         673 :     }
      87         673 : }
      88             : 
      89        3890 : QEOpServerProxy::AggOper StatsQuery::ParseAgg(
      90             :         const std::string& vname,
      91             :         std::string& sfield) {
      92             : 
      93        3890 :     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        3875 :     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        3821 :     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        3521 :     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        3504 :     if (0 == vname.compare(0,3,string("MAX"))) {
     122          18 :         sfield = vname.substr(4);
     123          18 :         int len = sfield.size();
     124          18 :         sfield.erase(len-1);
     125          18 :         return QEOpServerProxy::MAX;
     126             :     }
     127             : 
     128        3486 :     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        3468 :     if (0 == vname.compare(0,3,string("AVG"))) {
     136          36 :         sfield = vname.substr(4);
     137          36 :         int len = sfield.size();
     138          36 :         sfield.erase(len-1);
     139          36 :         return QEOpServerProxy::AVG;
     140             :     }
     141             : 
     142        3432 :     if (0 == vname.compare(0,11,string("PERCENTILES"))) {
     143          18 :         sfield = vname.substr(12);
     144          18 :         int len = sfield.size();
     145          18 :         sfield.erase(len-1);
     146          18 :         return QEOpServerProxy::PERCENTILES;
     147             :     }
     148             : 
     149        3414 :     return QEOpServerProxy::INVALID;
     150             : }
     151             : 

Generated by: LCOV version 1.14