A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FilterQueryProcessor.cc
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 #ifndef FILTER_QUERY_PROCESSOR_CC
20 #define FILTER_QUERY_PROCESSOR_CC
21 
22 #include "InterfaceFunctions.h"
23 #include "FilterQueryProcessor.h"
24 
25 namespace pdb {
26 
27 template <class Output, class Input>
29 
30  // get a copy of the lambdas for query processing
31  filterPred = forMe.getSelection(inputObject);
32  finalized = false;
33 }
34 
35 template <class Output, class Input>
37 
38  // get a copy of the lambdas for filter processing
39  this->filterPred = filterPred;
40  finalized = false;
41 }
42 
43 // no need to do anything
44 template <class Output, class Input>
46  // filterFunc = filterPred.getFunc ();
47  finalized = false;
48 }
49 
50 // loads up another input page to process
51 template <class Output, class Input>
53  Record<Vector<Handle<Input>>>* myRec = (Record<Vector<Handle<Input>>>*)pageToProcess;
54  inputVec = myRec->getRootObject();
55  posInInput = 0;
56 }
57 
58 // load up another output page to process
59 template <class Output, class Input>
61  size_t numBytesInPage) {
62 
63  // kill the old allocation block
64  blockPtr = nullptr;
65 
66  // create the new one
67  blockPtr = std::make_shared<UseTemporaryAllocationBlock>(pageToWriteTo, numBytesInPage);
68 
69  // and here's where we write the ouput to
70  outputVec = makeObject<Vector<Handle<Input>>>(10);
71 }
72 
73 template <class Output, class Input>
75 
76  Vector<Handle<Input>>& myInVec = *(inputVec);
77  Vector<Handle<Input>>& myOutVec = *(outputVec);
78 
79  // if we are finalized, see if there are some left over records
80  if (finalized) {
81  getRecord(outputVec);
82  return false;
83  }
84 
85  // we are not finalized, so process the page
86  try {
87  int vecSize = myInVec.size();
88  for (; posInInput < vecSize; posInInput++) {
89  inputObject = myInVec[posInInput];
90  if (filterFunc()) {
91  myOutVec.push_back(inputObject);
92  // inputObject->print();
93  }
94  }
95  // std::cout << "Returning false" << std::endl;
96 
97  return false;
98 
99  } catch (NotEnoughSpace& n) {
100  // std::cout << "Got not enough space " << std::endl;
101  getRecord(outputVec);
102  // blockPtr = nullptr;
103  return true;
104  }
105 }
106 
107 // must be called repeately after all of the input pages have been sent in...
108 template <class Output, class Input>
110  finalized = true;
111 }
112 
113 // must be called before freeing the memory in output page
114 template <class Output, class Input>
116  outputVec = nullptr;
117  blockPtr = nullptr;
118 }
119 
120 // must be called before freeing the memory in input page
121 template <class Output, class Input>
123  inputVec = nullptr;
124  inputObject = nullptr;
125 }
126 }
127 
128 #endif
void loadOutputPage(void *pageToWriteTo, size_t numBytesInPage) override
Handle< ObjType > getRootObject()
Definition: Record.cc:46
void loadInputPage(void *pageToProcess) override
Record< ObjType > * getRecord(Handle< ObjType > &forMe)
size_t size() const
Definition: PDBVector.cc:67
void push_back(const TypeContained &val)
Definition: PDBVector.cc:95
FilterQueryProcessor(Selection< Output, Input > &forMe)