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-11-09 02:10:49 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             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : /*
       7             :  * This file has utility functions for handling StatsOracle queries
       8             :  *
       9             :  */
      10             : 
      11             : #include "stats_query.h"
      12             : 
      13             : using std::string;
      14             : 
      15             : bool
      16         692 : StatsQuery::is_stat_table_query(const std::string & tname) {
      17         692 :     if (tname.compare(0, g_viz_constants.STAT_VT_PREFIX.length(),
      18             :             g_viz_constants.STAT_VT_PREFIX)) {
      19           0 :         return false;
      20             :     }
      21         692 :     return true;
      22             : }
      23             : 
      24         692 : StatsQuery::StatsQuery(const std::string & tname) {
      25             : 
      26         692 :     QE_ASSERT(is_stat_table_query(tname));
      27             :     size_t tpos,apos;
      28         692 :     tpos = tname.find('.');
      29         692 :     apos = tname.find('.', tpos+1);
      30         692 :     type_ = tname.substr(tpos+1, apos-tpos-1);
      31         691 :     attr_ = tname.substr(apos+1, std::string::npos);        
      32             : 
      33         692 :     std::map<std::string,column_t>& s = schema_;
      34             : 
      35         692 :     is_static_ = false;
      36       53616 :     for (uint idx=0;
      37       53616 :          idx<g_viz_constants._STAT_TABLES.size() + g_viz_constants._STAT_TEST_TABLES.size();
      38             :          idx++) {
      39       52920 :         const stat_table& st = idx < g_viz_constants._STAT_TABLES.size() ? 
      40       50893 :              g_viz_constants._STAT_TABLES[idx] :
      41       52916 :              g_viz_constants._STAT_TEST_TABLES[idx-g_viz_constants._STAT_TABLES.size()];
      42       53452 :         if ((st.stat_type != type_)||
      43         475 :             (st.stat_attr != attr_)) {
      44       52470 :             continue;
      45             :         }
      46         457 :         is_static_ = true;
      47        3363 :         for (uint j=0; j<st.attributes.size(); j++) {
      48        2907 :             column_t c;
      49        2903 :             std::string dtype(st.attributes[j].datatype);
      50        2896 :             if (dtype=="string") {
      51        1684 :                 c.datatype = QEOpServerProxy::STRING;
      52        1263 :             } else if (dtype=="double") {
      53         421 :                 c.datatype = QEOpServerProxy::DOUBLE;
      54             :             } else {
      55         842 :                 c.datatype = QEOpServerProxy::UINT64;
      56             :             }
      57        2947 :             c.index = st.attributes[j].index;
      58        2942 :             c.output = true;
      59             :             std::set<std::string> sf(
      60        2933 :                 st.attributes[j].suffixes.begin(),
      61        5868 :                 st.attributes[j].suffixes.end());
      62        2913 :             c.suffixes = sf;
      63             : 
      64        2910 :             s[st.attributes[j].name] = c;
      65        2907 :         }
      66             :     }
      67         689 :     if (s.find(g_viz_constants.STAT_OBJECTID_FIELD)==s.end()) {
      68         305 :         column_t c;
      69         305 :         c.datatype = QEOpServerProxy::STRING;
      70         305 :         c.index = true;
      71         305 :         c.output = true;
      72         305 :         s[g_viz_constants.STAT_OBJECTID_FIELD] = c;
      73         303 :     }
      74             :     {
      75         687 :         column_t c;
      76         685 :         c.datatype = QEOpServerProxy::STRING;
      77         685 :         c.index = true;
      78         685 :         c.output = false;
      79         685 :         s[g_viz_constants.STAT_SOURCE_FIELD] = c;
      80         685 :     }
      81             :     {
      82         685 :         column_t c;
      83         685 :         c.datatype = QEOpServerProxy::UUID;
      84         685 :         c.index = false;
      85         685 :         c.output = true;
      86         685 :         s[g_viz_constants.STAT_UUID_FIELD] = c;
      87         689 :     }
      88         688 : }
      89             : 
      90        3945 : QEOpServerProxy::AggOper StatsQuery::ParseAgg(
      91             :         const std::string& vname,
      92             :         std::string& sfield) {
      93             : 
      94        3945 :     if (0 == vname.compare(0,14,string("COUNT_DISTINCT"))) {
      95          18 :         sfield = vname.substr(15);
      96          18 :         int len = sfield.size();
      97          18 :         sfield.erase(len-1);
      98          18 :         return QEOpServerProxy::COUNT_DISTINCT;
      99             :     }
     100             : 
     101        3929 :     if (0 == vname.compare(0,5,string("COUNT"))) {
     102          54 :         sfield = vname.substr(6);
     103          54 :         int len = sfield.size();
     104          54 :         sfield.erase(len-1);
     105          54 :         return QEOpServerProxy::COUNT;
     106             :     }
     107             : 
     108        3875 :     if (0 == vname.compare(0,3,string("SUM"))) {
     109         300 :         sfield = vname.substr(4);
     110         300 :         int len = sfield.size();
     111         300 :         sfield.erase(len-1);
     112         300 :         return QEOpServerProxy::SUM;
     113             :     }
     114             : 
     115        3575 :     if (0 == vname.compare(0,5,string("CLASS"))) {
     116          17 :         sfield = vname.substr(6);
     117          17 :         int len = sfield.size();
     118          17 :         sfield.erase(len-1);
     119          17 :         return QEOpServerProxy::CLASS;
     120             :     }
     121             : 
     122        3558 :     if (0 == vname.compare(0,3,string("MAX"))) {
     123          36 :         sfield = vname.substr(4);
     124          36 :         int len = sfield.size();
     125          36 :         sfield.erase(len-1);
     126          36 :         return QEOpServerProxy::MAX;
     127             :     }
     128             : 
     129        3521 :     if (0 == vname.compare(0,3,string("MIN"))) {
     130          18 :         sfield = vname.substr(4);
     131          18 :         int len = sfield.size();
     132          18 :         sfield.erase(len-1);
     133          18 :         return QEOpServerProxy::MIN;
     134             :     }
     135             : 
     136        3504 :     if (0 == vname.compare(0,3,string("AVG"))) {
     137          54 :         sfield = vname.substr(4);
     138          54 :         int len = sfield.size();
     139          54 :         sfield.erase(len-1);
     140          54 :         return QEOpServerProxy::AVG;
     141             :     }
     142             : 
     143        3450 :     if (0 == vname.compare(0,11,string("PERCENTILES"))) {
     144          36 :         sfield = vname.substr(12);
     145          36 :         int len = sfield.size();
     146          36 :         sfield.erase(len-1);
     147          36 :         return QEOpServerProxy::PERCENTILES;
     148             :     }
     149             : 
     150        3413 :     return QEOpServerProxy::INVALID;
     151             : }
     152             : 

Generated by: LCOV version 1.14