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
ProjectionQueryProcessor.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 PROJECTION_QUERY_PROCESSOR_CC
20 #define PROJECTION_QUERY_PROCESSOR_CC
21 
22 #include "PDBDebug.h"
23 #include "InterfaceFunctions.h"
25 
26 
27 namespace pdb {
28 
29 template <class Output, class Input>
31 
32  // get a copy of the lambdas for query processing
33  projection = forMe.getProjection(inputObject);
34  finalized = false;
35 }
36 
37 
38 template <class Output, class Input>
40  SimpleLambda<Handle<Output>> projection) {
41 
42  // get a copy of the lambdas for query processing
43  this->projection = projection;
44  finalized = false;
45 }
46 
47 // no need to do anything
48 template <class Output, class Input>
50  projectionFunc = projection.getFunc();
51  finalized = false;
52 }
53 
54 // loads up another input page to process
55 template <class Output, class Input>
57  Record<Vector<Handle<Input>>>* myRec = (Record<Vector<Handle<Input>>>*)pageToProcess;
58  inputVec = myRec->getRootObject();
59  posInInput = 0;
60 }
61 
62 // load up another output page to process
63 template <class Output, class Input>
65  size_t numBytesInPage) {
66 
67  // kill the old allocation block
68  blockPtr = nullptr;
69 
70  // create the new one
71  blockPtr = std::make_shared<UseTemporaryAllocationBlock>(pageToWriteTo, numBytesInPage);
72 
73  // and here's where we write the ouput to
74  outputVec = makeObject<Vector<Handle<Output>>>(10);
75 }
76 
77 template <class Output, class Input>
79 
80  Vector<Handle<Input>>& myInVec = *(inputVec);
81  Vector<Handle<Output>>& myOutVec = *(outputVec);
82 
83  // if we are finalized, see if there are some left over records
84  if (finalized) {
85  getRecord(outputVec);
86  return false;
87  }
88 
89  // we are not finalized, so process the page
90  try {
91  int vecSize = myInVec.size();
92  PDB_COUT << "Vector Size: " << std::to_string(vecSize) << std::endl;
93  for (; posInInput < vecSize; posInInput++) {
94  inputObject = myInVec[posInInput];
95  // std :: cout << "Pos: "<< std::to_string(posInInput) << std::endl;
96  myOutVec.push_back(projectionFunc());
97  }
98 
99  return false;
100 
101  } catch (NotEnoughSpace& n) {
102 
103  getRecord(outputVec);
104  return true;
105  }
106 }
107 
108 // must be called repeately after all of the input pages have been sent in...
109 template <class Output, class Input>
111  finalized = true;
112 }
113 
114 // must be called before freeing the memory in output page
115 template <class Output, class Input>
117  outputVec = nullptr;
118  blockPtr = nullptr;
119 }
120 
121 template <class Output, class Input>
123  inputVec = nullptr;
124  inputObject = nullptr;
125 }
126 }
127 
128 #endif
Handle< ObjType > getRootObject()
Definition: Record.cc:46
ProjectionQueryProcessor(Selection< Output, Input > &forMe)
void loadInputPage(void *pageToProcess) override
Record< ObjType > * getRecord(Handle< ObjType > &forMe)
#define PDB_COUT
Definition: PDBDebug.h:31
void loadOutputPage(void *pageToWriteTo, size_t numBytesInPage) override
size_t size() const
Definition: PDBVector.cc:67
void push_back(const TypeContained &val)
Definition: PDBVector.cc:95