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 : #include "query.h" 7 : #include "stats_query.h" 8 : 9 : using std::vector; 10 : using boost::shared_ptr; 11 : using std::string; 12 : 13 : // for sorting and set operations 14 25972 : bool query_result_unit_t::operator<(const query_result_unit_t& rhs) const 15 : { 16 25972 : if (timestamp == rhs.timestamp) 17 : { 18 558 : GenDb::DbDataValueVec::const_iterator it = info.begin(); 19 558 : GenDb::DbDataValueVec::const_iterator jt = rhs.info.begin(); 20 6765 : for (; it != info.end() && jt != rhs.info.end(); it++, jt++) { 21 6517 : if (*it < *jt) { 22 100 : return true; 23 6417 : } else if (*jt < *it) { 24 210 : return false; 25 : } 26 : } 27 248 : return false; 28 : } 29 : 30 25414 : return (timestamp < rhs.timestamp); 31 : } 32 : 33 : 34 : void 35 450 : SetOperationUnit::op_and(string qi, WhereResultT& res, 36 : vector<WhereResultT*> inp) { 37 450 : res = *inp[0]; 38 457 : for (size_t and_idx=1; and_idx<inp.size(); and_idx++) { 39 6 : WhereResultT tmp_query_result; 40 6 : QE_LOG_NOQID(INFO, qi << " INT between tables of sizes " << 41 : res.size() << " and " << inp[and_idx]->size()); 42 18 : set_intersection(res.begin(), res.end(), 43 6 : inp[and_idx]->begin(), 44 6 : inp[and_idx]->end(), 45 : std::back_inserter(tmp_query_result)); 46 6 : res = tmp_query_result; // keep the result in output var 47 6 : QE_LOG_NOQID(INFO, qi << " Resulting size of set " << 48 : res.size()); 49 : 50 6 : } 51 451 : } 52 : 53 : void 54 1615 : SetOperationUnit::op_or(string qi, WhereResultT& res, 55 : vector<WhereResultT*> inp) { 56 1615 : res = *inp[0]; 57 2558 : for (size_t or_idx=1; or_idx<inp.size(); or_idx++) { 58 : // If the OR term has mulitple ORs, union is needed 59 943 : WhereResultT tmp_query_result; 60 943 : QE_LOG_NOQID(INFO, qi << " UNION between tables of sizes " << 61 : res.size() << " and " << inp[or_idx]->size()); 62 2829 : set_union(res.begin(), res.end(), 63 943 : inp[or_idx]->begin(), 64 943 : inp[or_idx]->end(), 65 : std::back_inserter(tmp_query_result)); 66 943 : res = tmp_query_result; // keep the result in output var 67 943 : QE_LOG_NOQID(INFO, qi << " Resulting size of set " << 68 : res.size()); 69 943 : } 70 1615 : } 71 :