NCBI C++ ToolKit
filtered_plan.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*****************************************************************************
2  * $Id: filtered_plan.hpp 93635 2021-05-06 19:26:47Z saprykin $
3  * ===========================================================================
4  *
5  * PUBLIC DOMAIN NOTICE
6  * National Center for Biotechnology Information
7  *
8  * This software/database is a "United States Government Work" under the
9  * terms of the United States Copyright Act. It was written as part of
10  * the author's official duties as a United States Government employee and
11  * thus cannot be copyrighted. This software/database is freely available
12  * to the public for use. The National Library of Medicine and the U.S.
13  * Government have not placed any restriction on its use or reproduction.
14  *
15  * Although all reasonable efforts have been taken to ensure the accuracy
16  * and reliability of the software and data, the NLM and the U.S.
17  * Government do not and cannot warrant the performance or results that
18  * may be obtained by using this software or data. The NLM and the U.S.
19  * Government disclaim all warranties, express or implied, including
20  * warranties of performance, merchantability or fitness for any particular
21  * purpose.
22  *
23  * Please cite the author in any work or product based on this material.
24  *
25  * Db Cassandra: class generating execution plans for cassandra table scans with filtered token ranges.
26  *
27  */
28 
29 #ifndef OBJTOOLS__PUBSEQ_GATEWAY__IMPL__CASSANDRA__FULLSCAN__FILTERED_PLAN_HPP
30 #define OBJTOOLS__PUBSEQ_GATEWAY__IMPL__CASSANDRA__FULLSCAN__FILTERED_PLAN_HPP
31 
34 
37 
39 {
40  public:
43  {
44  if (ranges.size()) {
45  pair<CCassConnection::TTokenValue, CCassConnection::TTokenValue> prev = {0,0};
46  for (auto range : ranges) {
47  if (range.first >= range.second) {
48  NCBI_USER_THROW("Illegal filter range - " + to_string(range.first) + ":" + to_string(range.second));
49  }
50  if (prev.first != 0 || prev.second != 0) {
51  if (range.first < prev.second) {
52  NCBI_USER_THROW("Unsorted filter range - " + to_string(range.first) + ":" + to_string(range.second));
53  }
54  }
55  prev = range;
56  }
57  }
58  m_Filter = ranges;
59  return *this;
60  }
61 
62  void Generate() override
63  {
64  // Subrange scan should be used for filtered plans
67  if (m_Filter.size()) {
68  CCassConnection::TTokenRanges filtered_ranges;
70  for (auto range : ranges) {
71  auto range_begin = range.first, range_end = range.second;
72  for (auto filter : m_Filter) {
73  auto filter_begin = filter.first, filter_end = filter.second;
74  if (range_begin < filter_end && range_end > filter_begin) {
75  filtered_ranges.push_back({
76  max(range_begin, filter_begin),
77  min(range_end, filter_end)
78  });
79  }
80  }
81  }
82 
83  /*for (auto range : filtered_ranges) {
84  cout << "Filtered range: " << range.first << ":" << range.second << endl;
85  }*/
86 
87  swap(ranges, filtered_ranges);
88  }
89  }
90 
91  /*TQueryPtr GetNextQuery() override
92  {
93  auto query = CCassandraFullscanPlan::GetNextQuery();
94  if (query) {
95  cout << query->ToString() << endl;
96  }
97  return query;
98  }*/
99 
100  private:
102 };
103 
105 
106 #endif
#define END_IDBLOB_SCOPE
Definition: IdCassScope.hpp:40
#define BEGIN_IDBLOB_SCOPE
Definition: IdCassScope.hpp:39
vector< pair< TTokenValue, TTokenValue > > TTokenRanges
void Generate() override
CCassandraFilteredPlan & SetFilterRanges(CCassConnection::TTokenRanges ranges)
CCassConnection::TTokenRanges m_Filter
CCassandraFilteredPlan()=default
void Generate() override
Definition: plan.cpp:293
CCassandraFullscanPlan & SetMinPartitionsForSubrangeScan(size_t value)
Definition: plan.cpp:135
CCassConnection::TTokenRanges & GetTokenRanges()
Definition: plan.cpp:322
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:61
BEGIN_IDBLOB_SCOPE USING_NCBI_SCOPE
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
Definition: ncbimisc.hpp:1508
#define NCBI_USER_THROW(message)
Throw a quick-and-dirty runtime exception of type 'CException' with the given error message and error...
Definition: ncbiexpt.hpp:715
range(_Ty, _Ty) -> range< _Ty >
T max(T x_, T y_)
T min(T x_, T y_)
Modified on Tue Feb 27 05:56:17 2024 by modify_doxy.py rev. 669887