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
ProjectionBlockQueryProcessor.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_BLOCK_QUERY_PROCESSOR_CC
20 #define PROJECTION_BLOCK_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  // std :: cout << "running ProjectionBlockQueryProcessor destructor" << std :: endl;
32  this->inputBlock = nullptr;
33  this->outputBlock = nullptr;
34  this->context = nullptr;
35  this->inputObject = nullptr;
36 }
37 
38 template <class Output, class Input>
40  Selection<Output, Input>& forMe) {
41 
42  // get a copy of the lambdas for query processing
43  projection = forMe.getProjection(inputObject);
44  finalized = false;
45 }
46 
47 
48 template <class Output, class Input>
50  SimpleLambda<Handle<Output>> projection) {
51 
52  // get a copy of the lambdas for query processing
53  this->projection = projection;
54  finalized = false;
55 }
56 
57 // no need to do anything
58 template <class Output, class Input>
60  projectionFunc = projection.getFunc();
61  finalized = false;
62 }
63 
64 // loads up another input page to process
65 template <class Output, class Input>
67  this->inputBlock = inputBlock;
68  this->batchSize = this->inputBlock->getBlock().size();
69  posInInput = 0;
70 }
71 
72 // load up another output page to process
73 template <class Output, class Input>
75  this->outputBlock = makeObject<GenericBlock>();
76  return this->outputBlock;
77 }
78 
79 template <class Output, class Input>
81 
82  // std :: cout << "Projection processor is running" << std :: endl;
83  Vector<Handle<Input>>& myInVec = (inputBlock->getBlock());
84  Vector<Handle<Output>>& myOutVec = (outputBlock->getBlock());
85 
86  // if we are finalized, see if there are some left over records
87  if (finalized) {
88  return false;
89  }
90 
91  // int totalObjects = 0;
92  // we are not finalized, so process the page
93  try {
94  int vecSize = myInVec.size();
95  // std :: cout << "Projection processor: posInInput="<< posInInput <<", input object num="
96  // << vecSize << std :: endl;
97  for (; posInInput < vecSize; posInInput++) {
98  inputObject = myInVec[posInInput];
99  myOutVec.push_back(projectionFunc());
100  // totalObjects ++;
101  }
102  // std :: cout << "Projection processor processed one input block with "<<totalObjects << "
103  // objects" << std :: endl;
104  return false;
105 
106  } catch (NotEnoughSpace& n) {
107  // std :: cout << "Projection processor consumed the page with "<< totalObjects << "
108  // objects" << std :: endl;
109  // std :: cout << "posInInput = " << posInInput << std :: endl;
110  if (this->context != nullptr) {
111  // getRecord (this->context->outputVec);
112  context->setOutputFull(true);
113  }
114  return true;
115  }
116 }
117 
118 // must be called repeately after all of the input pages have been sent in...
119 template <class Output, class Input>
121  finalized = true;
122 }
123 
124 // must be called before freeing the memory in output page
125 template <class Output, class Input>
127  outputBlock = nullptr;
128 }
129 
130 template <class Output, class Input>
132  inputBlock = nullptr;
133  inputObject = nullptr;
134 }
135 }
136 
137 #endif
void loadInputBlock(Handle< GenericBlock > block) override
Handle< GenericBlock > & loadOutputBlock() override
ProjectionBlockQueryProcessor(Selection< Output, Input > &forMe)
size_t size() const
Definition: PDBVector.cc:67
void push_back(const TypeContained &val)
Definition: PDBVector.cc:95