Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #include "query.h" 6 : #include "stats_query.h" 7 : 8 : using std::vector; 9 : using boost::shared_ptr; 10 : using std::string; 11 : 12 : // for sorting and set operations 13 25723 : bool query_result_unit_t::operator<(const query_result_unit_t& rhs) const 14 : { 15 25723 : if (timestamp == rhs.timestamp) 16 : { 17 553 : GenDb::DbDataValueVec::const_iterator it = info.begin(); 18 553 : GenDb::DbDataValueVec::const_iterator jt = rhs.info.begin(); 19 6746 : for (; it != info.end() && jt != rhs.info.end(); it++, jt++) { 20 6498 : if (*it < *jt) { 21 87 : return true; 22 6411 : } else if (*jt < *it) { 23 218 : return false; 24 : } 25 : } 26 248 : return false; 27 : } 28 : 29 25170 : return (timestamp < rhs.timestamp); 30 : } 31 : 32 : 33 : void 34 458 : SetOperationUnit::op_and(string qi, WhereResultT& res, 35 : vector<WhereResultT*> inp) { 36 458 : res = *inp[0]; 37 464 : for (size_t and_idx=1; and_idx<inp.size(); and_idx++) { 38 6 : WhereResultT tmp_query_result; 39 6 : QE_LOG_NOQID(INFO, qi << " INT between tables of sizes " << 40 : res.size() << " and " << inp[and_idx]->size()); 41 18 : set_intersection(res.begin(), res.end(), 42 6 : inp[and_idx]->begin(), 43 6 : inp[and_idx]->end(), 44 : std::back_inserter(tmp_query_result)); 45 6 : res = tmp_query_result; // keep the result in output var 46 6 : QE_LOG_NOQID(INFO, qi << " Resulting size of set " << 47 : res.size()); 48 : 49 6 : } 50 458 : } 51 : 52 : void 53 1631 : SetOperationUnit::op_or(string qi, WhereResultT& res, 54 : vector<WhereResultT*> inp) { 55 1631 : res = *inp[0]; 56 2573 : for (size_t or_idx=1; or_idx<inp.size(); or_idx++) { 57 : // If the OR term has mulitple ORs, union is needed 58 943 : WhereResultT tmp_query_result; 59 943 : QE_LOG_NOQID(INFO, qi << " UNION between tables of sizes " << 60 : res.size() << " and " << inp[or_idx]->size()); 61 2829 : set_union(res.begin(), res.end(), 62 943 : inp[or_idx]->begin(), 63 943 : inp[or_idx]->end(), 64 : std::back_inserter(tmp_query_result)); 65 943 : res = tmp_query_result; // keep the result in output var 66 943 : QE_LOG_NOQID(INFO, qi << " Resulting size of set " << 67 : res.size()); 68 943 : } 69 1629 : } 70 :